// JavaScript Document

function init() { 
	updateClock();
	gMenu();
	if($('sdlink')) {
		changeImg();
		popup();
	}
	if($('player'))
		playVideo();
}

setInterval('updateClock()', 1000 );

function clearText(elm) {
	elm.value  = "";
}

function popup() {
	if(!checkCookie()) {
		$('popup').setStyle('display', 'block');
		$('popup').makeDraggable({container: document.body});
		$('popup').setStyle('top', $random(50, 400) + 'px');
		$('popup').setStyle('left', $random(50, 1000) + 'px');
	}
}

function setCook() {
	Cookie.write('showPopup', 1, {duration: 30, path: '/'});
	closePopup();
	window.location.href = 'http://account.redcherrypoker.com/downloadFile.php?do=xp&skinversion=1';
}

function checkCookie() 
{
	if(!Cookie.read('showPopup'))
		return false;
	else
		return true;
}

function closePopup() {
	$('popup').setStyle('display', 'none');
}

function changeImg() {
	var today = new Date();
	var month = today.getMonth();
	var day = today.getDate();
/*	var index = 30*(month%3) + day;	*/
	var index = (30*month + day ) % 78;
	if (index < 10)	index =  '0'+index;
	var img = 'DailyImages/Small/' + index + '.jpg';
	var lnk = 'DailyImages/Big/' + index + '.jpg';
	$('swankOfTheDay').src = img;
	$('sdlink').href = lnk;
	preloadImg(img);
}


function preloadImg(img)
{
 	sd = new Image(373,247);
	sd.src = img;
	menuActive = new Image(33,91);
	menuActive.src = "images/menuActive.jpg";
}

if(!myDate){
 var myDate = new Date();
}

function updateClock( )
{

	var absolute = myDate.getTime() + 1;
	myDate.setTime(absolute);
	var currentTime = myDate;

  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  //var currentSeconds = currentTime.getSeconds ( );

  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  //currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

  // Choose either "AM" or "PM" as appropriate
  var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

  // Convert the hours component to 12-hour format if needed
  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

  // Convert an hours component of "0" to "12"
  currentHours = ( currentHours == 0 ) ? 12 : currentHours;

  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + " " + timeOfDay;

  // Update the time display
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}


function playVideo(path, title)
{
	var so = new SWFObject("videos/gddflvplayer.swf", "player", "356", "244", "8", "#FFF");
	
	so.addParam("scale", "noscale");
	so.addParam("quality", "best");
	so.addParam("allowFullScreen", "true");
	so.addParam("allowScriptAccess", "always");

	if(!path) {
		path = "AllInOne.flv";
		title = "All In One";
		so.addVariable("autoplay", "false");
	} else {
		so.addVariable("autoplay", "true");
	}

	so.addVariable("vdo", escape(path));
	so.addVariable("desc", escape(title));
	so.addVariable("sound", "50");
	so.addVariable("buffer", "2");
	so.write("player");
}


function myWindow(url,width,height){
	if(width<=0) width=500;
	if(height<=0) height=500;
	var myw = window.open(url,'SUBWINDOW','resizable,toolbar=no,statusbar=no,scrollbars=yes,dependent=yes,location=no,menubar=no,status=no,width='+width+',height='+height);
	
}
