// JavaScript Document

$(document).ready(function(){
	// Bind our event to our select
	$('#themeSelect').change(function () { // first switch, basic swap background colours
	  var theme = $('#themeSelect :selected').text(); // grabs our select theme name
	  //createCookie("theme",theme);
	  createCookie("THEME",theme);
	  var linkHref = "/assets/jquery/themes/" + theme + "/ui.all.css"; // sets the new stylesheet variable
	  //alert(linkHref.replace(/%23/g, "").replace(/[\?#]+/g, ""));
	  updateCSS(linkHref);
	});
});

function updateCSS(locStr){
	//once 1.6 final is ready: 
	$("html").find("link[title=theme]").attr("href", locStr); // set the new stylesheet
	//$("head").append('<link href="' + locStr +'" type="text/css" rel="Stylesheet" />');
	/*$("link[title=theme]:last").after('<link href="' + locStr +'" type="text/css" rel="Stylesheet" />');
	if($("link[title=theme]").size() > 3){
		$("link[title=theme]:first").remove();
	}*/	
};

function PopupFlyer(eventID) { 
	//alert('event_viewflyer.cfm?id='+eventID);
	flyer = window.open( "/v1/event_viewflyer.cfm/id/"+eventID, "flyer", "resizable=1,HEIGHT=200,WIDTH=200"); 
}

function viewFlyer(action) {
	if (action == 'init') {
		
		$("#flyerBig").dialog({
			bgiframe: true,
			height: 'auto',
			width: 'auto',
			modal: false,
			draggable: false,
			resizable: false,
			autoOpen: false,
			title: 'Event Flyer',
			position: 'center',
			dialogClass: 'ui-widget-content ui-corners-all'
		});

		//$('#flyerBig').dialog();
		//$('#flyerBig').dialog('close');
	} else if (action == 'open') {
		$('#flyerBig').dialog('open');
		//$("#flyerBig").dialog('option', 'position', 'center');
	} else {
		$('#flyerBig').dialog('close');
	}
}



tday  =new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
tmonth=new Array("January","February","March","April","May","June","July","August","September","October","November","December");

function GetClock(){
	d = new Date();
	nday   = d.getDay();
	nmonth = d.getMonth();
	ndate  = d.getDate();
	nyeara = d.getYear();
	nhour  = d.getHours();
	nmin   = d.getMinutes();
	nsec   = d.getSeconds();
	
	if(nyeara<1000){nyeara=(""+(nyeara+11900)).substring(1,5);}
	else{nyeara=(""+(nyeara+10000)).substring(1,5);}
	
		 if(nhour ==  0) {ap = " AM";nhour = 12;} 
	else if(nhour <= 11) {ap = " AM";} 
	else if(nhour == 12) {ap = " PM";} 
	else if(nhour >= 13) {ap = " PM";nhour -= 12;}
	
	if(nmin <= 9) {nmin = "0" +nmin;}
	if(nsec <= 9) {nsec = "0" +nsec;}
	
	timeString = ""+tday[nday]+", "+tmonth[nmonth]+" "+ndate+", "+nyeara+" "+nhour+":"+nmin+":"+nsec+ap+""
	$('#clockbox').html(timeString);
	//alert(timeString);
	setTimeout("GetClock()", 1000);
}
window.onload=function(){GetClock();}