/* end of Main functions */
$( document ).ready( function(){
		googleConListen();
		loginRegEvent();
		checkBioPages();
		//GoogleListener();
//		$(document).pngFix(); 
		enableCalendar();
		homeRotator();
		//setInterval (rotateImage, 5000);
		rotateImage();
		homePromos();
		checkFlashContent();
		logValidation();
		secretCode();
		scrollingGames();
		scrollingCatalog();
		firstBio_BlogPage();
		redirect();
		musicPlayer();
		PngFix_IE();
		chooseCountry();
		Translation();		
});

function Translation() {
	if( $__( $( "#overlay-box" ) ) ){
		
		//Bio
		$("#screen").html(moxieHash.language.bio.screen);
		$("#paper").html(moxieHash.language.bio.paper);
		
		//Catalog
		$("#catalog-dolls-menu").html(moxieHash.language.catalog.dolls);
		$("#catalog-acc-menu").html(moxieHash.language.catalog.acc);
		
		
		$("#dialog-title").html(moxieHash.language.registration.dialogtitle);
		$("#dialog-desc").html(moxieHash.language.registration.dialogdesc);
		$("#dialog-dob").html(moxieHash.language.registration.dialogdob);
		$("#calendar").html(moxieHash.language.registration.calendar);
		$("#lang-firstname1").html(moxieHash.language.registration.firstname);
		$("#lang-firstname2").html(moxieHash.language.registration.firstname);
		$("#lang-firstname3").html(moxieHash.language.registration.firstname);
		$("#lang-lastname1").html(moxieHash.language.registration.lastname);
		$("#lang-lastname2").html(moxieHash.language.registration.lastname);
		$("#lang-lastname3").html(moxieHash.language.registration.lastname);
		$("#lang-username1").html(moxieHash.language.registration.username);
		$("#lang-username2").html(moxieHash.language.registration.username);
		$("#lang-username3").html(moxieHash.language.registration.username);
		$("#lang-password1").html(moxieHash.language.registration.password);
		$("#lang-password2").html(moxieHash.language.registration.password);
		$("#lang-gender").html(moxieHash.language.registration.gender);
		$("#lang-gender-boy").html(moxieHash.language.myaccount.boy);
		$("#lang-gender-boy2").html(moxieHash.language.myaccount.boy);
		$("#lang-gender-girl").html(moxieHash.language.myaccount.girl);
		$("#lang-gender-girl2").html(moxieHash.language.myaccount.girl);
		$("#lang-email1").html(moxieHash.language.registration.email);
		$("#lang-email2").html(moxieHash.language.registration.email);
		$("#lang-email3").html(moxieHash.language.registration.email);
		$("#lang-parent-email").html(moxieHash.language.registration.parentemail);
		$("#lang-select-one").html(moxieHash.language.registration.selectone);
		$("#lang-newsletters").html(moxieHash.language.registration.newsletters);
		$("#lang-offer1").html(moxieHash.language.registration.offer1);
		$("#lang-offer2").html(moxieHash.language.registration.offer2);
		$("#btn-next").html(moxieHash.language.registration.btnnext);
		$("#btn-next").css("width", "100px");
		$("#reg-complete-header-left").html(moxieHash.language.registration.regcompleteheader);
		$("#p-reg-complete").html(moxieHash.language.registration.regcomplete);
		$("#enable-product-code").html(moxieHash.language.registration.enableproductcode);
		$("#complete-btn-close").html(moxieHash.language.registration.btnclose);
		$("#logon-header-left").html(moxieHash.language.registration.logonheader);
		$("#a-logon-forgot").html(moxieHash.language.registration.forgotpassword);
		$("#a-logon-register").html(moxieHash.language.registration.register);
		$("#btn-logon").html(moxieHash.language.registration.btnlogon);
		$("#forgot-header-left").html(moxieHash.language.registration.forgotpassword);
		$("#p-forgot-desc").html(moxieHash.language.registration.forgotdesc);
		$("#forgotusername").html(moxieHash.language.registration.forgotusername);
		$("#forgotemail").html(moxieHash.language.registration.forgotemail);
		$("#forgot-submit").html(moxieHash.language.registration.btnsubmit);
		$("#myacct-header-left").html(moxieHash.language.registration["myacct-header-left"]);
		
		$("#menu-enable-edit").html(moxieHash.language.registration.menuenableedit);
		$("#s-brand-offers").html(moxieHash.language.registration.brandoffers);
		$("#s-check").html(moxieHash.language.registration.check);
		$("#update-save").html(moxieHash.language.registration.btnsave);
		$("#update-cancel").html(moxieHash.language.registration.btncancel);
		$("#see-other-brands").html(moxieHash.language.myaccount.seeotherbrands);
		
		//My Account
		$("#login").html(moxieHash.language.homepage.login);
		$("#register").html(moxieHash.language.homepage.register);
		$("#logged-on").html(moxieHash.language.homepage.welcome + " " + obj.username);
		$("#myaccount").html(moxieHash.language.homepage.myaccount);
		$("#profile").html(moxieHash.language.myaccount.profile);
		$("#products").html(moxieHash.language.myaccount.products);
		$("#scores").html(moxieHash.language.myaccount.scores);
		$("#children").html(moxieHash.language.myaccount.children);
		$("#activities").html(moxieHash.language.myaccount.activities);
		$("#span-myacct-password").html(moxieHash.language.myaccount["myacct-password"]);
		$("#myacct-password-confirm").html(moxieHash.language.myaccount["myacct-password-confirm"]);
		
		
		$("#logout").html(moxieHash.language.homepage.logout);
		$("#a-country").html(moxieHash.language.homepage.country);
		$("#country-header-left").html(moxieHash.language.homepage.country);
		$("#en-us").html(moxieHash.language.homepage.en);
		$("#es-es").html(moxieHash.language.homepage.es);
		$("#fr-ca").html(moxieHash.language.homepage.fr);
		$("#en-ca").html(moxieHash.language.homepage.enca);
		$("#ru-ru").html(moxieHash.language.homepage.ru);
		
		
		$("#myacct-header-left").html(moxieHash.language.homepage.myaccount);
		$("#logout").html(moxieHash.language.homepage.logout);
		$("#menu-country").html(moxieHash.language.homepage.country);
		$("#terms").html(moxieHash.language.homepage.terms);
		$("#footer_wtb").html(moxieHash.language.homepage.wheretobuy);
		$("#privacy").html(moxieHash.language.homepage.privacy);
		$("#copyright").html(moxieHash.language.homepage.copyright);
		$("#faq").html(moxieHash.language.homepage.faq);
		
		$("#senddolls").html(moxieHash.language.catalog.sendtofriend);
		$("#sendacc").html(moxieHash.language.catalog.sendtofriend);
		
		$("#senddolls").attr("href",moxieHash.language.catalog.senddolls);
		$("#sendacc").attr("href",moxieHash.language.catalog.sendacc);
		
	}
}

function chooseCountry() {
	
	if( $__( $( "#overlay-country" ) ) ){
		
		$("#a-country, #a-flag").click( function(){
			$("#country-wrapper").css("display","block");
			
		});
		
		$("#country-header-close").click( function() {
			$("#country-wrapper").css("display","none");
		});
		
		$(".choosecountry").click( function() {
			$(".btn-close").click();
			setCookie("moxiegirlzlang", this.id);
			window.location="";
		});
	}	
	
}


function musicPlayer(){
	if( $__( $( "#div-moxieteenz-audio" ) ) ){
		/* see if off exists */
		var params = { wmode : "transparent" };
		var attributes={wmode : "transparent" };
		var on = moxieHash.language.homepage["audio-on"];
		var off = moxieHash.language.homepage["audio-off"];
		
		if(getCookie("volOff")){				
			var flashvars={"onString":on, "offString":off, "playState":0, "songURL":"http://www.moxieteenz.com/smarty_files/templates/sounds/MT_commercial_loop_2.mp3"}
				swfobject.embedSWF( "smarty_files/templates/flash/build/MGAMusicPlayer.swf" , "div-moxieteenz-audio" , "95" , "20" , "9.0.0" , "", flashvars , params , attributes );
		} else { 
			var flashvars={"onString":on, "offString":off, "playState":1, "songURL":"http://www.moxieteenz.com/smarty_files/templates/sounds/MT_commercial_loop_2.mp3"}
				swfobject.embedSWF( "smarty_files/templates/flash/build/MGAMusicPlayer.swf" , "div-moxieteenz-audio" , "95" , "20" , "9.0.0" , "", flashvars , params , attributes );
		}
				
    }

}

function googleConListen(){
	if( google_return_con == "reg" ) { $("#register").click(); }
}

