$( document ).ready( function(){ 
	jcarousel();
});

function $_( idSender ){
	return document.getElementById( idSender );
}

/* main object works like a controller calls a factory and a event class */
function main( s_objname_fp ){

	this.o_construct = __construct;
	this.o_factory; 
	this.s_objname;
	this.o_attach;

	function __construct(){
		/* instanciating factory to create lang , gallery , form , acctuil */
		this.o_factory = new factorycreateobjs();
		/* calling attachEventObjs  */
		this.o_attach = new attachEventObjs( this.o_factory );
		return this.o_factory;
	}

	function setCallBack( s_objname_fp ){
		/* keeps a reference of its self*/
		this.s_objname = s_objname_fp;
	}

}

function attachEventObjs( o_main_fp ){
	/* this is a event binder more object could be attach to this array as needed*/
	this.o_main_fp = o_main_fp;
	this.a_object_holder = new Array();

	this.a_object_holder["login"] = new loginEvent(  this.o_main_fp );
	this.a_object_holder["register"] = new registerEvent( this.o_main_fp );
	this.a_object_holder["redirect"] = new redirect();
	this.a_object_holder["login-menu"] = new loginMenuEvent( );
	this.a_object_holder["download"]	= new downloadEvent( this.o_main_fp );
	this.a_object_holder["gallery"] 	= new galleryEvent( this.o_main_fp );
	this.a_object_holder["invite_code"]	= new invitecodeEvent( this.o_main_fp );
	this.a_object_holder["secret_game"] 	= new secretgameEvent( this.o_main_fp );
	this.a_object_holder["choose_country"]  = new choosecountryEvent( this.o_main_fp );
	this.a_object_holder["video"]		= new videoEvent( );
	this.a_object_holder["videoplay"]	= new videoplayEvent();
	this.a_object_holder["links"]		= new linkEvents();
	this.a_object_holder["ruwheretobuy"] = new ruWhereToBuy();
	this.a_object_holder["subcategory"]		= new subcategoryEvent( this.o_main_fp );
	this.a_object_holder["wishlist"]		= new wishlistEvent( this.o_main_fp );
	this.a_object_holder["frontgallery"]		= frontgallery( );
	this.a_object_holder["logout"]		= logoutEvent( );
	secretCode();
	sweeps();
	hiddenGame();
	loadCoupons();
	rotateHomePromos();
	spanishPromo();
}

function factorycreateobjs(){
	/* this is the factory class that holds all objects need such as lang , util and ani that gallery needs, its all in one place more class and be added*/
	this.createobjs = createobjs;
	this.o_container = {}

	function createobjs(){
		this.o_container.lang = new createlang();
		this.o_container.util = new createutils();
		this.o_container.anim = new createanim();
		return this.o_container;
	}

}

function loadCoupons(){
	
	var baseLocal = "http://localhost/latest_moxiegirlz_onstage/";
	
	var params = { wmode : "transparent" };
	params.base = base + "smarty_files/templates/flash/coupons/moxie_coupons_flash/";
	var attributes = { };
	var flashvars = { couponXML : "couponXML/moxie.xml" };
	
	if(couponSource){
		flashvars.source = couponSource;

	}else{
		flashvars.source = "web";
	}
	
	swfobject.embedSWF("smarty_files/templates/flash/coupons/moxie_coupons_flash/FallCouponApplication.swf", "moxie-coupon", "800", "600", "9.0.0","smarty_files/templates/flash/expressInstall.swf", flashvars, params, attributes);
	
}

function createlang(){
/* holds a pointer to accutil and returns it back to the factory */
	        // get the account utils loading in the background
        o_acctutil = new acctUtils('o_acctutil', s_interfacelangpath,
                        s_langlistpath, s_skinlistpath, s_langcode, DEF_SKINCOOKIE,
                        DEF_LANGCOOKIE, DEF_REGPATH, DEF_LOGINPATH, DEF_ACCTINFOPATH,
                        DEF_ACCTMAINTPATH);
        o_acctutil.setCtrlDivs(DEF_CTRLCOVER, DEF_CTRLDIALOG);
        return o_acctutil;
}

