google.load("jquery",1.2);	// Load jQuery

var popUp = function(mypage,myname,w,h,scroll) {
	var win = null;
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var params = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes';
	
	win = window.open(mypage,myname,params);
	
	if (parseInt(navigator.appVersion)>=4) { win.window.focus(); }
};

var shareLink = function(linkName) {
	
	var shareURL = null;
	
	if (linkName=='Favorites') {
		
		var cubeName = 'cesar unwrap the holidays';
		var cubeURL = 'http://www.cesar.com/unwrap/?cid=favorites';
		
		if (window.sidebar) {															// Firefox
			window.sidebar.addPanel(cubeName,cubeURL,"");
		} else if (window.external) {										// IE
			window.external.AddFavorite(cubeURL,cubeName);
		} else if (window.opera&&window.print) {					// Opera
			alert('Press Ctrl+T to bookmark \'Unwrap The Holidays\'');
		} else {
			alert('Your browser does not support this feature.');
		}

	} else if (linkName=='Myspace') {
		
		document.getElementById('Share_On_MySpace').submit();
		
	} else {
		
		switch (linkName) {
			case 'Facebook':		shareURL = 'http://www.facebook.com/sharer.php?u=http://www.cesar.com/unwrap/&t=cesar%AE+unwrap+the+holidays';																	break;
			case 'Delicious':		shareURL = 'http://del.icio.us/post?url=http://www.cesar.com/unwrap/&title=cesar%AE+unwrap+the+holidays';																				break;
			case 'Digg':				shareURL = 'http://www.digg.com/submit?phase=2&url=http://www.cesar.com/unwrap/&title=cesar%AE+unwrap+the+holidays';														break;
			case 'Live':				shareURL = 'https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=http://www.cesar.com/unwrap/&title=cesar%AE+unwrap+the+holidays';	break;
			case 'Yahoo':				shareURL = 'http://myweb.yahoo.com/myresults/bookmarklet?t=cesar%AE+unwrap+the+holidays&u=http://www.cesar.com/unwrap/&ei=UTF';									break;
		}
			
		omniTrack("Unwrap The Holidays - Share This - "+linkName);
		
		popUp(shareURL,'share_cesar_cube',850,600,'yes');
		
	}
};

var popUpRules = function() {	popUp('unwrap_official_rules.html','share_cesar_cube',850,600,'yes'); };

var setWelcomeCookie = function(showWelcome) {
	if (showWelcome) { showWelcome = '1'; } else { showWelcome = '0'; }
	$.post('/unwrap/SetWelcomeCookieOperation.aspx',{ showWelcome:showWelcome });
};

var setLoginCookies = function(userEmail) {
	setCookie('Email',userEmail);
	setCookie('UserGuid',userEmail);
};

var clearLoginCookies = function() {
	deleteCookie('Email');
	deleteCookie('UserGuid');
	location.href = "/default.aspx";
};

var setColorCookie = function(color) {
	setCookie('CubeColor',color);
};

var popupRules = function(pageName) {
	width=700;
	height=475;
	
	switch (pageName) {
		case 'how-to-play': 	url = 'Rules/how-to-play.html';	break;
		case 'contact': 			url = 'Rules/contact.html'; 		break;
		case 'rules': 		url = 'Rules/rules.html';
	}
	
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	props = 'height='+height+',width='+width+',top='+TopPosition+',left='+LeftPosition+',scrollbars=0';
	win = window.open(url,"cube_rules",props)
};

var interfaceColor = getCookie('CubeColor');

if (interfaceColor==null) {
	
	randColorNum = Math.ceil(Math.random() * 3);
	
	switch (randColorNum) {
		case 1: interfaceColor = "r"; break;
		case 2: interfaceColor = "g"; break;
		case 3: interfaceColor = "b"; break;
	}
	
}

// google.setOnLoadCallback(function() {});