var opacitytimeout = 0;
var iscancel = false;
var hasRun = false;

var newstimeout = 0;

var flashvars = {};
var params = {};
	params.play = "true";
	params.loop = "true";
	params.menu = "true";
	params.quality = "high";
	params.scale = "showall";
	params.wmode = "transparent";
	params.bgcolor = "#ffffff";
var attributes = {};

//swfobject.embedSWF("/assets/flash/homepage.swf", "flashcontent", "461", "461", "9.0.0", false, flashvars, params, attributes, flashEmbeded);

$(function(){
	if(swfobject.hasFlashPlayerVersion("9.0.0") && !($("body").is(".DesignMode") || $("body").is(".EditMode"))){
			swfobject.embedSWF("/assets/flash/com15994_flash_4.swf", "flashcontent", "461", "461", "9.0.0", false, flashvars, params, attributes);
	
			//$("#homeopacity").css("display", "block");
			//opacitytimeout = setTimeout("fadeOpacity()", 5000);
			
			newstimout = setTimeout("nextnews()", 7000);
	}
});
function fadeOpacity(){
	if(!hasRun){
		$("#homeopacity").stop().fadeOut(500, function(){
			$("#homeopacity").css("display","none");
		});
		if(iscancel){
			clearTimeout(opacitytimeout);
			iscancel = false;
		}
		hasRun = true;
	}
}
function cancelTimeout(){
	clearTimeout(opacitytimeout);
	opacitytimeout = setTimeout("fadeOpacity()", 5000);
	iscancel = true;
}

function nextnews(){
	clearTimeout(newstimout);

	var newscount = $("#homenewsscroller p.newsitem").size();
	var currentindex = $("#homenewsscroller p.newsitem").index($("#homenewsscroller p.active")) + 1;
	var currentobj = $("#homenewsscroller p.active");
	
	
	if(currentindex == newscount){
		$("#homenewsscroller p:nth-child(1)").addClass("active").show();
	}
	else{
		$("#homenewsscroller p.active + p.newsitem").addClass("active").show();
	}
	currentobj.hide().removeClass("active");
	
	newstimout = setTimeout("nextnews()", 7000);
}

function prevnews(){
	clearTimeout(newstimout);
	var currentindex = $("#homenewsscroller p").index($("#homenewsscroller p.active")) + 1;
	var currentobj = $("#homenewsscroller p.active");
	
	
	if(currentindex == 1){
		$("#homenewsscroller p:last-child").addClass("active").show();
	}
	else{
		$("#homenewsscroller p.active").prev().addClass("active").show();
	}
	currentobj.hide().removeClass("active");
	
	newstimout = setTimeout("nextnews()", 7000);
}
