//jQuery(document).ready(function () {
	//pngfix();
//});

/**************************************************************************
START ROTATOR
**************************************************************************/
if (location.href.indexOf('HomePage') >= 0) 
	var rotate = true;	
else
	var rotate = true;
var rotate_current = 0;
var rotate_end = 3;

jQuery(document).ready(function () {
	jQuery("img.sub-image").click(function () { 
		if(rotate)
			toggle();
		for(i=0;i<jQuery("img.sub-image").length;i++) {
			if(jQuery("img.sub-image")[i]==this) {
				rotate_current = i;
				//console.log('subimage click:'+rotate_current);
				changeArticle();
			}
		}
	});
});

function changeArticle() {
	jQuery("#Rotator .main-content").fadeOut(500);
	//jQuery("#Rotator .main-content").hide();
	//jQuery("#Rotator .main-content").css("display","none");
	setTimeout('jQuery("#Rotator .main-content:eq('+rotate_current+')").fadeIn(500)',500);
	rotate_past = rotate_current - 1;
	if (rotate_past < 0)
		rotate_past = 0;
	if (rotate_current == 0)
		rotate_past = 3;
	//console.log(rotate_current+' - '+rotate_past);
	jQuery('#rotatorPage'+rotate_current).css("background", "#ccc");
	jQuery('#rotatorPage'+rotate_past).css("background", "#fff");
	//jQuery("#Rotator .main-content:eq("+rotate_current+")").show();
	//jQuery("#Rotator .main-content:eq('+rotate_current+')").css("display","block");
	//jQuery("img.sub-image").css("borderWidth","0px");
	//jQuery("img.sub-image").css("marginBottom", "7px");
	//jQuery("img.arrow").slideUp(500);
	//jQuery("img.arrow").hide();
	//setTimeout('subStoryOn(rotate_current)',510);
	//subStoryOn(rotate_current);
	
}

function article(num) {
	rotate_past = rotate_current;
	rotate_current = num;
	jQuery("#Rotator .main-content").fadeOut(500);
	setTimeout('jQuery("#Rotator .main-content:eq('+rotate_current+')").fadeIn(500)',510);
	//console.log(rotate_current+' - '+rotate_past);
	jQuery('#rotatorPage'+rotate_current).css("background", "#ccc");
	jQuery('#rotatorPage'+rotate_past).css("background", "#fff");
	jQuery("#Rotator .main-content:eq('+rotate_current+')").css("display","block");
	rotate = false;
}

/*function subStoryOn(num) {
	//console.log('subStoryOn:'+num);
	jQuery("img.sub-image").css("borderStyle","solid")
	//console.log(jQuery("img.sub-image").css("borderColor"));
	
	jQuery("img.sub-image:eq("+num+")").css("border", "2px solid #fff");
	jQuery("img.sub-image:eq("+num+")").css("marginBottom", "2px");
	
	jQuery("img.sub-image:eq("+num+")").animate({
		borderWidth:"2px",
		marginBottom:"2px"
	},500);
	//jQuery("img.arrow:eq("+num+")").slideDown(500);
	
	jQuery("img.arrow:eq("+num+")").css("display", "block");
}*/

function rotateForward(button) {
	if(button)
		rotate = false;
	//console.log('Forward');
	if(rotate_current!=rotate_end)
		rotate_current ++;
	else
		rotate_current = 0;	
	changeArticle();
}

function rotateBack() {
	//console.log('Back');
	if(rotate_current!=0)
		rotate_current --;
	else
		rotate_current = rotate_end;	
	changeArticle();
}

function Rotate() {
	//console.log("Rotate()");
	if(rotate) {
		//console.log("go");
		rotateForward(false);
	}
	else {
		//console.log('stop');
	}
}

function toggle() {
	//console.log('toggle');
	if(rotate) 
		rotate = false;
	else 
		rotate = true;
}

jQuery(document).ready(function () {
	if(document.getElementById("Rotator")) 
		var r = setInterval('Rotate()',6000);	//call rotate every 5 seconds
	else {
		//console.log('no rotator');
	}
});

/**************************************************************************
END ROTATOR
**************************************************************************/