function createutils(){
	/* holds a pointer to Utils and returns it back to the factory */
	var o_utils = new siteUtils("o_utils");
	    return o_utils;
}

function createanim(){
/* holds a pointer to animation class and returns it back to the factory */
	var o_anim = new animObj('o_anim');
	    return o_anim;

}

/* on page complete window on loads calls a method with name declaration __call which 
	creates a pointer to the main object which creates a factory object , and calls attach events.
*/

var o_main; /* this is global incase some object outside the framework needs to use it, such as a function being called from html like onclick, onmouse etc*/
window.onload = __call; 

function __call(){
	o_main = new main("o_main");
	o_main.o_construct();
	$("#p-login-area").css( { "visibility" : "visible" } );

	checkSecretCookieEnable();

}


/* events start here which are called from attachEvent object */

function loginEvent( o_attachevent_fp ){
/* this object checks for login-btn id selector if found will  call doInitLoginForm which appends the login html form to div-ctrl*/
	if( $_("a-login") ){	
		$_("a-login").onclick = function(){ 
			 doInitLoginForm( o_attachevent_fp.createobjs().lang );
		 }
	}
	if( $_("login-btn") ){	
		$_("login-btn").onclick = function(){ 
			 doInitLoginForm( o_attachevent_fp.createobjs().lang );
		 }
	}
	/* country login*/
	if( $_("a-login-signin-btn-" + language ) ){
		$_("a-login-signin-btn-" + language ).onclick = function(){
			doInitLoginForm( o_attachevent_fp.createobjs().lang );
		}
	}
}

function redirect(){


	var currentWebsite = "";
	var arr = new Array();
	     	arr["a-buy-toysrus"] = "http://www.toysrus.com/moxie";
			arr["a-buy-target"] = "http://www.target.com/gp/search/176-1590015-1667608?field-keywords=moxie+girlz&url=index%3Dtarget%26search-alias%3Dtgt-index&ref=sr_bx_1_1&x=0&y=0";
			arr["a-buy-walmart"] = "http://www.walmart.com/search/search-ng.do?search_constraint=0&ic=48_0&search_query=moxie+girlz&Find.x=0&Find.y=0&Find=Find";
			arr["a-buy-kmart"] = "http://www.kmart.com/shc/s/TopCategoriesDisplay?storeId=10151&catalogId=10104";
			arr["a-buy-amazon"] = "http://www.amazon.com/s/?ref=ty_mga_direct&tag=mgaentertainm-20&ie=UTF8&hidden-keywords=moxie%20girlz%20-barbie&rh=n%3A165793011%2Cp_6%3AATVPDKIKX0DER";
			arr["home-facebook"] = "http://www.facebook.com/pages/Moxie-Girlz/146635009438";
			arr["home-twitter"] = "http://www.twitter.com/TheMoxieGirlz/";
			arr["home-youtube"] = "http://youtube.com/moxiegirlz";
			arr["a-buy-toyrus-au"] = "http://www.toysrus.com.au";
			arr["a-buy-kmart-au"] = "http://www.kmart.com.au/";
			arr["a-buy-target-au"] = "http://www.target.com.au/html/homepage/home_fw.htm";
			arr["a-buy-bigw-au"] = "http://www.bigw.com.au/";
			arr["a-buy-myer-au"] = "http://www.myer.com.au/";
			arr["home-promo3-be3"] = "http://www.masterphoto.nl/moxiegirlz/gallery";
			arr["droomwens-lock"] = "http://mgae.us2.list-manage.com/subscribe?u=d4ff17dfc6e616c046646a55d&id=9a08060d41";
			arr["diorama-facebook"] = "http://www.facebook.com/album.php?aid=307004&id=146635009438";
			arr["turkey-home-facebook"] = "http://www.facebook.com/pages/Moxie-Kizlari/162847350423708";
			arr["spanish-home-facebook"] = "http://www.facebook.com/moxiegirlz.es";		
			arr["a-buy-toysrus_ca"] = "http://www.toysrus.com/search/index.jsp?kwCatId=&kw=moxie%20girlz&origkw=moxie%20girlz&f=Taxonomy/TRUS/2254197&sr=1";
			arr["a-buy-zellers_ca"] = "http://www.zellers.com";
			arr["a-buy-walmarts_ca"] = "http://www.walmart.com/search/search-ng.do?search_constraint=0&ic=48_0&search_query=moxie+girlz&Find.x=0&Find.y=0&Find=Find";
			arr["wtb_joker_tu-tu"] = "http://www.joker.com.tr";
			arr["wtb_toyz_tu-tu"] = "http://www.toyzzshop.com";
			arr["wtb_armagan_tu-tu"] = "http://www.armaganoyuncak.com";
			arr["wtb_nezih_tu-tu"] = "http://www.nezih.com.tr";
			arr["wtb_loco_tu-tu"] = "http://www.locopoco.com";
			arr["a-colorsticker-download"] = "http://itunes.apple.com/app/moxie-girlz-color-sticker/id462434964?mt=8";
			arr["a-colorsticker-freeapp"] = "http://itunes.apple.com/app/moxie-girlz-color-sticker/id462434964?mt=8";
			arr["a-buy-corte"] = "http://www.elcorteingles.es";
			arr["a-buy-toysrus-es"] = "http://www.toysrus.es";
			arr["a-buy-mondo"] = "http://www.mundotoys.es";
			arr["a-buy-landia"] = "http://www.juguetilandia.com";
			arr["a-buy-poly"] = "http://www.jugueteriapoly.com";
			arr["a-buy-centroxogo"] = "http://www.centroxogo.com";
			arr["a-buy-reunidas"] = "http://www.jugueteriasreunidas.com";
			arr["a-buy-joguines"] = "http://www.joguines.com";
			arr["a-buy-supe"] = "http://www.superjuguete.es";
			arr["a-buy-planet"] = "http://www.toyplanet.es";
			arr["a-buy-todo"] = "http://www.todojuguete.es";
			arr["a-buy-jupesa"] = "http://www.grupojupesa.es";

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

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

	$("#interstitial-no-"+language).click( function(){ 
		$("#interstitial-"+language).fadeOut("slow");
	});
}

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