var PngFix_IE = ( function( ){ 
		if( $.browser.msie == true && $.browser.version == "6.0" || $.browser.version == "7.0" ){
		//if( $.browser.msie == true && $.browser.version == "6.0" ){
			$('.imgfix').css("visibility","hidden");
			var stringElem = "";
			$('.imgfix').each( function( i , val ){ 
				var img_url =  $( this ).attr("src");
				var img_width = $( this ).attr("width"); 
				var img_height = $( this ).attr("height");

				$( this ).parent().get( 0 ).innerHTML = "<span style=\"width:"+ img_width +";height:"+ img_height +";filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enable=true,src='"+ img_url +"' ,sizingMethod='scale')\"></span>";   
			} );

			$(".png").each( function( i , val ){
				var img_url =  $( this ).css("background-image").replace(/url\("|"|\)$/ig, "");
				$( this ).addClass("force").attr("style", "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img_url + "' ,sizingMethod='scale');");
			 });
		}
	} );

function redirect(){
	var currentWebsite = "";
	var arr = new Array();
	    
	    arr["a-walmart-"+language] = moxieHash.catalog.links.walmart;	//"http://www.walmart.com/";
	    arr["a-kmart-"+language] = moxieHash.catalog.links.kmart;	//"http://www.kmart.com/";
	    arr["a-toys-"+language] = moxieHash.catalog.links.tru;	//"http://www.toysrus.com/";
	    arr["a-target-"+language] = moxieHash.catalog.links.target;
		arr["a-amazon-"+language]= moxieHash.catalog.links.amazon
	    
	    arr["facebook-"+language] = "http://www.facebook.com/moxieteenz";
	    arr["twitter-"+language] = "http://www.twitter.com/moxieteenz";
		arr["youtube"] = "http://www.youtube.com/moxieteenz";
		arr["home-promo-left"] = "http://www.youtube.com/moxieteenz";
		arr["home-promo-center"] = "http://www.stardoll.com/en/dolls-games/";

	    arr["facebook2"] = "http://www.facebook.com/moxieteenz";
	    arr["twitter2"] = "http://www.twitter.com/moxieteenz";
	    arr["stardoll"] = "http://www.stardoll.com/en/dolls-games/";
		arr["voteMT-en"] = "http://www.peoplesplayawards.com"

	$(".a-inter-event").click( function(){
		$("#interstitial").fadeIn("slow");
		currentWebsite = arr[this.id];
	 });

	$("#interstitial-yes").click( function(){ 
			gotoLink( currentWebsite );
			pageTracker._trackEvent('retailers', currentWebsite);
		$("#interstitial").fadeOut("slow");
	});

	$("#interstitial-no").click( function(){ 
		$("#interstitial").fadeOut("slow");
	});
	
	if ($.getUrlVar('uriLang') ) {
			setCookie("moxiegirlzlang", $.getUrlVar('uriLang'));
			url = "?section=" + $.getUrlVar('section') + "&category=" + $.getUrlVar('category') + "&id=" + $.getUrlVar('id');
			window.location=url;
	}
}

function gotoLink( website ){
			window.open( website ,"","menubar=1,resizable=1,location=1,status=1,scrollbars=1" );
}

function firstBio_BlogPage(){
	if( $__( $( "#div-bio-box" ) ) ){
		if( content_type == "blog" ){
			$("#bio-copy").css("display","none");
			$("#blog-copy,#bio-girl-img").css("display","block");
			$("#link-blog").css("text-decoration","underline");
		 }
		else{
			$("#blog-copy").css("display","none");
			$("#bio-copy,#bio-girl-img").css("display","block");
			$("#link-bio").css("text-decoration","underline");
		}
	}
}

function $__( objId ) {
        return $( objId ).get(0);
}

function scrollingGames(){

	$(".game-items").cycle({ 
	   		fx: 'fade', 
		    speed:  'slow', 
		    timeout: 0, 
		    next:   '.next', 
		    prev:   '.prev' });
		    
		    
	/*$(".games-scroller").scrollable({ 
	    size: 1,
		loop: true });*/
		
	$("#games-future").click(function(){
		$("#future-games-wrapper").css("display","block");
		$("#perfectmatch-games-wrapper").css("display","none");
		$("#photoshoot-games-wrapper").css("display","none");		
			var params = { wmode : "transparent" };
 			var attributes = {};
			var flashvars = { };
			swfobject.embedSWF("smarty_files/templates/flash/Future_fantasy2.swf", "future-game", "600", "400", "9.0.0","expressInstall.swf", flashvars, params, attributes); 
			
		var currentGame = this.id;
		
		pageTracker._trackEvent('Moxieteenz Game', currentGame); 				
	});
	
	/* Perfect match game*/
	$("#games-perfectmatch").click(function(){
		$("#future-games-wrapper").css("display","none");
		$("#perfectmatch-games-wrapper").css("display","block");
			var params = { wmode : "transparent" };
 			var attributes = {};
			var flashvars = { };
			swfobject.embedSWF("smarty_files/templates/flash/PerfectMatch.swf", "perfectmatch-game", "600", "400", "9.0.0","expressInstall.swf", flashvars, params, attributes);
			
		var currentGame = this.id;

		pageTracker._trackEvent('Moxieteenz Game', currentGame);  	
			
	});
	
	/* Photoshoot game*/
	$("#games-photoshoot").click(function(){
		$("#future-games-wrapper").css("display","none");
		$("#perfectmatch-games-wrapper").css("display","none");
		$("#photoshoot-games-wrapper").css("display","block");
			var params = { wmode : "transparent"};
			params.base = base + "smarty_files/templates/flash/mtphotoshoot/build/";
 			var attributes = {};
			var flashvars = {};
			flashvars.gamepipe = gamepipe + "index.php";
			swfobject.embedSWF("smarty_files/templates/flash/mtphotoshoot/build/PhotoshootLoader.swf", "photoshoot-game", "800", "600", "9.0.0","expressInstall.swf", flashvars, params, attributes);  
			
		var currentGame = this.id;
		
		var foo = pageTracker._trackEvent('Moxieteenz Game', currentGame);

	});
	
	/* closes the games wrapper */
	$(".close").click(function(){
		
		$("#"+this.id+"-wrapper").css("display" , "none");
		
	});
	
	if(  $__( $( ".game-items" ) ) ){
			var google_conversion_label = "XL9jCLLu4AEQgIyC7wM";
			$("#google_conversion").html("<img src='http://www.googleadservices.com/pagead/conversion/1038124544/?label=XL9jCLLu4AEQgIyC7wM&amp;guid=ON&amp;script=0' border='0' />");
	}
	
	
}

function scrollingCatalog(){
	
	if($__( $("#div-catalog") ) ){
		
		var catalog_arr = moxieHash.productGallery.a_allprod.dolls;
		
		
		var toString = "";
		
		for( x in catalog_arr ){
			
			toString += "<div class=\"div-dolls\">";
			toString += "<img src=\""+ catalog_arr[x]["imgpath"] +"\" class=\""+ catalog_arr[x]["cssClass"]+"\"/>";	
			toString += "<p class=\"p-dolls-desc\">" + catalog_arr[x]["description"]  + "</p>";
			toString += "</div>";
			
		}
		
		$("#catalog-dolls").html( toString );
		
		var catalog_acc = moxieHash.productGallery.a_allprod.accessories;

		var accString = "";

		for( x in catalog_acc ){

			accString += "<div class=\"div-acc\">";
			accString += "<img src=\""+ catalog_acc[x]["imgpath"] +"\" class=\""+ catalog_acc[x]["cssClass"]+"\"/>";	
			accString += "<p class=\"p-acc-desc\">" + catalog_acc[x]["description"]  + "</p>";
			accString += "</div>";

		}

	$("#catalog-acc").html( accString );
		
		$("#catalog-dolls").cycle({ 
				cleartype:  !$.support.opacity, 
				cleartypeNoBg: true,
		   		fx: 'fade', 
			    speed:  'slow', 
			    timeout: 0, 
			    next:   '.next', 
			    prev:   '.prev' });
			
		$("#catalog-acc").cycle({ 
				cleartype:  !$.support.opacity, 
				cleartypeNoBg: true,
				fx: 'fade', 
				speed:  'slow', 
				timeout: 0, 
				next:   '.next', 
				prev:   '.prev' });
		}
		
}

function getFlashVersion(){
  // ie
  try {
    try {
      // avoid fp6 minor version lookup issues
      // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
      try { axo.AllowScriptAccess = 'always'; }
      catch(e) { return '6,0,0'; }
    } catch(e) {}
    return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
  // other browsers
  } catch(e) {
    try {
      if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
        return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
      }
    } catch(e) {}
  }
  return '0,0,0';
}
 
	

