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

/* 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["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["videos"] 	= new videosEvent( 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["flashbio"]=new flashbioEvent( );
	this.a_object_holder["bookpage"]= new bookpageEvent( );
}

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 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();
}


/* 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( $_("login-btn") ){	
		$_("login-btn").onclick = function(){ 
			 doInitLoginForm( o_attachevent_fp.createobjs().lang );
		 }
	}
}

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

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-products-box") ){
	// pub/lang/prod_gallery.js (and a_allprod therein) need to be available to
	// the calling page!
	var a_prod;
	var s_category;
	var s_season;
	
		s_category = o_attachevent_fp.createobjs().util.getUriValue(KEY_CATEGORY);
		s_season = o_attachevent_fp.createobjs().util.getUriValue(KEY_SEASON);
		o_anim = o_attachevent_fp.createobjs().anim;

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

		a_prod = bfcinkHash.productGallery.a_allprod[s_season][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( "bouncepounce" ); }
	}
	
	if( $_("a-fun-games1") ){
		$_("a-fun-games1").onclick = function(){ accessGame("bouncepounce"); }
	}
	
	if( $_("a-fun-games2") ){
		$_("a-fun-games2").onclick = function(){ accessGame("bfcinker"); }
	}

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

}

function videosEvent( o_attachevent_fp ){
	if( $_("div-header-video-fr-fr") ){
		$_("div-header-video-fr-fr").onclick = function(){ 
			document.getElementById('div-video-box').style.display='block'; 
			playVideo('http://c0206222.cdn.cloudfiles.rackspacecloud.com/bfc_20_320.f4v'); 
		}
	}	
}


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

function videoClose(){
	
	$_("a-video-close").onclick = function(){ 
	    playVideo('');
		document.getElementById('div-video-box').style.display='none'; 
	}
}

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

	 if( $_("div-home-promo1-" + language) ){
		swfobject.embedSWF("smarty_files/templates/flash/home_promo1_" + language + ".swf", "div-home-promo1-" + language, "341" , "343" , "9.0.0" , "" , flashvars, params, attributes );
	 }
	 if( $_("div-header-flash") ){
		swfobject.embedSWF("smarty_files/templates/flash/header.swf", "div-header-flash", "859" , "319" , "9.0.0" , "" , flashvars, params, attributes );
	 }
}

function flashbioEvent(){
	
	if($_("div-flash-player")){
			

		    var typedisplay = ( typeset == "blog" ) ? "Blog" : "Bio";
		    var girldisplay = (  girlset ) ? girlset : "Addision"; 	
		    var flashvars = ( typeset == "blog" ) ? {language: "en-us" , girl: "Kaitlin", type: typedisplay } : {language: "en-us" , girl: girldisplay , type: typedisplay };
    	            var params = { wmode: "transparent" };

          	        swfobject.embedSWF( "smarty_files/templates/bfcinkweb/build/BiosBlogs.swf", "div-flash-player", "800", "600", "9.0.0","",flashvars,params ); 	

			$(".flash-bio").click( function(){
					flashObj4 = document["div-flash-player"];
					var ret = flashObj4.changeBlock( this.id , typedisplay );
			 });	
	
	 }
}

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=\"#\">[" + bfcinkHash.language.registration.close + "]</a></div>";    
     		$_("div-ctrldialog").innerHTML += "<h4>" + bfcinkHash.language.registration.introduction + "</h4>";
     		$_("div-ctrldialog").innerHTML += "<button id=\"login-btn\">" + bfcinkHash.language.registration.login + "</button>";
     		$_("div-ctrldialog").innerHTML += "<button id=\"register-btn\">" + bfcinkHash.language.registration.register + "</button>";
	}

}

function accessGame( s_secretgame ){
	var b_loggin = ( obj.id )? true : false;	
	
		if( b_loggin ){
			if( bfcinkHash.secretGame[s_secretgame][2] ){
				var p_code = window.prompt( bfcinkHash.language.fun.code );    
                        	if( p_code == bfcinkHash.secretGame[s_secretgame][0] ){ 
					/* open the new window with uri */ 
					windowOpen( bfcinkHash.secretGame[s_secretgame][1] , bfcinkHash.secretGame[s_secretgame][3] , bfcinkHash.secretGame[s_secretgame][4] );

				 }
                       		else if( p_code == null ){    /* this means they cancelled the window */ }    
                        	else { /* */ accessGame( s_secretgame ); }
			}
			
			else{
				windowOpen( bfcinkHash.secretGame[s_secretgame][1] , bfcinkHash.secretGame[s_secretgame][3] , bfcinkHash.secretGame[s_secretgame][4] );
			}
		}
		
		else{ dialogBox(); o_main.o_construct(); }
} 

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

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" , "427" , "240" , "9.0.0", "", flashvars, params, attributes);
}


function bookpageEvent(){

	if( bookset ){

		if( bookset == "Aliesha" || bookset == "Noelle" ){ 

			doClickBookGirl( "twins" );
		}
		else{

			doClickBookGirl( bookset.toLowerCase() );

		}	
	 }
}


var s_book_girl = "addison";

function doClickBookGirl(s_new_book_girl){

        $_("p-books-text-" + s_book_girl ).style.display = "none";
        $_("p-books-text-" + s_new_book_girl ).style.display = "block";
        s_book_girl = s_new_book_girl;
        return false;
}