function needToRegister(){
	$_("a-register").onclick();
}


function registerEvent( o_attachevent_fp ){
/* this object checks for register-btn id selector if found will call doInitRegForm which beings the registeration process*/
	if( $_("a-register") ){
		$_("a-register").onclick = function(){
			setTimeout( function() { 
				doInitRegForm( o_attachevent_fp.createobjs().lang );	
			} , 3000 );	
		}
	}

	if( $_("register-btn") ){
		$_("register-btn").onclick = function(){
			setTimeout( function() { 
				doInitRegForm( o_attachevent_fp.createobjs().lang );	
			} , 3000 );	
		}
	}
	/* country reg*/	
	if( $_("a-login-reg-btn-" + language ) ){
                $_("a-login-reg-btn-" + language ).onclick = function(){ 
			setTimeout( function() { 
				doInitRegForm( o_attachevent_fp.createobjs().lang );	
			} , 3000 );	
                 }   
        }   

}

function loginMenuEvent(){
/* this object checks for a-nav-login id selector if found will call dialogbox menu box */
	if( $_("a-nav-login" ) ){
		$_("a-nav-login").onclick = function(){
			dialogBox();
			o_main.o_construct();
		}
	}
}

function downloadEvent( o_attachevent_fp ){
/* download event gets all elements that are anchors, looks for a occurance with fdownload in the element id string
	if found will continue through the loop then will attach the force download that also calls google.
*/
	if( $_("div-fun-box") ) {
		var elemList = document.getElementsByTagName("a");		
		for( var i = 0; i < elemList.length; i++ ){
			if( elemList[i].id.indexOf( "fdownload" ) > -1 ){
			
				elemList[i].onclick = function(){
					var a_intString = this.id.split("-"); 
					var s_int =  a_intString[ a_intString.length - 1 ];
					o_attachevent_fp.createobjs().util.doDownloadWindow("?request=download&id=" + s_int );
				}				

			}
			
		}
	}
}