function homeRotator(){
	if(  $__( $( "#div-home-rotator" ) ) ){
			var google_conversion_label = "lfqZCLrt4AEQgIyC7wM";
			$("#google_conversion").html("<img src='http://www.googleadservices.com/pagead/conversion/1038124544/?label=lfqZCLrt4AEQgIyC7wM&amp;guid=ON&amp;script=0' border='0' />");
	}
	
	/*var flashVersion = getFlashVersion().split(',').shift();
	
	if (jQuery.browser.mozilla && flashVersion >= 10) {
	
		var htmlString = "";
		htmlString += "<img src='http://c1877532.cdn.cloudfiles.rackspacecloud.com/2_melrose_lrg_v3.png' />";
		htmlString += "<img src='http://c1877532.cdn.cloudfiles.rackspacecloud.com/1_melrose_sm_v3.png' />";
		htmlString += "<img src='http://c1877532.cdn.cloudfiles.rackspacecloud.com/2_bijou_lrg_v3.png' />";
		htmlString += "<img src='http://c1877532.cdn.cloudfiles.rackspacecloud.com/1_bijou_sm_v3.png' />";
		htmlString += "<img src='http://c1877532.cdn.cloudfiles.rackspacecloud.com/2_tristen_lrg_v3.png' />";
		htmlString += "<img src='http://c1877532.cdn.cloudfiles.rackspacecloud.com/1_tristen_sm_v3.png' />";
		htmlString += "<img src='http://c1877532.cdn.cloudfiles.rackspacecloud.com/2_arizona_lrg_v3.png' />";
		htmlString += "<img src='http://c1877532.cdn.cloudfiles.rackspacecloud.com/1_arizona_sm_v3.png' />";

		$("#div-home-rotator").html(htmlString);
		$("#div-home-rotator").cycle({ 
	   		fx: 'fade', 
		    speed:  'slow', 
		    timeout: 5000 });
		
		//drop the code for the fading thing here.
	
	} else {

		*/
		var params = { wmode : "transparent"};
		var attributes = {};

		var flashvars = {};

		/*
		flashvars.image1 = "smarty_files/templates/images/cloud_animation/2_melrose_lrg.png,1,10";
		flashvars.image2 = "smarty_files/templates/images/cloud_animation/1_melrose_sm.png,2,10";
		flashvars.image3 = "smarty_files/templates/images/cloud_animation/2_bijou_lrg.png,3,10";
		flashvars.image4 = "smarty_files/templates/images/cloud_animation/1_bijou_sm.png,4,10";
		flashvars.image5 = "smarty_files/templates/images/cloud_animation/2_tristen_lrg.png,5,10";
		flashvars.image6 = "smarty_files/templates/images/cloud_animation/1_tristen_sm.png,6,10";
		flashvars.image7 = "smarty_files/templates/images/cloud_animation/2_arizona_lrg.png,7,10";
		flashvars.image8 = "smarty_files/templates/images/cloud_animation/1_arizona_sm.png,8,10";
		*/
		
		flashvars.image1 = "http://c1877532.cdn.cloudfiles.rackspacecloud.com/2_melrose_lrg_v3.png,1,10";
		flashvars.image2 = "http://c1877532.cdn.cloudfiles.rackspacecloud.com/1_melrose_sm_v3.png,2,10";
		flashvars.image3 = "http://c1877532.cdn.cloudfiles.rackspacecloud.com/2_bijou_lrg_v3.png,3,10";
		flashvars.image4 = "http://c1877532.cdn.cloudfiles.rackspacecloud.com/1_bijou_sm_v3.png,4,10";
		flashvars.image5 = "http://c1877532.cdn.cloudfiles.rackspacecloud.com/2_tristen_lrg_v3.png,5,10";
		flashvars.image6 = "http://c1877532.cdn.cloudfiles.rackspacecloud.com/1_tristen_sm_v3.png,6,10";
		flashvars.image7 = "http://c1877532.cdn.cloudfiles.rackspacecloud.com/2_arizona_lrg_v3.png,7,10";
		flashvars.image8 = "http://c1877532.cdn.cloudfiles.rackspacecloud.com/1_arizona_sm_v3.png,8,10";

		flashvars.nominalHeight = "450";
		flashvars.nominalWidth = "1400";
		

		swfobject.embedSWF("smarty_files/templates/flash/build/ImageFader.swf", "div-home-rotator", "1400", "450", "9.0.0","smarty_files/templates/flash/expressInstall.swf", flashvars, params, attributes);


		$("#a-flash-desc,#p-flash-desc").css({"display":"block"});
		
	//}
	
}

function rotateImage( ){
	
	
	/* This functions will rotate the right Home promo, that links to secretcode */
	
	if(country == "en-us"){
		var rightPromo=new Array()
		rightPromo[0]=moxieHash.homepromos.img_right_1
		rightPromo[1]=moxieHash.homepromos.img_right_2
	
		$("#home-promo-right").css( {"background-image" : "url("+ rightPromo[1] +")" } );
	
		function fadeOut(){ 

			// call fadeIn();

			setTimeout( function() { fadeIn('slow'); } , 10000  );
		
			$("#home-promo-right").css( {"background-image" : "url("+ rightPromo[0] +")" } );
		}

		function fadeIn(){

			// fadeOut(); 

			setTimeout( function() { fadeOut('slow');  } , 10000  );
				
			$("#home-promo-right").css( {"background-image" : "url("+ rightPromo[1] +")" } );
		}
		
		fadeOut();
		
	}else{
		$("#home-promo-right").css( {"background-image" : "url("+ moxieHash.homepromos.img_right +")" } );
	}
}

function homePromos(str){
	if($__( $("#div-home-promos") ) ){
		
		 /* var rightPromo=new Array()
		  //specify random images below. You can have as many as you wish
		  //rightPromo[0]=moxieHash.homepromos.img_right_1
		  //rightPromo[1]=moxieHash.homepromos.img_right_2

		  //var rand=Math.floor(Math.random()*rightPromo.length);*/
		
		$("#home-promo-left").css( {"background-image" : "url("+ moxieHash.homepromos.img_left +")" } );
		$("#home-promo-center").css( {"background-image" : "url("+ moxieHash.homepromos.img_center +")" } );
		
		/*if(country == "en-us"){
			var randPromo = rightPromo[rand];
			$("#home-promo-right").css( {"background-image" : "url("+ rightPromo[rand] +")" } );
		}else{
			$("#home-promo-right").css( {"background-image" : "url("+ moxieHash.homepromos.img_right +")" } );
		}*/
		$("#home-promo-left").attr("class",moxieHash.homepromos.class_left);
		$("#home-promo-center").attr("class",moxieHash.homepromos.class_center);
		$("#home-promo-right").attr("class",moxieHash.homepromos.class_right);
				
		$("#home-promo-left").attr("href",moxieHash.homepromos.href_left);
		$("#home-promo-center").attr("href",moxieHash.homepromos.href_center);
		$("#home-promo-right").attr("href",moxieHash.homepromos.href_right);
	} 	
}


function secretCode(){

	$("#enable-product-code").click( function(){
		$("#dialog-reg-complete").css("display","none");			
		setCookie( "secretcode", "1" );
		window.location = "";
	});

		$(".secret-code").click(function(){
			if( obj.id ){
			
				$("#input-secret-code").val("");
				$("#secretcode-basic").css("display","none");
				$("#secret-code-"+language).fadeIn('slow');
		
				$("#input-secret-code").keyup( function(){
					if( this.value.length >= 6 ){
						$("#secretcode-basic").fadeIn('slow');
						$("#secretcode-next").click(function(){
							$("#secretcode-basic").css("display" , "none");
							$("#secretcode-party").fadeIn('slow');
						});
					
						$("#secretcode-party-next").click(function(){
							$("#secretcode-party").css("display" , "none");
							$("#secretcode-basic").fadeIn('slow');
						});
					
					}
					else{
						$("#secretcode-basic, #secretcode-party").fadeOut('slow');
					}
				});

				$("#secretcode-close-"+language).click(function(){
					$("#secret-code-"+language).fadeOut('slow');
				});
		
				setCookie("secretcode", null);
				deleteCookie("secretcode");		
			} else{ 
				setCookie("secretcode", "1");
				$("#login").click();  
			}//end if
		});//end function
	
		if(getCookie("secretcode") != null && getCookie("secretcode") != "") {
	 		$(".secret-code").click();
	 	}


	$("#btn-submit").click( function(){
		var girl = 0;
		var secret_code = $("#input-secret-code").val();
		/*$(".radio-secretcode").each( function( i , val ){ 
			if( $( this ).attr("checked") ){
				girl =  this.value;
			}
		});*/

			
			
				 $.post("?request=secretcode", { secret_code : secret_code , girl : girl , user_id : obj.id , website_id : website_id }, function( http ){
		         	var s_return = eval( http );
		         	if( s_return > 0 ){
		         		alert(moxieHash.language.registration.addSecretCode); 
						$.get("?request=download&id=" + s_return , { id : s_return } , function( url ){
						window.location = url;
						} );

					}
					else if( s_return == 0 ){
						alert("You have already registered this product.");
						$.get("?request=download&id=" + s_return , { id : s_return } , function( url ){
							window.location = url;
						} );
					}
					else if( s_return < 0 ){
						alert(moxieHash.language.registration.check_secretcode);
					}
			
		});
	 });

}


