var whyunsoy_timeout = 10000;		//The timer value in milliseconds
var whyunsoy_fadetime = 1;
var whyunsoy_currentimage;	
var whyunsoy_nextimage;
var whyunsoy_clock;

function whyunsoy_fadeToImage(imageindex){
	
	if (imageindex != whyunsoy_currentimage){
		whyunsoy_currentimage = imageindex;
		
		$j('.bannerimage:visible').fadeOut(whyunsoy_fadetime);
		
		//fade in the image
		$j('#bannerimage' + imageindex).fadeIn(whyunsoy_fadetime);
	}
	
}

function whyunsoy_highlightPlug(id){
	
	if (id != whyunsoy_currentimage){		
		$j('.aktifbar[id!=bannerplug' + id + ']').animate({opacity: 0.0}, 100);	//Dim out other plugs
		//$j('#bannerplug' + id).find('.aktifbar').animate({opacity: 0.0}, 500);	//Fade in current plug	//Doesn't work in webkit brosers
		$j('div:first', '#bannerplug' + id).animate({opacity: 1.0}, whyunsoy_fadetime);
		$j('div:first', '#bannerplug' + id).css({color: "#b99a37"});
		$j('.bannerplug[id=bannerplug' + id + '] h3').animate({color: '#b99a37'}, whyunsoy_fadetime);
		$j('.bannerplug[id!=bannerplug' + id + '] h3').animate({color: '#747474'}, whyunsoy_fadetime);
	}
	
}

function whyunsoy_startRotate(){
	whyunsoy_clock = setInterval('whyunsoy_rotateImage()', whyunsoy_timeout);
}

function whyunsoy_stopRotate(){
	clearInterval(whyunsoy_clock);
}


function whyunsoy_rotateImage(){
	//Fade in next banner

	whyunsoy_nextimage = parseInt(whyunsoy_currentimage) + 1;
	if (whyunsoy_nextimage > 6) {
		whyunsoy_nextimage = 1;
	}

	whyunsoy_highlightPlug(whyunsoy_nextimage);
	whyunsoy_fadeToImage(whyunsoy_nextimage);
}


/*
Master jquery controller	
*/

$j(document).ready(function(){

	//Set the banner dimmer
	$j('.aktifbar').animate({opacity: 0.5}, 0);

	//Start the banner rotation
	whyunsoy_highlightPlug(1);
	whyunsoy_fadeToImage(1);
	whyunsoy_startRotate();
	
	//Bannerplug hover
	$j('.bannerplug').hover(
		function(event){
			var id = $j(this).attr('id').substring(10);
						
			//Highlight current
			whyunsoy_highlightPlug(id);
						
			//alert(id);
			whyunsoy_stopRotate();
			whyunsoy_fadeToImage(id);
			
		}, function(event){
			whyunsoy_startRotate();
		}
	);
	
	//Banner hover
	$j('.bannerimage').hover(
		function(event){
			whyunsoy_stopRotate();
		}, function(event){
			whyunsoy_startRotate();
	});
});
