/* --------------------------------------------------------------
 *  News Scroller Stuff
 * -------------------------------------------------------------- */
var time;
var amount = 1;
var theTime = 80; //should be 40

function initializeNews() {
	var container = $("#block-views-news_events-block_1 > div");
	news1 = $("#block-views-news_events-block_1  > div > div").css("top", "0px");
	
	news2 = news1.clone(true).attr("id", "newsholder2").css("top", parseInt(news1.css("top")) + news1.height() + "px");
	container.append(news2);
	
	setTimeout("realscroll()", 2000);
	
	container.mouseover(stopScroll);
	container.mouseout(function(){time = setTimeout('realscroll()',50);});
}

function realscroll() {	
	if(parseInt(news1.css("top")) + news1.height() < 0) {
		news1.css("top", parseInt(news2.css("top")) + news2.height() + "px");
	}
	
	if(parseInt(news2.css("top")) + news2.height() < 0) {		
		news2.css("top", parseInt(news1.css("top")) + news1.height() + "px");
	}
	
	news1.css("top", parseInt(news1.css("top")) - amount + "px");
	news2.css("top", parseInt(news2.css("top")) - amount + "px");
			
	time = setTimeout('realscroll()',theTime);								
}

function stopScroll() {
	if (time) clearTimeout(time);
}

/* --------------------------------------------------------------
 *  IE Dropdown Stuff
 * -------------------------------------------------------------- */
function startlist() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("drop");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {				
				node.onmouseover=function() {
					this.className+=" over";
		  		}
		  		node.onmouseout=function() {
		  			this.className=this.className.replace(" over", "");
		   		}
		   	}
		 }
	 }
}

/* --------------------------------------------------------------
 *  Add Initalizers to Onload
 * -------------------------------------------------------------- */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

//addLoadEvent(initializeNews);
$(function() { initializeNews(); });
//addLoadEvent(startlist);

/* --------------------------------------------------------------
 *  Add Initalizers to Onload
 * -------------------------------------------------------------- */
$(function() {
	var checkBanner = readCookie('bannerCookie');
	
	/* --------------------------------------------------------------
	 *  Check to see if banner cookie is set.
	 * -------------------------------------------------------------- */
	if(!checkBanner) {
		eraseCookie('bannerCookie');
		createCookie('bannerCookie','visible',7);
	} else if(checkBanner == 'hidden') {
		$('#flashcontainer').hide();
		$('#shrinker').attr("src","sites/all/themes/cardboard/images/zipdown.png");
	}
		
	/* --------------------------------------------------------------
	 *  Click event for the show/hide banner link.
	 * -------------------------------------------------------------- */
	$('#shrinker').click(function(){
		var bannerStatus = readCookie('bannerCookie');
		switch(bannerStatus) {
		case 'null':
			eraseCookie('bannerCookie');
			createCookie('bannerCookie','visible',7);
			break;
		case 'visible':
			$('#flashcontainer').slideUp("slow");
			$('#shrinker').attr("src","sites/all/themes/cardboard/images/zipdown.png");;
			eraseCookie('bannerCookie');
			createCookie('bannerCookie','hidden',7);
			break;
		case 'hidden':
			embedFlash();
			$('#flashcontainer').slideDown("slow");
			$('#shrinker').attr("src","sites/all/themes/cardboard/images/zipup.png");;
			eraseCookie('bannerCookie');
			createCookie('bannerCookie','visible',7);
			break;
		}
	});
});
			
/* --------------------------------------------------------------
 *  Used for any fading buttons on the GCCIS site.
 * -------------------------------------------------------------- */
$(document).ready(function() {
	var fadeButton = $(".fadeButton");
	jQuery.each(fadeButton, function() {
		$(this).mouseover(function() { $(this).fadeTo(300, 1) });
		$(this).mouseout(function() { $(this).fadeTo(300, .65) });
	});
});

		
/* --------------------------------------------------------------
 *  embedFlash function is used to embed the flash banner in the
 *  GCCIS site.
 * -------------------------------------------------------------- */
function embedFlash() {
	var so = new SWFObject("sites/all/themes/cardboard/banner/banner.swf", "mymovie", "100%", "100%", "8", "#000000");
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	so.write("flashcontainer");
}

function test(){
	alert('test');
}