function galleryEvent( o_attachevent_fp ){
	if( $_("div-gallery-box") ){
	// pub/lang/prod_gallery.js (and a_allprod therein) need to be available to
	// the calling page!
	var a_prod;
	var s_category;
	
		s_category = o_attachevent_fp.createobjs().util.getUriValue(KEY_CATEGORY);
		o_anim = o_attachevent_fp.createobjs().anim;

		if (s_category === false) {
			s_category = DEF_PRODCAT;
		}

		a_prod = moxieHash.productGallery.a_allprod[s_category];
		o_gallery = new galleryObj(o_anim, 'o_gallery', a_prod, IMG_PRELDR,DEF_PUBPATH + s_langcode + '/' + DEF_INTRFCELANGPATH);
		o_gallery.doImgPreload();

	}
}

function invitecodeEvent( o_attachevent_fp ){
	/* this object here checks to see if there is a ?vite_code=( 32 length varchars ) param and arg in the uri , if so calls reg form  */
	if( o_attachevent_fp.createobjs().util.getUriValue(KEY_INVCODE).length == 32  ){
		doInitRegForm();
	}
}

function secretgameEvent( o_attachevent_fp ){
	if( $_("a-header-code") ){
		$_("a-header-code").onclick = function(){ accessGame( "moxifier" ); }
	}
	
	if( $_("a-fun-game-equestrian") ){
	        $_("a-fun-game-equestrian").onclick = function(){ accessGame("equestrian"); }
	}
	
	if( $_("a-fun-game-moxiesurf") ){
	        $_("a-fun-game-moxiesurf").onclick = function(){ accessGame("moxiesurf"); }
	}

	if( $_("a-fun-game-moxieyourself") ){
	        $_("a-fun-game-moxieyourself").onclick = function(){ accessGame("moxieyourself"); }
	}

	if( $_("a-fun-game-moxiematch") ){
	        $_("a-fun-game-moxiematch").onclick = function(){ accessGame("moxiematch"); }
	}

	if( $_("a-fun-game-moxifier") ){
	        $_("a-fun-game-moxifier").onclick = function(){ accessGame("moxifier"); }
	}
	
	if( $_("a-fun-game-moxiemixer") ){
	        $_("a-fun-game-moxiemixer").onclick = function(){ accessGame("moxiemixer"); }
	}	

	if( $_("a-home-promo-secret") ){
		$_("a-home-promo-secret").onclick = function(){ dropCookieSecretCode(); } 
	}
	
	if( $_("a-home-promo-secret_ru") ){
		$_("a-home-promo-secret_ru").onclick = function(){ dropCookieSecretCode(); } 
	}
	
	if( $_("a-home-promo-secret_tu") ){
		$_("a-home-promo-secret_tu").onclick = function(){ dropCookieSecretCode(); } 
	}

	if( $_("a-fun-game-moxiesalon") ){
		$_("a-fun-game-moxiesalon").onclick = function(){ accessGame("moxiesalon"); }
	}

	if( $_("a-fun-game-beauty") ){
		$_("a-fun-game-beauty").onclick = function(){ accessGame("beauty"); }
	}

	if( $_("a-fun-game-weathergirl") ){
		$_("a-fun-game-weathergirl").onclick = function(){ downloadGame( ); } 
	}

	/* fun page events */
	if( $_("a-fun-secret-1") ){
		$_("a-fun-secret-1").onclick = function(){ secretscreen2( o_attachevent_fp , 21 ); } 
	}

	if( $_("a-fun-secret-2") ){
		$_("a-fun-secret-2").onclick = function(){ secretscreen2( o_attachevent_fp , 20 ); } 
	}

	/* homepage promos  */ 
	if( $_("div-home-promo1-en-us") ){
		$_("div-home-promo2-en-us").onclick = function(){ secretscreen( o_attachevent_fp , 21 );  } 
	}

	if( $_("div-home-promo2-en-us") ){
		//$_("div-home-promo3-en-us").onclick = function(){ secretscreen( o_attachevent_fp , 20 ); } 
	}

	if( $_("a-home-promo2-en-us") ){
		$_("a-center-promo1").onclick = function(){ accessGame("equestrian"); } 
	}
}