function checkBioPages(){
	
	if( $__( $( "#girl-menu" ) ) ){
		$(".home-girl-menu").click( function(){ 
				var stringcurrent = this.id.split("-");				
				currentGirl = stringcurrent[1];
			window.location = "?section=moxieteenzbio&girl="+currentGirl;				
		});
	}
	
	if( $__( $( "#div-download-content" ) ) ){
		$("#a-download-screen").click( function(){ 
								
				var url = "smarty_files/templates/downloads/screensavers/screensaver.sfp.zip";
				window.location = url;			
		});
		
		$("#a-download-paper").click( function(){ 
				
				var url = "smarty_files/templates/downloads/wallpapers/wallpaper.jpg.zip";
				window.location = url;				
		});
	}
	
	if( $__( $( "#div-bio-box" ) ) ){
		
		$(".girl-menu").click( function(){ 
				var stringcurrent = this.id.split("-");				
				currentGirl = stringcurrent[1];
				$(".girl-menu").each( function( val , i ) {
						$("#" + this.id ).removeClass( this.id + "-current");
						$( this ).addClass( this.id );
						
				 });
				
						$("#div-bio-"+currentGirl).removeClass("bio-show");
						$("#div-bio-"+currentGirl).addClass("bio-noshow");
				
				$( this ).addClass( this.id + "-current");
				
				$("#div-bio-chatbox-"+language).attr("class","").addClass( currentGirl + "-chat");
				$("#bio-copy").html( moxieHash.girls[currentGirl].bio ); 
				$("#blog-copy").html( moxieHash.girls[currentGirl].blog );
				$("#bio-header").html('<img src='+moxieHash.girls[currentGirl].header+'>');
				$("#div-bio-image").html('<img class="center-image" src='+moxieHash.girls[currentGirl].image+'>');
				$("#link-bio").html(moxieHash.girls[currentGirl].bioheader);
				$("#link-blog").html(moxieHash.girls[currentGirl].blogheader);
							
		});
			$("#link-blog").html(moxieHash.girls[currentGirl].blogheader);
			$("#link-bio").html(moxieHash.girls[currentGirl].bioheader);
			$("#div-bio-chatbox-"+language).attr("class","").addClass( currentGirl + "-chat");
			$("#bio-copy").html( moxieHash.girls[currentGirl].bio ); 
			$("#blog-copy").html( moxieHash.girls[currentGirl].blog );
			$("#bio-header").html('<img src='+moxieHash.girls[currentGirl].header+'>');
			$("#div-bio-image").html('<img class="center-image" src='+moxieHash.girls[currentGirl].image+'>');
			
			$("#link-blog,#menu-blog").click( function(){
				$("#bio-copy").css("display","none");
				$("#blog-copy").css("display","block");
				$( this ).css("text-decoration","underline");
				$( "#link-bio" ).css("text-decoration","none");
			});

			$("#link-bio").click( function(){
				$("#blog-copy").css("display","none");
				$("#bio-copy").css("display","block");
				$( this ).css("text-decoration","underline");
				$( "#link-blog" ).css("text-decoration","none");
			});
	}	
	
	$('#div-chat-copy').cycle({ 
	    fx:    'scrollUp',
	 	speed:  1000,
	    timeout: 8000
	});

}

function checkFlashContent(){
	
	var params = { wmode : "transparent" };	
	 var attributes = {};

	 var flashvars = { };

	 swfobject.embedSWF("smarty_files/templates/flash/home_promo.swf", "div-home-promo", "630", "520", "9.0.0","expressInstall.swf", flashvars, params, attributes);  	

		setTimeout( function(){
			$("#div-btm-promo").fadeIn('slow');
		} , 2000 );

}


/* Google Analytics */

function loginRegEvent(){
	

		$("#register").click( function( ){ 
			
					$("#dialog-date").val( moxieHash.language.registration["dialog-date"] );
					$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1500 , function(){
					$("#overlay-box").css({ "display" : "block" , "opacity" : "1" });
					$("#overlay-dialog").css({ "display" : "block" , "opacity" : "1" });
					regValidateObj.checkDate();
					
					var google_conversion_label = "iMgCCKrv4AEQgIyC7wM";
					$("#google_conversion").html("<img src='http://www.googleadservices.com/pagead/conversion/1038124544/?label=iMgCCKrv4AEQgIyC7wM&amp;guid=ON&amp;script=0' border='0' />");
					
				 } );
		} );
		
		$("#logged-on").hover( function() {
			$(this).css({"cursor":"default"})
		});
		
		$("#myaccount").click(function(){
				$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1500 , function(){
				$("#login-dialog-wrapper").css({ "display" : "block" , "opacity" : "1" });
			});	
		});
		
		$("#login").click( function(){
				$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1500 , function(){
			    $("#overlay-login").css({ "opacity" : "1" , "display" : "block" });
				$("#logon-wrapper").css({ "display" : "block" , "opacity" : "1" });
				$("#forgot-wrapper").css({ "display" : "none" } );
				
				$("#a-logon-forgot").click( function(){
					setTimeout( function(){
						$("#logon-wrapper").css({ "display" : "none" ,  "opacity" : "0"  });
						$("#forgot-wrapper").css({ "opacity" : "1" , "display" : "block" });
						$("#div-forgot").css({ "display" : "block" , "opacity" : "1" });						
					} , 500 );	
				});
		
				$("#a-logon-register").click( function(){
					$("#register").click(); 
					$("#logon-dialog").css("display","none");
				});


				$(".disabled").attr("disabled",true);
				
				$(".menu-events").click(function(){
					$(".wrapper").css("display" , "none");
					$("#div-"+this.id+"-wrapper").css("display" , "block");

					$(".disabled").attr("disabled",true);

					( this.id == "profile")? $("#menu-edit").css("display","block") : $("#menu-edit").css("display","none"); 
					( this.id == "products")? buildAllProducts() : null;
					( this.id == "children")? buildAllChildAccess() : null;
					
					if(!$("#menu-my"+this.id).hasClass('menu-active')){
						$("#menu-my"+this.id).removeClass('menu-active');
						$("#menu-my"+this.id).addClass('menu-active');
					}
				});


				$("#menu-enable-edit").click(function(){
					$(".disabled").attr("disabled", false);
					$("#username").attr("disabled", true);
				 });


				$("#update-save").click( function(){
					getAllupdateElems();
				});				
			 });
		});
		
		$("#myacct-userid, #myacct-password").keypress( function(event) {
				if (event.keyCode == '13') {$("#btn-logon").click();}
		});

		$("#btn-logon").click( function() {
				$.post("?request=login" , { username: jQuery.trim( $("#myacct-userid").val() ) , website_id : website_id , password: jQuery.trim( $("#myacct-password").val() ) } , function(http){ 
					var stringBool = eval( "(" + http + ")" );
					if( stringBool == 3 ){
						alert(moxieHash.language.registration.errorcode3); 
					}
					else if( stringBool == 2 ){
						alert(moxieHash.language.registration.errorcode2); 
					}
					else if( stringBool == 0 ){ 
				 		window.location = "";
					 }
				});

		 } );
	

	
	if( $__( $("#dialog-close") ) ){
		$(".btn-close, #update-cancel, #dialog-close, #login-a-dialog-close , #logon-header-close, #forgot-header-right, #forgot-password-close").click(function(){
			$("#overlay-box,#overlay-login").css({ "display" : "none" , "opacity" : "0" });
			$("#overlay-wrapper").animate({ "opacity" : "0" , "height" : "0px" } , 1500 , function(){ $( this ).css("display" , "none"); } );
			$("#dialog-title").html(moxieHash.language.registration.dialogtitle);

			$("#dialog-content-2").css({ "display" : "none" });
			$("#dialog-content").css({ "display" : "block" });
			$("#overlay-dialog").css({ "width" : "385px" , "height" : "230px" });
			$("#reg-save").attr("id","btn-next").html(moxieHash.language.registration.btnnext);

		});
	}

		if( $__( $("#forgot-submit") ) ){
		$("#forgot-submit").click(function(){ 
			var first_name = $("#input-forgot-firstname").val();
			var input_value = $("#input-forgot-email").val();
			var radio_type = null;
			    $(".radio-forgot-password").each( function( i , val ){ if( $( this ).attr("checked") ){ radio_type = this.value; } });
			    $.post("?request=forgotpasswordbyusername", { first_name : first_name , input_value : input_value , radio_type : radio_type } , function( http ){
					if( http == 0 ){
						alert(moxieHash.language.forgotpassword.code0);
					}
					else if( http == 1 ){
						alert(moxieHash.language.forgotpassword.code1);
					}
					else if( http == 2 ){
						alert(moxieHash.language.forgotpassword.code2);
					}

			    });

		});
	}
}

function buildProfileSection(){
	$("#menu-edit,#div-all-info").css("display","block");
	$(".disabled").attr("readonly",true);
}

function buildAllChildAccess(){
	$("#div-mychildren").html("");
	$.post("?request=mychildaccess" , { parent_email_id : obj.parent_email_id } , function( http ){ 
			if( http != "false" ){
			var json_arr = eval("(" + http + ")");
			for( x in json_arr ){
				childLoop( json_arr[x] );
			}
			}
			else{
				$("#div-mychildren").html("You don't have any kids registered.");
			}

	});
} 

