$(document).ready(doc_readyHandler);

function doc_readyHandler()
{
	// IE
	//$(document).pngFix();

	// Tooltips
	$("#socialMedia a[title]").tooltip({ offset: [10, 0], effect: 'slide'});

	// Colorbox
	$(".image-cloud a").colorbox({iframe:true,width:984,height:740,scrolling:false,overlayClose:true});
	$(".monster-profile a").colorbox({scrolling:false,overlayClose:true});
	$("#contact a").colorbox({iframe:true,width:500,height:610,scrolling:false,overlayClose:false});
	$("#monsterlogin a").colorbox({iframe:true,width:500,height:610,scrolling:false,overlayClose:false});
	$("#registernow a").colorbox({iframe:true,width:984,height:640,scrolling:false,close:"closecolorbox",overlayClose:false});
	$("#ie6").colorbox({href: 'modal/ie-update.cfm',transition: 'fade',overlayClose: false,open:true,title: false});
	$(".avatar_editor").colorbox({innerWidth:"1281", innerHeight:"880", scrolling:false, opacity:"0.9", iframe:true, overlayClose:false});

	// Fonts
	Cufon.replace('#maintitle')('h3')('h5');

	// Tabs
	$("#tabs").tabs("#gameinfo > .panes > div");
	$("#tabs").tabs("#tabs_panes > div");
	$("#tabs2").tabs("#tabs2_panes > div");
	$(".tabs").tabs("div.panes > div");	
	$("#galnavigation").tabs("#allmonsters > div");
	
	// Cycle
	$('#slidecontainer').before('<div id="slidemenu">').cycle({fx:'scrollLeft',timeout: 8000,pager:'#slidemenu'});
	$('#slideshowrecipe').cycle({prev:'#prev',next:'#next',timeout:0});
	$('#slideshowrecipeveg').cycle({prev:'#preveg',next:'#nextveg',timeout:0});
	$('#slideshowwinners').cycle({prev:'#prevWinner',next:'#nextWinner',timeout:0});
	$('#slideshowrunnerups').cycle({prev:'#prevRunnerup',next:'#nextRunnerup',timeout:0});
	$('#case1').cycle({prev:'#prev1',next:'#next1',timeout:0});
	$('#case2').cycle({prev:'#prev2',next:'#next2',timeout:0});
	$('#case3').cycle({prev:'#prev3',next:'#next3',timeout:0});
	$('#case4').cycle({prev:'#prev4',next:'#next4',timeout:0});
	
	// Misc
	$("a").filter(function(){return this.hostname && this.hostname.replace("www.", "") != location.hostname.replace("www.", "");
		}).click(function() {
			window.open($(this).attr("href"));
			return false;
	});
	
	// Animations
	var flashvars = {};
	var params = {wmode:"transparent"};
	var attributes = {id:"interactiveMonsters"};
	swfobject.embedSWF("/assets/flash/interactivemonsters.swf", "interactiveMonsters", "1000", "600", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}

function signIn_showRegisterHandler()
{
	$.colorbox({href:'modal/register.cfm', iframe:true, width:984, height:640, scrolling:false});
}

function member_showMonsterHandler()
{
	$.colorbox({href:'modal/monster.cfm', iframe:true, width:984, height:640, scrolling:false});
}

function signIn_clickHandler(args)
{
	$.colorbox({iframe:true, href:'modal/login?'+args, width:500, height:500, scrolling:false});
}

function signOut_clickHandler()
{
	if(confirm("Sign out of Playnormous?"))
	{
		$.AjaxCFC({url: "com/playnormous/service/AjaxService.cfc",
			method: "signOutMember",
			success: signOut_completeHandler
		});
	}		
}

function signOut_completeHandler(data)
{
	parent.location.reload(true);
}

function signup()
{
	$.fn.colorbox({iframe:true, href:'modal/register', width:984, height:640, scrolling:false});
}

function closeButton_clickHandler()
{
	alert('clicked');
	Sexy.confirm('Your monster will not be saved. Are you sure you want to quit?', {
	  onComplete:
		function(returnvalue) {
		  if (returnvalue) {
			parent.$.fn.colorbox.close();
		  } else {
		  	//alert('pressed Cancel');
		  }
		}
	  });
}

function registration_completeHandler()
{
	parent.$.fn.colorbox.close();
}

function registration_continueHandler(step)
{
	var titlecount = $("##titlecount");
	var title = $("##title");
	var value = (step == "2") ? "Tell Us Your Age." : "Name Your Monster.";
	var valuesmall = (step == "2") ? "step 2 of 3" : "step 3 of 3";
	title.text(value);
	titlecount.text(valuesmall);
	Cufon.replace("##title");
	Cufon.replace("##titlecount");
}