function rotateHomePromos(){
		$("#a-home-promo2-en-us").cycle({
			fx: 'fade',
			speed: 'slow',
			timeout: 5000 
		});
	
}


function secretPromo( id ){
		o_main = new main("o_main");
	        o_attachevent_fp =   o_main.o_construct();
		secretscreen( o_attachevent_fp , id );
}


function choosecountryEvent( o_attachevent_fp ){
	if( $_("a-country") ){
		$_("a-country").onclick = function(){ o_attachevent_fp.createobjs().lang.doUserLangInterface(); }
		$_("a-flag").onclick = function(){ o_attachevent_fp.createobjs().lang.doUserLangInterface(); }
	}
}

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 ruWhereToBuy(){
	
	$("#ru_retail").click( function(){
	
		$("#russia_store_type").css("display" , "none");
		$("#russia_store_type_retail").fadeIn('slow');
	});
	
	$("#ru_market").click( function(){
	
		$("#russia_store_type").css("display" , "none");
		$("#russia_store_type_market").fadeIn('slow');
	});
	
}


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


function videoEvent( ){
var flashvars = {}
var params = {wmode: "transparent"}
var attributes = {wmode : "transparent"}

var stop = ( country == "en-us" )? 2 : 3;


for (var spots=1;spots<= stop;spots++){
	 if( $_("div-home-promo" + spots + "-" + country) ){
		if ( spots == "3" && country == "en-us" || country == "es-es" && spots == "3" || country == "es-es" && spots == "2" || country == "es-es" && spots == "1"){

		}else{
			swfobject.embedSWF("smarty_files/templates/flash/home_promo" + spots + "_" + country + ".swf", "div-home-promo" + spots + "-" + country, "216" , "216" , "9.0.0" , "" , flashvars, params, attributes );
		}
	 }
	
	if("#div-home-content"){
		
	swfobject.embedSWF("smarty_files/templates/flash/home_promo1_es-mx.swf", "div-home-promo1-es-mx", "216" , "216" , "9.0.0" , "" , flashvars, params, attributes );
	
	}
	
	
	
}
	 
    if( $_("div-logo") ){
		swfobject.embedSWF( "smarty_files/templates/flash/logo" + "_" + language + ".swf" , "div-logo" , "216" , "216" , "9.0.0" , "" , flashvars , params , attributes );

    }	
	 
    if( $_("div-main-logo") ){
		swfobject.embedSWF( "smarty_files/templates/flash/logo" + "_" + language + ".swf" , "div-main-logo" , "216" , "216" , "9.0.0" , "" , flashvars , params , attributes );
    }	 


    if( $_("div-volume") ){
		/* see if off exists */
		if(getCookie("volOff")){
			var flashvars={"playState":0}
		} else { 
			var flashvars={"playState":1}
		}
		swfobject.embedSWF( "smarty_files/templates/flash/volume.swf" , "div-volume" , "55" , "20" , "9.0.0" , "", flashvars , params , attributes );
    }
}

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

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

var videoplayEvent = function (){ 
        for (var i=0; i < moxieHash.video.length; i++ ){
                if( $_("a-video-" + moxieHash.video[i].element) ){
                        bindVideo( $_("a-video-" + moxieHash.video[i].element),i );
                }
        }
}

var bindVideo = function(obj,i){
        obj.onclick = function(){
                playVideo(moxieHash.video[i].path);
        }
}

function jcarousel(){
	if ( $("#mycarousel") ){
		$("#mycarousel-games,#mycarousel-fun, #mycarousel-ss").jcarousel( {
			itemLoadCallback: itemLoadCallbackFunction
		} );	
	}
}

function itemLoadCallbackFunction(carousel, state)
{
    for (var i = carousel.first; i <= carousel.last; i++) {
        // Check if the item already exists
        if (!carousel.has(i)) {
            // Add the item
            carousel.add(i, "I'm item #" + i);
        }
    }
}

function playVideo( uri ){
        var flashvars = { 
                file:uri,
                dock:'false', 
                autostart:'true'
        };
        var params = { 	
                allowscriptaccess:'always',
                allowfullscreen:'true',
                WMODE:'transparent'
                };
        var attributes = {}; 
        swfobject.embedSWF("smarty_files/templates/flash/player.swf" , "div-video-content" , "394" , "394" , "9.0.0", "", flashvars, params, attributes);
}