function buildAllActivities(){
	var stringHtml = "";
	$.post("?request=mykidactivities" , { parent_email_id : obj.parent_email_id } , function( http ){
			var json_arr = eval("(" + http + ")");
			var name = moxieHash.language.myaccount.name;
			var productsregistered = moxieHash.language.myaccount.productsregistered;
			
			for( x in json_arr ){
				if( json_arr[x]["userInfo"] ){
					stringHtml += "<ul id=\"ul-activities-name\">"
					stringHtml += "<li class=\"li-activities\" ><span>" + name + "</span><input type=\"text\" id=\"activities-name\" value=\""+ json_arr[x]["userInfo"]["first_name"]  +"\"></li>";
					stringHtml += "<li class=\"li-activities\"><span>" + productsregistered + "</span><input class=\"input-activities\" value=\"" + kidsLoop( json_arr[x] , x ) + "\"></li>";
					stringHtml +="</ul>";
				}
			}
		$("#div-activities").html( stringHtml );
	 });
}

function kidsLoop( obj_arr , i  ){
	var stringProducts = "";
	for( x in obj_arr ){
		if( obj_arr[x]["product_name"] ){
			stringProducts += obj_arr[x]["product_name"];
			if( obj_arr.length - 1 != x  ){
				stringProducts += ", ";
			} 
		}
	}
	return stringProducts = stringProducts.substr( 0 , stringProducts.length - 2 );
}

function childLoop( obj_arr ){
        var ulInfoString = "";
        var finalString = "";
        var id = moxieHash.language.myaccount.id;
        var name = moxieHash.language.myaccount.name;
        var password = moxieHash.language.myaccount.myacct_password;
		var email = moxieHash.language.myaccount.email;
		var save = moxieHash.language.myaccount.save;
		var cancel = moxieHash.language.myaccount.cancel;
		var pmychildren = moxieHash.language.myaccount.pmychildren;
		
        for( x in obj_arr ){
                if( !obj_arr[x]["user_access_id"] ){
                        /*upper part*/
                        ulInfoString += "<ul id=\"ul-mychildren-info\"><li class=\"li-children\"><div><span>" + name + "</span><input type=\"text\" class=\"input user_id"+obj_arr[x]["user_id"] +"\" id=\"mychildren-id\" value=\""+ obj_arr[x]["first_name"] +"\" name=\"first_name\"></div></li>";
                        ulInfoString += "<li class=\"li-children\"><div><span>" + id + "</span><input type=\"text\" class=\"input\" id=\"mychildren-id\" value=\""+ obj_arr[x]["user_id"] +"\" disabled></div></li>";
                        ulInfoString += "<li class=\"li-children\"><div><span>" + password + "</span><input type=\"text\" class=\"input user_id"+ obj_arr[x]["user_id"] +"\" id=\"mychildren-password\" name=\"password\" /></div></li>";
                        if( obj_arr[x]["email"] ){
                        ulInfoString += "<li class=\"li-children\"><div><span>" + email + "</span><input type=\"text\" class=\"input user_id"+ obj_arr[x]["user_id"] +"\" id=\"mychildren-email\" value=\"" + obj_arr[x]["email"] + "\" name=\"email\" /></div></li></ul>";
                        }
                }

        }
        var global_id = null;
        var string1 = "<ul id=\"ul-mychildren-info\" class=\"clear\">";
        string1 += "<p id=\"p-mychildren\" class=\"clear\">" + pmychildren + "</p>";
        for( x in obj_arr ){
                if( obj_arr[x]["user_access_id"] ){
                        global_id = obj_arr[x]["user_id"];
                        string1 += continueLoop( obj_arr[x] );
                }
        }
        string1 += "<li class=\"li-button-save\"><button id=\""+ global_id +"\" onclick=\"mychildsave( this )\">" + save + "</button><button>" + cancel + "</button></li>";
        string1 += "</ul>";
        finalString += ulInfoString;
        finalString += string1;
        $("#div-mychildren").html( $("#div-mychildren").html() + finalString );

}

function continueLoop( arr ){
                var strInfoString = "";
                return strInfoString += "<li class=\"li-children\"><span>"+ arr["website_domain"]  +":</span><input type=\"checkbox\" "+ checkedState( arr )+" class=\"user_id"+ arr["user_id"] +"\" name=\""+ arr["user_access_id"]+"\" /></li>";
}

function checkedState(arr){
        if( arr["access_bool"] == "1" ){
                return "checked=\"checked\"";
        }
}


function mychildsave( obj ){
      var json_send = {};
      $(".user_id" + obj.id ).each(function( i , val ){
                 if( $(this).is('input:checkbox') ){
                                json_send[ "website_" + $( this ).attr("name") ] = $( this ).attr("name") + "," + checkboxstatus( $( this ).attr("checked") );
                }
                 else{
                        if( $( this ).val()  != "" ){
                                 json_send[ $( this ).attr("name") ] = $( this ).attr("name") + "," + $( this ).val();
                       }
                 }
         });
 
        json_send.user_id = "user_id," + obj.id;

         $.post("?request=childrenupdate" , json_send , function(){

          } );
 }


function checkboxstatus( val ){
         if( val == "true" || val == true ){
                 return "1";
         }
         else{
                 return "0";
         }
}

function buildAllProducts(){
	var json_arr;

	var website_obj = { "1" : ["nara_icon_logo_v2.png", "160px"] , "2" : ["bitty_icon_logo_v2.png", "160px"] , "3" : ["bratz_icon_logo_v2.png","110px"] , "4" : ["moxieteenz_icon_logo_v2.png", "110px"] }

	$.post("?request=myproducts" , { id : obj.id } , function( http ){ 
		
		if( http ){
			json_arr = eval("(" + http + ")");	
			var sku = "";
			for( x in json_arr ){
				if( json_arr[x]["website_id"] == website_id ){
			
					if( json_arr[x]["sku"] != "undefined" || json_arr[x]["sku"] != undefined ){
						sku += "<li class=\"li-products\" >";
						sku += "<img class=\"div-product-image\" src=\"http://c2154692.cdn.cloudfiles.rackspacecloud.com/" + jQuery.trim(json_arr[x]["product_key"]) + ".png\" />";
						sku += "<span>" + json_arr[x]["product_name"]  + "</span>";
						sku += "</li>";
					}
				}
			}
			
			$("#ul-products").html( sku );
			$("#product-website").css( { "width" : website_obj[website_id][1] , "background-image" : "url(http://c2154692.cdn.cloudfiles.rackspacecloud.com/"+ website_obj[ website_id ][0]  +")" } );
		
		}
		else{
			$("#ul-products").html( "You currently don't any items registered." );
		}
	});

	$("#sort-by-website").change( function(){
		var sku = "";
		for( x in json_arr ){
                                if( json_arr[x]["website_id"] == this.value ){
                                        if( json_arr[x]["sku"] != "undefined" || json_arr[x]["sku"] != undefined ){
						sku += "<li class=\"li-products\" >";
                                                sku += "<img class=\"div-product-image\" src=\"http://c2154692.cdn.cloudfiles.rackspacecloud.com/" + json_arr[x]["product_key"] + ".png\" />";
                                                sku += "<span>" + json_arr[x]["product_name"]  + "</span>";
                                                sku += "</li>";

                                        }

                                }
               }
		$("#ul-products").html( sku );
		$("#product-website").css( { "width" : website_obj[this.value][1] , "background-image" : "url(http://c2154692.cdn.cloudfiles.rackspacecloud.com/"+ website_obj[this.value][0]  +")" } );
	});
}

function getAllupdateElems(){
	var obj_ = { };
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

	if( $("#first_name").val().length >= 2 ){
		obj_.first_name = "first_name," + $("#first_name").val();
		$("#first_name").css("border","1px solid #AFAFAF");	
	}
	else{
		$("#first_name").css("border","1px solid red");	
	}

	if( $("#last_name").val().length >= 2 ){
		obj_.last_name = "last_name," + $("#last_name").val();
		$("#last_name").css("border","1px solid #AFAFAF");	
	}
	else{
		$("#last_name").css("border","1px solid red");	
	}

	if( $("#password").val() != "" || $("#password").val() != "******" ){
		if( $("#password-confirm").val() != $("#password").val() ){
			$("#password-match").html("Your password doesn't match.");
		}
		else{
			$("#password-match").html("");
			obj_.password = "password," + $("#password").val();
		}
	}

	if( filter.test( $("#email").val() ) ){
		obj_.email = "email," + $("#email").val();
	 }

	if( $("#myacct-postal_code").val().length > 4 ){
		obj_.postal_code = "postal_code," + $("#myacct-postal_code").val();
		$("#myacct-postal_code").css("border","1px solid #AFAFAF");	
	}
	else{
		$("#myacct-postal_code").css("border","1px solid red");	
	}


	obj_.country_id = "country_id," + $("#choose-country option:selected").attr("id");
	obj_.state_id = "state_id," + $("#choose-state option:selected").attr("id");
	obj_.gender = ( $("#input-f").attr("checked") )? "gender,f" : "gender,m";
	obj_.user_id = "user_id," + obj.id ;

	$.post("?request=regupdate" , obj_ , function( http ){ });


}

function buildCountry(){
	var obj = moxieHash.countryList;
	var stringCountry = "";
	for( x in obj ){
		stringCountry += "<option id=\""+ obj[x]["country_id"] +"\" " + selectCountry( obj[x]["country_id"] ) + ">"+ obj[x]["local_name"] + "</option>";
	}
	$("#choose-country").html( stringCountry ).change( function(){
			getBuildState( this.options[ this.selectedIndex ].id );
	 });	
}

