/* ================================================================ 
This copyright notice must be untouched at all times.
Copyright (c) 2009 Stu Nicholls - stunicholls.com - all rights reserved.
=================================================================== */
$(document).ready(function(){
var countarticle = document.getElementById('countarticle').value;						   
current_g = 1;
button_g = 1;
images_g = 2;
images_g = parseInt(countarticle)-1;
width_g = 350;

$('#gp1').animate({"left": "0px"}, 400, "swing");
$('#g1').css("backgroundPosition", "left bottom")
$('#g1 g').css("color","#fff");
$('#loading').css("display","none");


$("#next").click(function() {
		button_g = current_g;
		current_g++
	if (current_g == (images_g+1) ) {current_g = 1}
animateLeft(current_g,button_g)
});

$("#previous").click(function() {
		button_g = current_g;
		current_g--
	if (current_g == 0 ) {current_g = images_g}
animateRight(current_g,button_g)
});

$("#buttons-g div").click(function() {
	button_g=current_g;
	clickButton_g = $(this).attr('id');
	current_g = parseInt(clickButton_g.slice(1));
	if (current_g > button_g) {animateLeft(current_g,button_g)}
	if (current_g < button_g) {animateRight(current_g,button_g)}
});

$("#buttons-g div g").mouseover(function() { clearTimeout(tss_g);
	if (($(this).css("color")) == "#FFFFFF" || ($(this).css("color")) == "rgb(0, 0, 0)") {$(this).css("color","#FFFFFF");}
});

$("#buttons-g div g").mouseout(function() { tss_g = setTimeout('runSlideShow_g()', SlideShowSpeed_g);
	if (($(this).css("color")) == "#FFFFFF" || ($(this).css("color")) == "rgb(0, 0, 0)") {$(this).css("color","#FFFFFF");}
});

function animateLeft(current_g,button_g) {
	$('#gp'+current_g).css("left",width_g +"px");
	$('#gp'+current_g).animate({"left": "0px"}, 400, "swing");
	$('#gp'+button_g).animate({"left": -width_g+"px"}, 400, "swing");
	setbutton()
}

function animateRight(current_g,button_g) {
	$('#gp'+current_g).css("left",-width_g+"px");
	$('#gp'+current_g).animate({"left": "0px"}, 400, "swing");
	$('#gp'+button_g).animate({"left": width_g+"px"}, 400, "swing");
	setbutton()
}

function setbutton () {
	$('#g'+button_g).css("backgroundPosition", "left top")
	$('#g'+button_g+' g').css("color","#FFFFFF");
	$('#g'+current_g).css("backgroundPosition", "left bottom")
	$('#g'+current_g+' g').css("color","#fff");
}

});

var SlideShowSpeed_g = 6000;
//var jss = 1 ;//var jmax = 5;//var jmin = 1;
var tss_g;
var jwait_g = 0;
function runSlideShow_g(){ 
 //var lnk = document.getElementById("next");
 if (jwait_g==0) { jwait_g = 1;}
 else { $("#next").trigger('click');  }	
	//lnk.click(); jss = jss + 1; //if (jss>jmax) jss = jmin; //add for check max 7
 tss_g = setTimeout('runSlideShow_g()', SlideShowSpeed_g);
}
 