function linkEvents(){
	if( $_("privacy") ){
	  	$_("privacy").onclick = function(){
		
			window.open('http://www.mgae.com/privacy.asp','privacy','width=800,height=600,scrollbars=yes')
	
		}
	}
	if( $_("terms" ) ){
		$_("terms").onclick = function(){
			
			window.open('http://www.mgae.com/terms.asp','privacy','width=800,height=600,scrollbars=yes')

		}
	}
}



function secretCode(){
	
	$("#a-secretcode").click(function(){
		$("#secretcode-wrapper").css("display", "block");
	});
	
	$("#secretcode-header-close").click( function(){
		$("#secret-input").val('');
		$("#secretcode-wrapper").css("display", "none");
	});

	$("#btn-redeem").click(function(){
		var i;
		var array1 = new Array();
		array1 = moxieHash.secretCode;
		var s_code = $("#secret-input").val();

		for(x in array1){			
			if (array1[x][s_code]){
				var url = array1[x][s_code]; 
				window.location = url;
				$("#secret-input").val('');
				return;
			}
		}
		alert("You have entered a wrong secret code.  Please try again.");		
	});	
		
}

var lastObj = {
	id : null,
	image : null,
	doll : null
}

function subcategoryEvent( o_acctutil ){
		if( $_("div-subcategory-dolls") ){ 
			if(language != "ru") {
				$( ".a-subcategory,.a-subcategory-2" ).click( function(){ 
					if( this.id != lastObj.id ){
					var moxiecategory = moxieHash.productGallery.a_allprod[ this.id.substr(6) ];
						o_gallery = new galleryObj(o_anim, 'o_gallery', moxiecategory , IMG_PRELDR,DEF_PUBPATH + s_langcode + '/' + DEF_INTRFCELANGPATH);
						o_gallery.doImgPreload();
						}

						if( lastObj.id != null && $( this ).hasClass("replace") == false ){
							$( "#" + lastObj.id ).css('background-image', lastObj.image ).removeClass("replace");
							$(".a-subcategory,.a-subcategory-2").css("display","block");
							lastObj.id = this.id;
							lastObj.image = $(this).css('background-image');
							$( this ).addClass("replace");
						}
						else if( $( this ).hasClass("replace") ){
							$( this ).css('background-image', lastObj.image ).removeClass("replace");
							$(".a-subcategory,.a-subcategory-2").css("display","block");
						}
						else{
							$(".a-subcategory,.a-subcategory-2").css("display","block");
							lastObj.id = this.id;
							lastObj.image = $(this).css('background-image');
							$( this ).addClass("replace");

						}
					});
			}
			else{
				$( ".a-subcategory" ).click( function(){ 
					var chooseDoll = this.id.split("-");
					var currentDoll = chooseDoll[2]
					var moxiecategory = moxieHash.productGallery.a_allprod[ currentDoll ];
						o_gallery = new galleryObj(o_anim, 'o_gallery', moxiecategory , IMG_PRELDR,DEF_PUBPATH + s_langcode + '/' + DEF_INTRFCELANGPATH);
						o_gallery.doImgPreload();
						$_('a-sub-avery-ru').style.display='block';
						if($_('a-sub-bria-ru')){
							$_('a-sub-bria-ru').style.display='block';
						}
						$_('a-sub-lexa-ru').style.display='block';
						if($_('a-sub-sasha-ru')){
							$_('a-sub-sasha-ru').style.display='block';
						}
						$_('a-sub-sophina-ru').style.display='block';
						$_('a-sub-dolls-ru').style.display='block';
						$_(this.id).style.display='none';
				});

			}
		}
}


function wishlistEvent( o_acctutil ){
	if( $_("div-wishlist-wrapper") ){ 

			$("#wishlist-add").click( function(){
				var arrC = new Array();
				var arr =  $_("img-gallery").src.split("/");
				var newArr =  array_push( arr[ arr.length - 1 ] , arrC );
				alert( newArr );
				
			});
	}	
}