function selectCountry( current_id ){
	if( current_id == obj.country_id ){
		return "selected=\"selected\"";
	}
}

function getBuildState( id ){
	var state = moxieHash.stateList[ id ];
	var stringState = "";
	for( x in state ){
		stringState += "<option id=\""+ state[x]["state_id"] +"\">" + state[x]["local_name"] + "</option>";
	}
	$("#choose-state").html( stringState );	
}

function getBuildState2( id ){
	var state = moxieHash.stateList[ id ];
	var selectone = moxieHash.language.registration.selectone;
	
	var stringState = "<option id=\"0\">" + selectone + "</option>";
	for( x in state ){
		stringState += "<option value=\""+ state[x]["state_id"] +"\">" + state[x]["local_name"] + "</option>";
	}
	$("#reg-signup-state").html( stringState );	
}

function buildState(){
	var state = moxieHash.stateList[ obj.country_id ];
	var stringState = "";
	for( x in state ){
		stringState += "<option id=\""+ state[x]["state_id"] +"\" "+ selectState( state[x]["state_id"] ) +" >" + state[x]["local_name"] + "</option>";
	}
	$("#choose-state").html( stringState );	
}

function selectState( current_id ){
	if( current_id == obj.state_id ){
		return "selected=\"selected\"";
	}
	else{
		return "";
	}
}

function loginTabs() {

	if(obj.id){
			var toplinks = parseInt( (obj.username.length * 19) + 3 ) + "px";
			$("#div-top-links").css("width", toplinks);
	}
	
}


function logValidation(){
	if(obj.id){
			$("#login").click( function(){
				
				$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1500 , function(){
						$("#logon-wrapper").css({"display" : "none"});
						$("#login-dialog-wrapper").css({"display" : "none"}).animate({ "opacity" : "1" , "height" : "408px" , "width" : "628px"} , 500 , function(){
							
							if( obj.acct_type == "parent" ){
								$("#myacct-header-left").html("Parent Console");
								$(".li-parent-email").css("display","none");
								$("#first_name").val(obj.first_name);
								$("#username").val(obj.username);
								$("#input-" + obj.gender ).attr("checked","checked");
								$("#email").val( obj.email );
								buildCountry();
								buildState();
								$("#myacct-postal_code").val( obj.postal_code );
							}
							
							else if( obj.acct_type == "child" ){
								$("#div-myacct-location,.li-child-email").css("display","none");
								$("#myacct-header-left").html("MyAccount");
								$(".li-parent-email").css("display","block");
								$("#first_name").val(obj.first_name);
								$("#username").val(obj.username);
								$("#parent-email-account").val(obj.parent_email);

								$("#input-" + obj.gender ).attr("checked","checked");
								$("#menu-mychildren, #menu-myactivities").css("display","none");

							}
							else if( obj.acct_type == "teen" ){
									$("#myacct-header-left").html("Parent Console");
									$(".li-parent-email").css("display","block");
									$("#first_name").val(obj.first_name);
									$("#username").val(obj.username);
									$("#input-" + obj.gender ).attr("checked","checked");
									$("#email").val( obj.email );
									buildCountry();
									buildState();
									$("#myacct-postal_code").val( obj.postal_code );
							}
							else{
								$("#myacct-header-left").html("My Account");
							}
						});//end function
				});//end function	
			} );//end function
				
		
			$("#logout").click( function(){ 
				$.post("?request=logout",function( ){
					window.location = "";
				});
			} );//end function
		
		
		
			$("#myaccount").click( function(){
				$("#password").val("******");
				$("#password-confirm").val("");
				$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1500 , function(){

					$("#logon-wrapper").css({"display" : "none"});
					$("#overlay-login,#login-dialog-wrapper,#div-myacct,#div-profile-wrapper,#login-ul-dialog-header,#div-all-info").css({"display" : "block","opacity" : "1"});

					$("#login-dialog-wrapper").css({"display" : "none"}).animate({ "opacity" : "1" , "height" : "408px" , "width" : "628px"} , 500 , function(){
						if( obj.acct_type == "parent" ){
								$("#myacct-header-left").html(moxieHash.language.myaccount.myacctheadertext);
								$(".li-parent-email").css("display","none");
								$("#first_name").val(obj.first_name);
								$("#last_name").val(obj.last_name);
								$("#username").val(obj.username);
								$("#input-" + obj.gender ).attr("checked","checked");
								$("#email-account").val( obj.email );
								buildCountry();
								buildState();
								$("#myacct-postal_code").val( obj.postal_code );
						}
						else if( obj.acct_type == "child" ){
								$("#div-myacct-location,.li-child-email").css("display","none");
								$("#myacct-header-left").html("MyAccount");
								$(".li-parent-email").css("display","block");
								$("#first_name").val(obj.first_name);
								$("#last_name").val(obj.last_name);
								$("#username").val(obj.username);
								$("#parent-email-account").val(obj.parent_email);

								$("#input-" + obj.gender ).attr("checked","checked");
								$("#menu-mychildren, #menu-myactivities").css("display","none");

						}
						else if( obj.acct_type == "teen" ){
								$("#myacct-header-left").html("Parent Account");
								$(".li-parent-email").css("display","block");
								$("#first_name").val(obj.first_name);
								$("#last_name").val(obj.last_name);
								$("#username").val(obj.username);
								$("#input-" + obj.gender ).attr("checked","checked");
								$("#email").val( obj.email );
								buildCountry();
								buildState();
								$("#myacct-postal_code").val( obj.postal_code );
						}
						else{
								$("#myacct-header-left").html("My Account");
						}

						$(".disabled").attr("readonly",true);

                    	$(".menu-events").click(function(){
                                        $(".wrapper,.li-password-confirm").css("display" , "none");
                                        $("#div-"+this.id+"-wrapper,#div-myacct-menu").css({"display":"block","opacity":"1"});
										$(".disabled").attr("readonly",false);
										
                                        ( this.id == "profile") ? buildProfileSection() : $("#menu-edit,#div-all-info").css("display","none");
                                        ( this.id == "products") ? buildAllProducts() : null;
                                        ( this.id == "children") ? buildAllChildAccess() : null;
                                        ( this.id == "activities") ? buildAllActivities() : null;

                                        $("#menu-myprofile").removeClass('menu-active');
                                        $("#menu-myproducts").removeClass('menu-active');
                                        $("#menu-myscores").removeClass('menu-active');
                                        $("#menu-mychildren").removeClass('menu-active');
                                        $("#menu-myactivities").removeClass('menu-active');
                                        
                                        if(!$("#menu-my"+this.id).hasClass('menu-active')){
                                                $("#menu-my"+this.id).removeClass('menu-active');
                                                $("#menu-my"+this.id).addClass('menu-active');
                                        }
                                        
                                        if (this.id != "profile") {
											if(!$("#div-"+this.id+"-wrapper").hasClass('show wrapper')){
                                                $("#div-"+this.id+"-wrapper").removeClass('show wrapper');
                                                $("#div-"+this.id+"-wrapper").addClass('show wrapper');
                                       		}
										}
                                        
                                        /*
                                        
                                        */
                                        
                     	});//end function

                    	 $("#menu-enable-edit").click(function(){
                    	                if ( $(".disabled").attr("readonly") ) {
                                        	$(".disabled").attr("readonly", false);
                                        	$("#username,#email-account,#parent-email-account").attr("readonly", true);
											$(".li-password-confirm").css("display","block");
											passwordListener();
										} else {
											$(".disabled").attr("readonly", true);
                                        	$(".li-password-confirm").css("display","none");
										}
						});//end function

                		$("#update-save").click( function(){
                			getAllupdateElems();
						});

					});//end function

				});	//end function
			} );//end click function()
		}

	else{
		$("#login").click( function(){
			$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1500 , function(){
				$("#logon-wrapper").css({ "display" : "block" , "opacity" : "1" });
			});
		});
	}
	
}//end function


function passwordListener(){
	$("#password").click( function(){ 
		if( this.value == "******" ){
			this.value = "";
		}
	}).blur( function(){ 
		if( this.value == "" ){
			this.value = "******";
		}
	});
}

var badwords = null;

var countryReady = false;

