// JavaScript Document
var BannerNumber = 1;
var BannerInterval = 10000;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'script/jquery-plugins.js';
document.getElementsByTagName('head')[0].appendChild(script);  

function frontpage_script()
{
	var thisPoll = $("#poll");
	var pollstring = "general/polster.aspx?mode=init&poll=" + thisPoll.attr("title");
	$.get(pollstring,function(data){
		thisPoll.html(data);
	
	});
	if(MSIEVersion() != 6)
	{
	changeToPng();
	$("#frontpage_banner").pngFix();
	}
	if($.cookie("DisplayMode") != "text") 
		setTimeout("bannerRotator()",BannerInterval);
	
}

function processPoll()
{
	var value= $("input:radio[name=poll]:checked").val();
	if (!(value==undefined))
	{
			var thisPoll = $("#poll");
			var pollTitle = thisPoll.attr("title");
			var cookieValue =	$.cookie(pollTitle)==null ? 0 : $.cookie(pollTitle);
			var pollstring = "general/polster.aspx?mode=update&poll=" + pollTitle + "&select=" + value + "&cook=" + cookieValue;
			$.get(pollstring, function(data){ 
				thisPoll.html(data);
				$.cookie(pollTitle,"1", { expires: 30});
			});
	}
	return false
}


function bannerRotator()
{
    $.get("general/BannerRotator.aspx?mode=" + BannerNumber,function(data) {
				$("#frontpage_banner").html(data);
				$("#frontpage_banner").pngFix();
				BannerNumber += 1;
				setTimeout("bannerRotator()",BannerInterval);
    });
}

function changeToPng()
{
	
	$(".changeToPng").each(function() {
	
		if((MSIEVersion() >= 6) || (MSIEVersion()==-1))
		{
			var src = $(this).attr("src");
			if (src.indexOf(".jpg")>0) 
				{
					src = src.substr(0,src.lastIndexOf(".jpg"));
					src += ".png";
				}
			$(this).attr("src",src);
			
		}
	});
}

function MSIEVersion() {
	var version = -1; 
	if (navigator.appVersion.indexOf("MSIE") != -1) {
	  version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	}
	return version;
}


function Video_Update()
{
	$("#section").after("<div id='dialog' style='background:black'><iframe width='380' height='320'  frameborder='0' style='margin-top:-40px'></iframe></div>");
	$("#dialog").dialog({
						
		bgiframe: false,
		width:	420,
		resizable: false,
		draggable: false,
		modal:true,
		autoOpen: false

	});
	$('#dialog').dialog('option', 'buttons', { "Close": function() { $(this).dialog("close"); } });
	$("#dialog").bind('dialogclose',function(event,ui) {
		$("#dialog > iframe").removeAttr("src");
	});
	$(".launchvideo").each(function() {
		var href = $(this).attr("href");
		$(this).removeAttr("target");
		$(this).removeAttr("title");
		$(this).removeAttr("href");
		$(this).hover( function() {
			document.body.style.cursor = "hand";
			document.body.style.cursor = "pointer";
					},
			function() {
			 document.body.style.cursor = "default";
		});
		$(this).click( function() {
			$("#dialog > iframe").attr("src",href);
			$("#dialog").dialog('option', 'title' , $(this).attr("name"));
			$("#dialog").dialog('open'); 
		});
	});
	
	
}

$(document).ready(function(){
	setActiveStyleSheet();
});


function setActiveStyleSheet()
{
	 switch ($.cookie("DisplayMode"))
	 {
		case "text" :
			$("#displaymode").html("<a href='javascript:changeDisplayMode();'>Graphics Mode</a> | ");
			$("#PageStyle").attr("href","../css/text.css");
			break;
		
		default:
			$("#displaymode").html("<a href='javascript:changeDisplayMode();'>Text Mode</a> | ");
			$("#PageStyle").attr("href","../css/default.css");
	 }
	
}

function changeDisplayMode()
{
	if($("#displaymode > a").text()=="Graphics Mode")
	{
		$.cookie("DisplayMode","graphics",{ expires: 30, path: '/'});
	} else {
		$.cookie("DisplayMode","text",{ expires: 30, path: '/'});
	}
	setActiveStyleSheet();
}



	