function frontgallery( ){

var flashvars = {}
var params = {wmode: "transparent"}
var attributes = {wmode : "transparent"}

	if( $_("div-flash-rotator") ){ 

		swfobject.embedSWF( "smarty_files/templates/flash/la_m2m_transition.swf" , "div-flash-rotator" , "653" , "251" , "9.0.0" , "" , flashvars , params , attributes );
	}	

}

function logoutEvent(){
	if( $_("a-logout") ){
		$("#a-logout").click( function(){
			$.post( "?request=logout" , { } , function( http ){ 
				window.location = "";	
			});
		 });
	}
}

function array_push( value , arr  ) {
		if( arr.length > 0 ){

			for( var i = 0; i <= arr.length; i++ ){
				if( arr[i] !== value ){ 
					arr[i] = value;
				}
			}
		}

		else { arr[i] = value; }

	return arr;
}


function doInitLoginForm( o_acctutil ) {
	/* this object creates a formObj for login*/
               o_loginform = new formObj('o_regform', o_acctutil.doUserLoginInterface , DEF_PUBPATH + s_langcode + '/' + DEF_INTRFCELANGPATH, '', '', '', '');
}

function doInitPasswordLookupForm() {
        o_regform = new formObj('o_regform', o_acctutil.doPasswordLookupInterface, DEF_PUBPATH + s_langcode + '/' + DEF_INTRFCELANGPATH, '', '', '', '');
}

function doInitRegForm( o_acctutil ) { 
/* this object creates a formObj for login*/
// this method gets called from acctutils if someone wants to register from login window so that o_form can be properly created

        o_regform = new formObj('o_regform', o_acctutil.doRegDOB , DEF_PUBPATH + s_langcode + '/' + DEF_INTRFCELANGPATH, DEF_PUBPATH + DEF_BADWORDPATH, DEF_TIMEPATH, DEF_PUBPATH + s_langcode + '/' + DEF_CNTRYLISTPATH, DEF_PUBPATH + s_langcode + '/' + DEF_STATELISTPATH);
}

function dialogBox(){
/* this object insert the dialog box to div-ctrldialog wich is the menu login/registeration */
	if( $_("div-ctrldialog") ){
    	 	$_("div-ctrldialog").style.display = "block";
     		$_("div-ctrldialog").innerHTML = "<div id=\"div-closebutton\"><a onclick=\"o_acctutil.doCloseCtrl();\" href=\"#\">[" + moxieHash.language.global["label-close"] + "]</a></div>";    
     		$_("div-ctrldialog").innerHTML += "<h4>" + moxieHash.language.registration["overlay-mess"] + "</h4>";
     		$_("div-ctrldialog").innerHTML += "<button id=\"login-btn\">" + moxieHash.language.homepage.login + "</button>";
     		$_("div-ctrldialog").innerHTML += "<button id=\"register-btn\">" + moxieHash.language.homepage.register + "</button>";
	}

}

function dropCookieSecretCode(){

	if( !obj.id ){
		document.cookie="secretCodeEnable=true; ;";
		dialogBox();
		o_main.o_construct();
	}
	else{
			accessGame("beauty");
	}

}


function checkSecretCookieEnable(){
		if( getCookie( "secretCodeEnable" ) && getCookie("finish") ){ 
			accessGame("beauty");
			deleteCookie( "secretCodeEnable" );
			deleteCookie( "finish" );
		}	
}


function accessGame( s_secretgame ){
	var b_loggin = ( obj.id )? true : false;	
	
		if( b_loggin ){
			if( moxieHash.secretGame[s_secretgame][2] ){
				var p_code = window.prompt( "Please enter the secret code" );    
                        	if( p_code == moxieHash.secretGame[s_secretgame][0] ){ 
					/* open the new window with uri */ 
					windowOpen( moxieHash.secretGame[s_secretgame][1] , moxieHash.secretGame[s_secretgame][3] , moxieHash.secretGame[s_secretgame][4] );
				 }
                       		else if( p_code == null ){    /* this means they cancelled the window */ }    
                        	else { /* */ accessGame( s_secretgame ); }
			}
			
			else{
				windowOpen( moxieHash.secretGame[s_secretgame][1] , moxieHash.secretGame[s_secretgame][3] , moxieHash.secretGame[s_secretgame][4] );
			}
		}
		
		else{ dialogBox(); o_main.o_construct(); }
} 