var regValidateObj = { 
	json_send : { } ,
	checkDate : function(){
		$("#btn-next").click( function( ){ 

			$("#dialog-calendar").css({ "display" : "none", "opacity" : "0" });
			$("#user-info-signup").css({ "display" : "block", "opacity" : "1" });

				if($("#dialog-date").val() != "yyyy-mm-dd" ){
					if( badwords != null ){
					regValidateObj.getAccount_type( $("#dialog-date").val() );
					regValidateObj.hideElem();
					regValidateObj.expandBuilt();
					}
					else{
					$.post("?request=loadbadwords",{},function( http ){ badwords = eval( "(" + http + ")" ); });
					regValidateObj.getAccount_type( $("#dialog-date").val() );
					regValidateObj.hideElem();
					regValidateObj.expandBuilt();
					}
				}
				else{
					alert(moxieHash.language.registration.errordob);
				}
		});

        }
	, 

	getAccount_type: function( dob ){
		var expl =  dob.split("-");	
		var d = new Date();
		var age = ( d.getFullYear() - expl[0] );

		if( age > 17 ){
			regValidateObj.json_send.acct_type = "parent";
		}
		else if( age <= 17 && age > 12 ){
			regValidateObj.json_send.acct_type = "teen";
		 }
		else{
			regValidateObj.json_send.acct_type = "child";
		}

	}
	,
	hideElem : function(){ 
			if( regValidateObj.json_send.acct_type == "child" ){
				$("#user-optins,#user-location-signup,.li-child-email").css("display","none");
				$(".li-parent-email").css("display","block");
			}
			else if( regValidateObj.json_send.acct_type == "parent" ){
				$("#user-optins,#user-location-signup,.li-child-email").css("display","block");
				$(".li-parent-email").css("display","none");
				regValidateObj.countrybuild();
				countryReady = true;
			}
			else{ 
				$("#user-optins,#user-location-signup,.li-child-email").css("display","block");
				regValidateObj.countrybuild();
				countryReady = true;
			}
	}
	,
	expandBuilt : function(){
		$("#dialog-content , #btn-next").css("display" , "none");
			$("#overlay-dialog").animate({ "width" : "705px" , "height" : "345px" } , 2000 , function(){
				$("#dialog-content-2").css({"display" : "block" , "height" : "260px" });
				$("#btn-next").css("display" , "block").attr("id","reg-save").html(moxieHash.language.registration.btnsubmit);
				$("#dialog-title").html(moxieHash.language.registration.dialogtitle2);
				regValidateObj.allElems();
		} );
        }
	,
	allElems : function(){
		$("#reg-save").click( function( evt ){
				evt.stopImmediatePropagation();

				if( regValidateObj.json_send.acct_type == "parent" ){
					regValidateObj.parentAcct();
				}
				else if( regValidateObj.json_send.acct_type == "teen" ){
					regValidateObj.teenAcct();
				}
				else{
					regValidateObj.childAcct();
				}

		})
	}
	,

	countrybuild : function(){ 

	if( countryReady == false ){
	var obj = moxieHash.countryList;
	var selectone = moxieHash.language.registration.selectone;
        var stringCountry = "<option id=\"0\" value=\"" + selectone + "\">" + selectone + "</option>";
        for( x in obj ){
                stringCountry += "<option id=\""+ obj[x]["country_id"] +"\" value=\""+ obj[x]["country_id"] +"\" >"+ obj[x]["local_name"] + "</option>";
        }

        $("#reg-signup-country").html( stringCountry ).change( function(){
                        getBuildState2( this.options[ this.selectedIndex ].id );
         });

	}
	

	}
	,
	elem : function( obj ){

	} 
	,
	parentAcct : function(){
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		var arr = new Array();
		var json_send = {};

		if( $("#reg-signup-first_name").val() == "" ){
			$("#reg-signup-first_name").css("border","1px solid red");	
			arr[0] = false;
		}
		else{
			$("#reg-signup-first_name").css("border","1px solid #CFCFCF");	
			json_send.first_name = "first_name," +  $("#reg-signup-first_name").val(); 
		}

		if( $("#reg-signup-username") ){
			if( $("#reg-signup-username").val() == "" ){
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
			}
			else {
				var arr_bad = badwords;
			for( x in arr_bad ){
				if( arr_bad[x]  == $("#reg-signup-username").val() ){ 
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
					break;
				}		
				else{
					$("#reg-signup-username").css("border","1px solid #CFCFCF");	
				}
			} 

			( arr[1] == false ) ? null : json_send.username = "username," + $("#reg-signup-username").val();

			}
		}

		if( $("#reg-signup-password").val() == "" ){
			$("#reg-signup-password").css("border","1px solid red");	
			arr[2] = false;
		}
		else{
			$("#reg-signup-password").css("border","1px solid #CFCFCF");	
			json_send.password = "password," +  $("#reg-signup-password").val(); 
		}

		if( filter.test( $("#reg-signup-email").val() ) ){
			$("#reg-signup-email").css("border","1px solid #CFCFCF");	
			json_send.email = "email," +  $("#reg-signup-email").val(); 
		}
		else{
			$("#reg-signup-email").css("border","1px solid red");	
			arr[3] = false;
		}

		if( $("#reg-signup-country").val() != moxieHash.language.registration.selectone){
			$("#reg-signup-country").css("border","1px solid #CFCFCF");	
			json_send.country = "country_id," +  $("#reg-signup-country").val(); 
		}
		else{
			$("#reg-signup-country").css("border","1px solid red");	
			arr[4] = false;
		}

		if( $("#reg-signup-state").val() != moxieHash.language.registration.selectone){
			$("#reg-signup-state").css("border","1px solid #CFCFCF");	
			json_send.state = "state_id," +  $("#reg-signup-state").val(); 
		}
		else{
			$("#reg-signup-state").css("border","1px solid red");	
			arr[5] = false;
		}

		if( $("#reg-signup-zip").val() != "" ){
			$("#reg-signup-zip").css("border","1px solid #CFCFCF");	
			json_send.zip = "postal_code," +  $("#reg-signup-zip").val(); 
		 }
		else{
			$("#reg-signup-zip").css("border","1px solid red");	
			arr[6] = false;
		 }

		if( $("#reg-signup-last_name").val() == "" ){
			$("#reg-signup-last_name").css("border","1px solid red");	
			arr[7] = false;
		}

		else{
			$("#reg-signup-last_name").css("border","1px solid #CFCFCF");	
			json_send.last_name = "last_name," +  $("#reg-signup-last_name").val(); 
		}
		
		json_send.parent_email = "parent_email," + $("#reg-signup-email").val(); 
		json_send.gender = ( $("#reg-signup-f").attr("checked") )? "gender,f" : "gender,m";
		json_send.acct_type = "acct_type,parent";
		json_send.option_1 = ( $("#option_1").attr("checked") == true )? "optins_1,brands,1" : "optins_1,brands,0";
		json_send.option_2 = ( $("#option_2").attr("checked") == true )? "optins_2,other_brands,1" : "optins_2,other_brands,0";
		json_send.option_3 = "optins_3,website_id,4";
		json_send.option_4 = "optins_4,email_my_child,1";
                json_send.dob = "dob," + $("#dialog-date").val();  


		if( arr.length == 0 ){
			$.post("?request=register", json_send , function( http ){
				if( http != "" ){
					var returnObj = eval( "(" + http  + ")" );
					if( returnObj["error"] ){
						//alert( returnObj["error"] );						
						alert(moxieHash.language.registration[ "errorcode" + returnObj["error"] ]);
					}
					else{ 
						$("#dialog-content-2,#dialog-parent-wrapper").css({ "display" : "none", "opacity" : "0" });
                        $("#overlay-dialog,dialog-reg-complete").css({ "display" : "block" , "opacity" : "1" });
						$("#overlay-dialog").css({ "background" : "none" , "border" : "none" });
						$("#dialog-header,#dialog-content-2,#dialog-bottom").css("display", "none");
						$("#dialog-reg-complete").css("display","block","background-color","#CFCFCF");
						
						$("#span-reg-complete-username").html(moxieHash.language.registration.labelusername + $("#reg-signup-username").val() );
                        $("#span-reg-complete-password").html(moxieHash.language.registration.labelpassword + $("#reg-signup-password").val() );

						$("#complete-btn-close,#reg-complete-close").click( function(){
							window.location = "";
						 });
					}

				}
			});
		}	

	}
	,
	teenAcct : function(){
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		var arr = new Array();
		var json_send = {};

		if( $("#reg-signup-first_name").val() == "" ){
			$("#reg-signup-first_name").css("border","1px solid red");	
			arr[0] = false;
		}
		else{
			$("#reg-signup-first_name").css("border","1px solid #CFCFCF");	
			json_send.first_name = "first_name," +  $("#reg-signup-first_name").val(); 
		}

		if( $("#reg-signup-username") ){
			if( $("#reg-signup-username").val() == "" ){
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
			}
			else {
				var arr_bad = badwords;
			for( x in arr_bad ){
				if( arr_bad[x]  == $("#reg-signup-username").val() ){ 
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
					break;
				}		
				else{
					$("#reg-signup-username").css("border","1px solid #CFCFCF");	
				}
			} 

			( arr[1] == false ) ? null : json_send.username = "username," + $("#reg-signup-username").val();

			}
		}

		if( $("#reg-signup-password").val() == "" ){
			$("#reg-signup-password").css("border","1px solid red");	
			arr[2] = false;
		}
		else{
			$("#reg-signup-password").css("border","1px solid #CFCFCF");	
			json_send.password = "password," +  $("#reg-signup-password").val(); 
		}

		if( filter.test( $("#reg-signup-parent_email").val() ) ){
			$("#reg-signup-parent_email").css("border","1px solid #CFCFCF");	
			json_send.parent_email = "parent_email," +  $("#reg-signup-parent_email").val(); 
		}
		else{
			$("#reg-signup-parent_email").css("border","1px solid red");	
			arr[3] = false;
		}

		if( filter.test( $("#reg-signup-email").val() ) ){
			$("#reg-signup-email").css("border","1px solid #CFCFCF");	
			json_send.email = "email," +  $("#reg-signup-email").val(); 
		}
		else{
			$("#reg-signup-email").css("border","1px solid red");	
			arr[4] = false;
		}

		if( $("#reg-signup-country").val() != moxieHash.language.registration.selectone){
			$("#reg-signup-country").css("border","1px solid #CFCFCF");	
			json_send.country = "country_id," +  $("#reg-signup-country").val(); 
		}
		else{
			$("#reg-signup-country").css("border","1px solid red");	
			arr[5] = false;
		}

		if( $("#reg-signup-state").val() != moxieHash.language.registration.selectone){
			$("#reg-signup-state").css("border","1px solid #CFCFCF");	
			json_send.state = "state_id," +  $("#reg-signup-state").val(); 
		}
		else{
			$("#reg-signup-state").css("border","1px solid red");	
			arr[6] = false;
		}

		if( $("#reg-signup-zip").val() != "" ){
			$("#reg-signup-zip").css("border","1px solid #CFCFCF");	
			json_send.zip = "postal_code," +  $("#reg-signup-zip").val(); 
		 }
		else{
			$("#reg-signup-zip").css("border","1px solid red");	
			arr[7] = false;
		 }
		
		if( $("#reg-signup-last_name").val() == "" ){
			$("#reg-signup-last_name").css("border","1px solid red");	
			arr[8] = false;
		}
		else{
			$("#reg-signup-last_name").css("border","1px solid #CFCFCF");	
			json_send.last_name = "last_name," +  $("#reg-signup-last_name").val(); 
		}

		json_send.gender = ( $("#reg-signup-f").attr("checked") )? "gender,f" : "gender,m";
		json_send.acct_type = "acct_type,teen";
		json_send.option_1 = ( $("#option_1").attr("checked") == true )? "optins_1,brands,1" : "optins_1,brands,0";
		json_send.option_2 = ( $("#option_2").attr("checked") == true )? "optins_2,other_brands,1" : "optins_2,other_brands,0";
		json_send.option_3 = "optins_1,website_id,4";
                json_send.dob = "dob," + $("#dialog-date").val();  


		if( arr.length == 0 ){
			if( jQuery.trim( $("#reg-signup-email").val() ) == jQuery.trim( $("#reg-signup-parent_email").val() ) ){
				alert(moxieHash.language.registration.erroremailmatch);
			 }
			else{
			$.post("?request=register", json_send , function( http ){
				if( http != "" ){
					var returnObj = eval( "(" + http  + ")" );
					if( returnObj["error"] ){
						//alert( returnObj["error"] );						
						alert(moxieHash.language.registration[ "errorcode" + returnObj["error"] ]);
					}
					 else{     
						$("#dialog-content-2,#dialog-parent-wrapper").css({ "display" : "none", "opacity" : "0" });
                        $("#overlay-dialog,dialog-reg-complete").css({ "display" : "block" , "opacity" : "1" });
                        $("#dialog-header,#dialog-content-2,#dialog-bottom").css("display", "none");
						$("#overlay-dialog").css({ "background" : "none" , "border" : "none" });
						$("#dialog-reg-complete").css("display","block","background-color","#CFCFCF");

						$("#span-reg-complete-username").html(moxieHash.language.registration.labelusername + $("#reg-signup-username").val() );
                        $("#span-reg-complete-password").html(moxieHash.language.registration.labelpassword + $("#reg-signup-password").val() );

                        $("#complete-btn-close,#reg-complete-close").click( function(){ 
                        	window.location = "";
                        });


                                        }


				}
			});
			}
		}	
	 }
	,
	childAcct : function(){
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		var arr = new Array();
		var json_send = {};

		if( $("#reg-signup-first_name").val() == "" ){
			$("#reg-signup-first_name").css("border","1px solid red");	
			arr[0] = false;
		}
		else{
			$("#reg-signup-first_name").css("border","1px solid #CFCFCF");	
			json_send.first_name = "first_name," +  $("#reg-signup-first_name").val(); 
		}

		if( $("#reg-signup-username") ){
			if( $("#reg-signup-username").val() == "" ){
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
			}
			else {
			var arr_bad = badwords;
			for( x in arr_bad ){
				if( arr_bad[x]  == $("#reg-signup-username").val() ){ 
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
					break;
				}		
				else{
					$("#reg-signup-username").css("border","1px solid #CFCFCF");	
				}
			} 

			( arr[1] == false ) ? null : json_send.username = "username," + $("#reg-signup-username").val();

			}
		}

		if( $("#reg-signup-password").val() == "" ){
			$("#reg-signup-password").css("border","1px solid red");	
			arr[2] = false;
		}
		else{
			$("#reg-signup-password").css("border","1px solid #CFCFCF");	
			json_send.password = "password," +  $("#reg-signup-password").val(); 
		}

		if( filter.test( $("#reg-signup-parent_email").val() ) ){
			$("#reg-signup-parent_email").css("border","1px solid #CFCFCF");	
			json_send.parent_email = "parent_email," +  $("#reg-signup-parent_email").val(); 
		}
		else{
			$("#reg-signup-parent_email").css("border","1px solid red");	
			arr[3] = false;
		}

		if( $("#reg-signup-last_name").val() == "" ){
			$("#reg-signup-last_name").css("border","1px solid red");	
			arr[4] = false;
		}

		else{
			$("#reg-signup-last_name").css("border","1px solid #CFCFCF");	
			json_send.last_name = "last_name," +  $("#reg-signup-last_name").val(); 
		}

		json_send.acct_type = "acct_type,child";
		json_send.gender = ( $("#reg-signup-f").attr("checked") )? "gender,f" : "gender,m";
                json_send.dob = "dob," + $("#dialog-date").val();  



		if( arr.length == 0 ){
			$.post("?request=register", json_send , function( http ){
				if( http != "" ){
					var returnObj = eval( "(" + http  + ")" );
					if( returnObj["error"] ){
						//alert( returnObj["error"] );						
						alert(moxieHash.language.registration[ "errorcode" + returnObj["error"] ]);
					}
					 else{     
						$("#dialog-content-2,#dialog-parent-wrapper").css({ "display" : "none", "opacity" : "0" });
                        $("#overlay-dialog,dialog-reg-complete").css({ "display" : "block" , "opacity" : "1" });
                        $("#dialog-header,#dialog-content-2,#dialog-bottom").css("display", "none");
						$("#overlay-dialog").css({ "background" : "none" , "border" : "none" });
						$("#dialog-reg-complete").css("display","block","background-color","#CFCFCF");

						$("#span-reg-complete-username").html(moxieHash.language.registration.labelusername + $("#reg-signup-username").val() );
                        $("#span-reg-complete-password").html(moxieHash.language.registration.labelpassword + $("#reg-signup-password").val() );

                        $("#complete-btn-close,#reg-complete-close").click( function(){ 
                        	window.location = "";
                        });

					}

				}
			});
		}	
	
	}

}

