startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("navigation_list");
		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", "");
				}
			}
		}
	}
}
window.onload=startList;

$(document).ready(function() {
	 // Equal heights function
	 jQuery.fn.equalHeights=function() {
		var maxHeight=0;
		this.each(function(){
			if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
		});
		this.each(function(){
			$(this).height(maxHeight + "px");
			if (this.offsetHeight>maxHeight) {
				$(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
			}
		});
	};
	
	// navigation rollover function
	$("#navigation_list li ul").hover(function(){
		$(this).parent("li").children("a").addClass("nav_link_over");
	},function(){
		$(this).parent("li").children("a").removeClass("nav_link_over");
	})
	
	$("#site_search_form #search_keywords").focus(function(){
		if($("#site_search_form #search_keywords").val()=="Enter search"){
			$("#site_search_form #search_keywords").val('');
			$("#site_search_form #search_keywords").removeClass('default_search');
		}else{
			$("#site_search_form #search_keywords").select();
		}
	});
	
	$("#navigation_list li").not("#navigation_list li ul li, #navigation_list li.right_nav_link").hover(
		function() { 
			$("#navigation_list li").removeClass("nav_link_hover");
			$("#navigation_list li").not(".nav_link_hover").find("ul").fadeOut(0);
			$(this).not(".nav_link_hover").find("ul").fadeIn(0);
			$(this).not(".nav_link_on").addClass("nav_link_hover");
		}
	);
	
	$(".login_box").click(
		function() { 
			$("#update_box").slideUp(300, function() {
				$("#login_box").slideToggle(300);
			});
			return false;
		}
	);
	
	$(".update_box").click(
		function() { 
			$("#login_box").slideUp(300, function() {
				$("#update_box").slideToggle(300);
			});
			return false;
		}
	);
	// PNG fix for IE
	//$(document).pngFix();
});


// ----------			NEWS MODULE			----------
nNewsModCurrent = 1;
function fNewsModNext() {
	if (nNewsModCurrent != nNewsModTotal) {
		if (nNewsModCurrent == 1) { $("#newsmod_button_prev").fadeTo(0,1); }
		$("#news_mod_"+nNewsModCurrent).hide();
		$("#news_mod_"+(nNewsModCurrent+1)).show();
		nNewsModCurrent += 1;
		if (nNewsModCurrent == nNewsModTotal) { $("#newsmod_button_next").fadeTo(0,0.4); }
	}
	return false;
}
function fNewsModPrev() {
	if (nNewsModCurrent != 1) {
		if (nNewsModCurrent == nNewsModTotal) { $("#newsmod_button_next").fadeTo(0,1); }
		$("#news_mod_"+nNewsModCurrent).hide();
		$("#news_mod_"+(nNewsModCurrent-1)).show();
		nNewsModCurrent -= 1;
		if (nNewsModCurrent == 1) { $("#newsmod_button_prev").fadeTo(0,0.4); }
	}
	return false;
}

//----------------- share module ---------------------//
//	Basic open window
function openWindow(url,width,height) {
	var rand = Math.floor(Math.random()*1001)
	var PopUpWin=window.open(url,"popup"+rand,'width=' + width + ',height=' + height + ',resizeable=0,scrollbars=yes,menubar=no,status=no');
	PopUpWin.focus()
}


// Winners
// Media Changers.
function fLoadZoom(fullPath) {
	var flashvars = { zoomifyImagePath: fullPath };
	var params = { bgcolor:"##000000", allowFullScreen:"true", rand:Math.floor(Math.random()*999999) };
	swfobject.embedSWF("/winners/includes/zoomify_viewer.swf", "mediaPlayer", "480", "360", "7.0.0", "/scripts/swfobject/expressInstall.swf", flashvars, params);
}

function fLoadFLV(fullPath,imagePath) {
	if ( imagePath === undefined ) { imagePath = "/winners/images/generic/480x360.jpg"; } 
	var flashvars = { file: fullPath, autostart:"true", image:imagePath, controlbar: 'over', 'controlbar.margin':0, 'http.startparam':'ec_seek' };
	var params = { allowFullScreen: "true", wmode: "transparent" };
	swfobject.embedSWF("/includes/player.swf", "mediaPlayer", "480", "360", "9.0.115.0", "/scripts/swfobject/expressInstall.swf", flashvars, params);
}

function fWinLoadZoom(fullPath) {
	$("#mediaPlayerHolder").html('<div id="mediaXPlayer"></div>')
	var flashvars = { zoomifyImagePath: fullPath };
	var params = { bgcolor:"##000000", allowFullScreen:"true", rand:Math.floor(Math.random()*999999) };
	swfobject.embedSWF("/winners/includes/zoomify_viewer.swf", "mediaXPlayer", "480", "360", "7.0.0", "/scripts/swfobject/expressInstall.swf", flashvars, params);
}

function fWinLoadImage(imagePath) {
	$("#mediaPlayerHolder").html('<div id="mediaXPlayer"><img src="'+imagePath+'" /></div>')
}
function fWinLoadJW(fullPath,imagePath) {
	if ( imagePath === undefined ) { imagePath = "/winners/images/generic/480x360.jpg"; }
	$("#mediaPlayerHolder").html('<div id="mediaXPlayer"></div>')
	jwplayer("mediaXPlayer").setup({ 
		flashplayer: "/includes/player.swf", 
		file: fullPath, 
		image: imagePath,
		height: 360, width: 480,
		autostart: true, allowFullScreen: true,
		controlbar: 'over', 'controlbar.margin':0, 'http.startparam':'ec_seek'
	})
}

function fBreakString(search,nLen) {
	$.each($(search), function() {
		var htm = $(this).html();
		aHtm = htm.split(" ");
		if (aHtm.length > 1) {
			$.each(aHtm, function(i,val) {
				//alert(i + " " + val)
				if (val.length > nLen) {
					if ( val.indexOf("/") != -1) {
						si = val.indexOf("/");
						aHtm[i] = val.substring(0,si+1)+"<wbr>"+val.substring(si+1,val.length);
					} else {
						aHtm[i] = val.substring(0,nLen)+"<wbr>"+val.substring(nLen,val.length); }
					}
			});
		} else if ( aHtm[0].indexOf("/") != -1) {
			si = aHtm[0].indexOf("/");
			aHtm[0] = aHtm[0].substring(0,si)+"<wbr>"+aHtm[0].substring(si,aHtm[0].length); 
		} else {
			aHtm[0] = aHtm[0].substring(0,nLen)+"<wbr>"+aHtm[0].substring(nLen,aHtm[0].length); 
		}
		htm = aHtm.join(" ");
		$(this).html(htm)
	});
}