function downloadGame(){
	var b_loggin = ( obj.id )? true : false;	
		
	if( b_loggin ){
		windowOpen( "smarty_files/templates/MoxieWeatherGirl/index.php?appName=" + s_appName , 217 , 180  );
	}
	else{ dialogBox(); o_main.o_construct(); }
	
}

function secretscreen( o_attachevent_fp , id ){
	var b_loggin = ( obj.id )? true : false;	
		
	if( b_loggin ){
		var p_code = window.prompt("Please enter the secret code.");
		if( p_code.toUpperCase() == "MOXIESCREEN" ){ 
			o_attachevent_fp.createobjs().util.doDownloadWindow("?request=download&id=" + id );
		}
		else if( p_code == null ){ } 
		else { secretscreen( o_attachevent_fp ); }
 
	}
	else{ dialogBox(); o_main.o_construct(); }
}

function secretscreen2( o_attachevent_fp , id ){

	window.location = moxieHash.downloads[id].path

}
function windowOpen( s_uri , i_width , i_height ){
	window.open( s_uri  , "myWindow" , "location=0,status=0,scrollbars=0,resizable=0, width=" + i_width + " ,height=" + i_height + " " );
}


function windowOpenScroll( s_uri , i_width , i_height ){
	window.open( s_uri  , "myWindow" , "location=0,status=0,scrollbars=0,resizable=0,width=809,height=889" );
}


function $_( o_elementname_fp ){
	/* this object encapsulates get element by id*/
	return document.getElementById( o_elementname_fp );
}


var s_bio_girl = "lexa";

function doClickBioGirl(s_new_bio_girl){
	$_("div-bio-box").style.background = "url('smarty_files/templates/images/bio_box_"+ s_new_bio_girl + "_2010.png') no-repeat top left";
	s_bio_girl = s_new_bio_girl;
	$_("div-bio-text").innerHTML=moxieHash.girls[s_new_bio_girl].bio;
	return false;
}

function hiddenGame(){
	$("#hidden-game-btn-"+language).click(function(){
		
		$("#hidden-game-wrapper").fadeIn('slow');
			var params = { wmode : "transparent" , base: base+"smarty_files/templates/flash/hiddenobject/build/"};
 			var attributes = {};
			var flashvars = { };
			swfobject.embedSWF("smarty_files/templates/flash/hiddenobject/build/HiddenObject.swf", "hidden-game", "800", "680", "9.0.0","expressInstall.swf", flashvars, params, attributes);
		
	});
	
	$("#hidden-game-close").click(function(){
		$("#hidden-game-wrapper").css("display" , "none");
	});
}

function sweeps(){
	$("#enter_sweepstake-btn").click( function(){ 
		iFrameWindow();
	} );

	$("#x-close-iframe").click( function(){ closeIframe()  });

	if( data.length > 0  ){
                iFrameWindow();
        }

}

function goHome(){
	window.location = "http://www.moxiegirlz.com/?section=moxiehomepage";
}

function closeIframe(){ 
	goHome();
	$("#iframe-3D,#div-3D-iframe-wrapper, #div-x-close-wrapper").css("display","none");
}

function iFrameWindow(){
                $("#div-3D-iframe-wrapper,#iframe-3D, #div-x-close-wrapper").fadeIn("slow");
                if( data != "" ){
                        $("#iframe-3D").attr("src","sweepstakes/index.php?data=" + data );
                }
                else{
                        $("#iframe-3D").attr("src","sweepstakes/index.php");
                }
}

function spanishPromo(){

	$("#div-home-promo1-es-es").click(function(){ 
		window.location = "?section=moxieproducts";
	});
	$("#div-home-promo2-es-es").click(function(){ 
		window.location = "?section=moxiefun";
	});
	$("#div-home-promo3-es-es").click(function(){ 
		window.location = "?section=colorstickerstudio";
	});			
}