function showDiv(pass){
		 if (document.getElementById(pass)) { 
		 var obj = document.getElementById(pass); 
		 obj.style.display = (obj.style.display=='block')?'none':'block'; 
		 } 
		 return false; 

}


function  GoogleListener(){
	//	objGoogleAEventAttach[ page ]();			
}

function enableCalendar(){
	if( $__( $( "#calendar" ) ) ){
                $("#calendar").click( function(){
                	$("#dialog-calendar").css({ "display" : "block", "opacity" : "1" });			
                        $("#dialog-calendar").datepicker( {
                                                 onSelect: function(dateText, inst) { $("#dialog-date").val(dateText); $( "#dialog-calendar" ).datepicker( "destroy" ); },
                                                 changeMonth: true ,
                                                 changeYear: true ,
                                                 yearRange: "1900:2010" ,
                                                 dateFormat : "yy-mm-dd"
	                  } );
		} );
		
	}

}

var objGoogleAEventAttach = {

	promos : function(){
	},

	downloads : function(){

			$(".google-a-icon").click( function(){ } );
			$(".google-a-wallpaper").click( function(){ } );
			$(".google-a-screensaver").click( function(){ } );
	},

	bittymeet : function(){ 

		if( page == "bittymeet" ){
			objCallEventTracker( new Object() , 4 );	
		}

	},

	blogs : function(){ 

	},

	catalog : function(){ 

	},

	wishlist : function(){ 

	}

}

function objCallEventTracker( obj , id ){
	alert( obj );
	alert( id );
}

function setMuteCookie(){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+50);
	document.cookie="volOff=1;expires="+exdate.toGMTString() + ";";
}

function setCookie( name , value ){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+50);
	document.cookie="" + name + "=" + value + ";expires="+exdate.toGMTString() + ";";
}

function removeMuteCookie(){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()-50);
	document.cookie="volOff=1;expires="+exdate.toGMTString() + ";" + ";";
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}


function deleteCookie( name ){
	var expdate = new Date();
	expdate.setTime(expdate.getTime() - 1);
	return	document.cookie = name += "=; expires=" + expdate.toGMTString();
}

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});


