//--------------------------------------
// VARS
//--------------------------------------

// CONSTANTS
var globalLocalURL = "";
var globalURL = "";
var IPHONE = ((navigator.userAgent.match(/Android/i)) || (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)));
var IPAD = ( navigator.userAgent.match(/iPad/i) );
var CONTENT_PAGES = [ "home","artistsanddesigners","clients","contact" ]; 

// OBJECTS
var buttonsObj;
var menuObj;
var motionObj;
var navControlObj;
var deepLinkObj;
var iphoneNavObj;
var currentPageObj;
var homeIntroObj;

// CONTROLS
var indice = 1;
var page = "home";
var pageCurrent = "home";
var containers = [];
var statusButton = true;
var statusNav = true;


//--------------------------------------
// PAGES
//--------------------------------------

containers[ indice ] = "home"; indice++;
containers[ indice ] = "artistsanddesigners"; indice++;
containers[ indice ] = "clients"; indice++;
containers[ indice ] = "contact"; indice++;


//--------------------------------------
// READY
//--------------------------------------

$(document).ready
(
	function()
	{
		// BUTTON
		buttonInit();
		
		// MENU
		menuInit();
	
		
		// NAV
		navInit();	
		
		
		// IPHONE
		iphoneInit();
		
		
		// HOME INTRO
		homeIntroInit();

				
		
		// ONLOAD
		$(window).load
		(
			function()
			{	
				// MOTION 
				motionInit();
				
				// DEEP LINK
				deepLinkInit();
			}
		);
	}
);




//--------------------------------------
// CLOSE
//--------------------------------------

$(window).unload
(
	function()
	{
		//analyticsCloseWindow();
	}
);

//--------------------------------------
// BUTTON
//--------------------------------------


function buttonInit()
{
	buttonsObj = new buttons();
	buttonsObj.init();
}

function overButton(id)
{
	buttonsObj.buttonOver(id);
}

function outButton(id)
{
	buttonsObj.buttonOut(id);
}


// ROLLOVER BUTTONS ------------------------------------------------------------------

function overteacosyButton()
{
	buttonsObj.buttonteacosyOver();
}

function outteacosyButton()
{
	buttonsObj.buttonteacosyOut();
}

function overcreateButton()
{
	buttonsObj.buttoncreateOver();
}

function outcreateButton()
{
	buttonsObj.buttoncreateOut();
}

function overwilliamButton()
{
	buttonsObj.buttonwilliamOver();
}

function outwilliamButton()
{
	buttonsObj.buttonwilliamOut();
}

function overrobbieButton()
{
	buttonsObj.buttonrobbieOver();
}

function outrobbieButton()
{
	buttonsObj.buttonrobbieOut();
}

function overtwitterButton()
{
	buttonsObj.buttontwitterOver();
}

function outtwitterButton()
{
	buttonsObj.buttontwitterOut();
}

function overfacebookButton()
{
	buttonsObj.buttonfacebookOver();
}

function outfacebookButton()
{
	buttonsObj.buttonfacebookOut();
}

function overvimeoButton()
{
	buttonsObj.buttonvimeoOver();
}

function outvimeoButton()
{
	buttonsObj.buttonvimeoOut();
}

function overemailButton()
{
	buttonsObj.buttonemailOver();
}

function outemailButton()
{
	buttonsObj.buttonemailOut();
}

function overmartinrnelsonButton()
{
	buttonsObj.buttonmartinrnelsonOver();
}

function outmartinrnelsonButton()
{
	buttonsObj.buttonmartinrnelsonOut();
}

// MENU ---------------------------------------------------------------------------------------------------

function menuInit()
{
	menuObj = new menu();
	menuObj.init();
}


function menuNav( id )
{
	// INFO PAGE CURRENT
	menuObj.currentMenu( id );
	
	// DeepLink INIT MORSA
	deepLinkObj.chageHash( containers.indexOf(id) );
	
	// MOTION CURRENT
	motionCurrent();
}


//--------------------------------------
// NAV
//--------------------------------------

// INIT
function navInit()
{
	navControlObj = new navControl();
	navControlObj.init();
}


//--------------------------------------
// MOTION
//--------------------------------------

// INIT
function motionInit()
{
	motionObj = new motion();
	motionObj.init();
	
	// EVENT CHANGE PAGE FOR HIGHT LIGHT
	$('body').bind( 'changePageEvent', changePageEvent ); 
	
	// FOOTER IPAD/IPOD
	$('body').bind( 'footerIpodEvent', footerIpodEvent ); 
}


function motionCurrent()
{
	//
	motionObj.motionCurrent();
}


function changePageEvent()
{
	//
	eventStepHightLight();
}


function footerIpodEvent()
{
	//
	eventIpodFooter();
}




// HOME INTRO --------------------------------------

// INIT
function homeIntroInit()
{
	if( !IPHONE && !IPAD )
	{
		// HIGHT LIGHT
		homeIntroObj = new homeIntro();
		homeIntroObj.init();
	}
}

function eventStepHightLight()
{
	if( !IPHONE && !IPAD )
	{
		homeIntroObj.stepChangePage();
	}
}


//--------------------------------------
// IPHONE NAV
//--------------------------------------

// INIT
function iphoneInit()
{
	// IPHONE
	iphoneNavObj = new iphoneNav();
	iphoneNavObj.init();
	
	// EVENT CHANGE PAGE IPHONE
	$('body').bind( 'changePageIphone', changePageIphone ); 
}

// Event
function changePageIphone( event, move )
{
	//
	var oldPageContent =  CONTENT_PAGES.indexOf( pageCurrent );
	
	//
	if( move == "right" )
	pageCurrent = CONTENT_PAGES[ oldPageContent + 1 ];
	else
	pageCurrent = CONTENT_PAGES[ oldPageContent - 1 ];
	
	
	// INFO PAGE CURRENT
	menuObj.currentMenu( pageCurrent );
	
	// DeepLink INIT MORSA
	deepLinkObj.chageHash( containers.indexOf(pageCurrent) );
	
	// MOTION CURRENT
	motionCurrent();
}

function eventIpodFooter()
{
	iphoneNavObj.footerPosition();
}

//--------------------------------------
// DEEP LINK
//--------------------------------------

// INIT
function deepLinkInit()
{
	deepLinkObj = new deepLink( containers );
	var infoPageCurrent = deepLinkObj.init();
	
	// INFO PAGE CURRENT
	menuObj.currentMenu( containers[ infoPageCurrent ] );
	motionObj.motionInit( containers[ infoPageCurrent ] );
}



