//launch map lightbox from flash
function openMap() {
	//$('#content-inner').append('<a href="http://www.brandthropology.com/home/swfs/map.html" class="nyroModal" id="maplink" style="display: none;" >Map</a>');
	$('#maplink').nyroModal().click();
}

function emmaLogin(usrAry)
{
	if (usrAry.length >= 2)
	{
		var usrName = usrAry[1];
		var usrPw = usrAry[0];
		
		if ((usrName == "null") | (usrPw == "null"))
		{
			alert('Please enter both fields!');
			window.location = window.location;
		}
		else
		{
			$("#inputUsername").val(usrName);
			$("#inputPw").val(usrPw);
			$("#frmLogin").submit();
		}
	}
}

//loadComplete called from flash
function loadComplete(name) {
	slideItDown();
}

//function to repove spaces from string
function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}


//load type content from flash movie
function loadType(name) {
	
	tempTarget = '/domestic/work/type/' + name;
	var t=setTimeout("window.location = '" + tempTarget + "'",1);
	
	varNameTmp = removeSpaces(name);
	varName = varNameTmp.toLowerCase();
	
	typeURL = varName + ".php #expander >";
	
	//alert(varName);
	typeText = "/domestic/includes/work/type-text/" + varName + ".html";
	
	//load description content to content area
	$("#content-inner").fadeTo(250, .1, function() {
		$(this).load(typeText);
	}).fadeTo(500, 1);	
	
	//load client img content into expander area
	$("#expander-content").fadeTo(250, .1, function() {
		$(this).load(typeURL);
	}).fadeTo(500, 1);	
	
	$("#mygaltop").livequery(function(){ 
									  
		//load initial alt tag value to content area
		varAltText = $("#mygaltop img").eq(0).attr("alt");				
		$("#content-inner").html(varAltText);

		//strip image src to set to site root ie. ../../images/ to images/
		$("#mygaltop img").each(function(){		 
			varTempSrc = stripFileName($(this).attr("src"));
			varNewSrc = '/domestic/includes/work/images/work/' + varTempSrc;
			$(this).attr("src", varNewSrc);
		});		
		
		//strip link href to set to site root ie. ../../images/ to images/
		$("#mygaltop a").each(function(){		 
			varTempHref = stripFileName($(this).attr("href"));
			varNewHref = '/domestic/includes/work/images/work_large/' + varTempHref;
			$(this).attr("href", varNewHref);
		});
		
		//stop double event binding
		if(!this.hasEventHander) {
		   $("#mygaltop").jCarouselLite({
				btnNext: ".next",
				btnPrev: ".prev",
				easing: "easeOutQuad",
				speed: 1000,
				mouseWheel: true,
				circular: false,
				visible: 1
			});
		}
		this.hasEventHander = true;
		
		slideItDownBig();
		
		//apply lightbox to links
		$('#mygaltop a').not('.video').not('.audio').not('.flash').not('.mobile').nyroModal(); // added the mobile line CSF 8-5-10
		$('a.video').nyroModal({ minWidth: 450, minHeight: 390, bgColor: '#000000', padding: 0 });
		$('a.audio').nyroModal({ minWidth: 450, minHeight: 420, bgColor: '#000000', padding: 0 });
		$('a.flash').nyroModal({ minWidth: 310, minHeight: 260, bgColor: '#000000', padding: 0 });
		$('a.mobile').nyroModal({ minWidth: 600, minHeight: 400, bgColor: '#0000FF', padding: 0}); // added by CSF 8-5-10
    });	
	
}

/* UGLY UGLY HACK!!! */
var team = ["anne","matt","nick","wilson","hat","erika", "langdale", "cooper", "cassandra", "corey"];

function setType(type) {
	// working code if ($.inArray(team, type)) {
	if ($.inArray(team, type) > -1) { // test code	
		setInfo(type); //switch to team!
		return;
	}
	var aboutURL = type + ".php";
	$("#content-inner").fadeTo(250, .1, function() {
		$("#content-inner").load(aboutURL);
		$("#content-inner").fadeTo(500,1); 
	});
}


function stripFileName(url){
	componentList = url.split('/');
	szDocument = componentList[componentList.length-1];	
	return szDocument;
}

function stripFileName2(url){
	componentList = url.split('/');
	
	if(componentList.length >= 2)
	{
		szDocument = componentList[componentList.length-2] + '/' + componentList[componentList.length-1];
	} else
	{
		szDocument = componentList[componentList.length-1];	
	}
	
	return szDocument;
}

function stripClientName(url){
	componentList = url.split('/');
	szDocument = componentList[componentList.length-2];	
	return szDocument;
}

//load client content from flash movie
function clickClient(name) {
	
	window.location = "client/" + name;
	
	clientURL = name + ".php #expander >";
		
	//load client img content into expander area
	$("#expander-content").fadeTo(250, .1, function() {
		$(this).load(clientURL);
	}).fadeTo(500, 1);

	$("#mygaltop").livequery(function(){	

		//load descriptions
		varSrc = $("#mygaltop img").eq(0).attr("src");
		componentList = varSrc.split('/');
		szDocument = componentList[componentList.length-1];	
		documentFilename = szDocument.split('.');
		pageName = documentFilename[0];	
		$("#content-inner").load('/domestic/includes/work/text/' + pageName + '.html');
		
		//strip image src to set to site root ie. ../../images/ to images/
		$("#mygaltop img").each(function(){		 
			varTempSrc = stripFileName($(this).attr("src"));
			varNewSrc = '/domestic/includes/work/images/work/' + varTempSrc;
			$(this).attr("src", varNewSrc);
		});		
		
		//strip link href to set to site root ie. ../../images/ to images/
		$("#mygaltop a").each(function(){		 
			varTempHref = stripFileName($(this).attr("href"));
			varNewHref = '/domestic/includes/work/images/work_large/' + varTempHref;
			$(this).attr("href", varNewHref);
		});
		
		//stop double event binding
		if(!this.hasEventHander) {
		   $("#mygaltop").jCarouselLite({
				btnNext: ".next",
				btnPrev: ".prev",
				easing: "easeOutQuad",
				speed: 1000,
				mouseWheel: true,
				circular: false,
				visible: 1
			});
		}
		this.hasEventHander = true;
		
		slideItDownBig();
		
		//apply lightbox to links
		$('#mygaltop a').not('.video').not('.audio').nyroModal();
		$('a.video').nyroModal({ minWidth: 450, minHeight: 390, bgColor: '#000000', padding: 0 });
		$('a.audio').nyroModal({ minWidth: 450, minHeight: 420, bgColor: '#000000', padding: 0 });
		$('a.flash').nyroModal({ minWidth: 310, minHeight: 260, bgColor: '#000000', padding: 0 });		
		
		return false;
    });
}

//clear expander contents
function clearExpander() {
	$("#expander-content").html("<div id=\"expander\"></div");
}

//load about content - call from flash
function setInfo(name) {
	
	aboutURL = name + ".php";
	
	$("#content-inner").fadeTo(250, .1, function() {
		if (aboutURL == 'hat.php') {
			$(this).load('team.php #content-inner >');
		} else {
			$(this).load(aboutURL + ' #content-inner >');
		}
	}).fadeTo(500, 1);
}

//slide exander up to 0 height
function slideItUp(){
	//initial animate open
	$("#expander-content").animate({
			height: '0px'
	}, 350, "easeOutExpo" );
	$("#expander-container").animate({
			height: '0px'
	}, 350, "easeOutExpo" );
	$("#expander-container2").animate({
			height: '0px'
	}, 350, "easeOutExpo" );
	$("#content").animate({
			top: '380px'
	}, 300, "easeOutExpo" );	
}

//slide exander up to medium height
function slideItDown(tempTarget){
	$("#expander-content").animate({
			height: '280px'
	}, 300, "easeOutExpo", function(){slideComplete(tempTarget)} );
	$("#expander-container").animate({
			height: '280px'
	}, 300, "easeOutExpo" );		
}

//slide exander up to big height
function slideItDownBig(){
	$("#expander-container").animate({
			height: '350px'
	}, 200, "easeOutExpo" );	
	$("#expander-content").animate({
			height: '350px'
	}, 200, "easeOutExpo" );	
	$("#content").animate({
			top: '450px'
	}, 200, "easeOutExpo" );
}

function slideComplete(tempTarget){
	//set flash movie
	switch(tempTarget)
	{
		case "work":
			 $('#expander').flash({ src: '/domestic/swfs/works.swf', width: 740, height: 280, base: "/domestic/swfs/"});
			 $("#work").addClass("here");
			 $("#client").addClass("here");
		break;			
		case "by-client.php":
			$('#expander').flash({ src: '/domestic/swfs/works.swf', width: 740, height: 280, base: "/domestic/swfs/"}); 
			 $("#work").addClass("here");
			 $("#client").addClass("here");						
		break;			
		case "by-type.php":
			$('#expander').flash({ src: '/domestic/swfs/worksbytype.swf', width: 740, height: 280, base: "/domestic/swfs/"});		
			 $("#work").addClass("here");
			 $("#type").addClass("here");								
		break;							
		case "team.php":
			$('#expander').flash({ src: '/domestic/swfs/about.swf', width: 740, height: 280, base: "/domestic/swfs/"});
			$("#team").addClass("here");				  
		 	break;
		case "game.php":
			$('#expander').html('<a href="/domestic/game-loader.php" id="game-link" class="nyroModal"><img src="/domestic/images/game.jpg" alt="Brandthropology Game"/></a>');			
			$("#game").addClass("here");
			$('#game-link').nyroModal();						
		  break;					  
		case "contact.php":
		   $('#expander').addClass('brown').flash({ src: '/domestic/swfs/contact.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'transparent' });
			$("#contact").addClass("here");
		  break;
		case "login.php":
			$("#expander").flash({ src: '/domestic/swfs/client.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'transparent' });
			 $("#login").addClass("here");	
		break;

		
		default:
	}		
}

//clear all nav here classes
function clearNav() {
	$("#nav a").each(function(intIndex){		 
		$(this).removeClass("here")
	});
}						

$(document).ready(function() {

	//show emma signup form
	$('#newsletter-show').click(function(){
		$('#newsletter-form').slideDown(250);
		return false;
	});
	
	
	$("#content-inner").hide();
	$("#content-inner").fadeTo(1, 0);
	$("#content-inner").show();
	
	$("#se-list").hide();
	//$("#se-list").fadeTo(1, 0);
	$("#se-list").show();
	
	$("#about").removeClass("here");

	//use class .large to check for sub page and apply slider
	
	if ($('#expander-content.large').size() > 0) {

		// check for starting slide
		varcurrentSlide = 1;
		
		if ( $("#currentSlide") )
			divCurrentSlide = $("#currentSlide").html();
		else
			divCurrentSlide = "1";
		
		if (divCurrentSlide)
		{
			varcurrentSlide = divCurrentSlide;
			intCurrentSlide = eval(varcurrentSlide) + 1;
			//color: #9E2A2A;
			
			strCurrentSlide = "#clientslidespan-" + intCurrentSlide;
			strCurrentSlideLink = "#clientslide-" + intCurrentSlide;
			
			strNextSlideLink = "#clientslide-" + (intCurrentSlide+1);
			strPrevSlideLink = "#clientslide-" + (intCurrentSlide-1);
			//alert(strNextSlideLink);
			
			//$("#clientslidespan-" + currentSlide).html()
			
			$(strCurrentSlide).css("color","#9E2A2A");
			$(strCurrentSlide).css("font-weight","bold");
		}
		
		$("#se-list").fadeTo(500, 1);
		
		$("#work").addClass("here");
		$("#work-by").slideDown(500);
		$('#mygaltop > ul > li > a > img:hidden').load(function(){
			$(this).fadeIn(750);
		});

		//strip image src to set to site root ie. ../../images/ to images/
		$("#mygaltop img").each(function(){		 
			varTempSrc = stripFileName($(this).attr("src"));
			varTempClient = stripClientName($(this).attr("src"));
			
			if (varTempClient == 'work')
				varNewSrc = '/domestic/includes/work/images/work/' + varTempSrc;
			else
				varNewSrc = '/domestic/includes/work/images/work/' + varTempClient + '/' + varTempSrc;
			$(this).attr("src", varNewSrc);
		});
		
		//strip link href to set to site root ie. ../../images/ to images/
		$("#mygaltop a").each(function(){		 
			varTempHref = stripFileName2($(this).attr("href"));
			
			if ((varTempHref.lastIndexOf('video.php') > 0) || (varTempHref.lastIndexOf('audio.php') > 0) || (varTempHref.lastIndexOf('flash.php') > 0))
			{
				varTempRmDir = varTempHref.split('/')
				varTempHref = varTempRmDir[1];
				
				//alert(varTempHref);
			}
			
			varNewHref = '/domestic/includes/work/images/work_large/' + varTempHref;
			//alert(varTempHref);
			$(this).attr("href", varNewHref);
		});		
		
		//load descriptions
		varSrc = $("#mygaltop img").eq(0).attr("src");
		componentList = varSrc.split('/');
		szDocument = componentList[componentList.length-1];	
		documentFilename = szDocument.split('.');
		pageName = documentFilename[0];		
		//$("#content-inner").load('/domestic/includes/work/text/' + pageName + '.html');	
		
		$("#content-inner").fadeTo(500, 1);
		
	  	$("#mygaltop").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			start: varcurrentSlide,
			beforeStart: function(a) {
				
        		$("#content-inner").fadeTo(500, .01);
				
    		},
			onPrevClick: function(o, curr) {
				
				//alert(o);
				
				//$("#content-inner").fadeTo(150, 0);
				//$("#se-list").fadeTo(150,0);
				$("#mygaltop").fadeTo(1, 0, function() {
						
						
						//clearExpander();
						//slideItUp();
	
						//alert($(strNextSlideLink).attr("href"));
						//alert(strPrevSlideLink);
						if ( $(strPrevSlideLink) )
							var t=setTimeout("window.location = '" + $(strPrevSlideLink).attr("href") + "'",50);
					
					});
				
			},
			onNextClick: function(o, curr) {
				
				//alert(o);
				
				//$("#content-inner").fadeTo(150, 0);
				//$("#se-list").fadeTo(150,0);
				$("#mygaltop").fadeTo(1, 0, function() {
						
						
						//clearExpander();
						//slideItUp();
	
						//alert($(strNextSlideLink).attr("href"));
						//alert(strNextSlideLink);
						if ( $(strNextSlideLink) )
							var t=setTimeout("window.location = '" + $(strNextSlideLink).attr("href") + "'",50);
					
					});
				
			},
			afterEnd: function(a) {
				
				if (a.length)
				{
					if (a[0].getElementsByTagName("img"))
					{
						curImg = a[0].getElementsByTagName("img")[0];
						curImgCompList = curImg.src.split('/');
						curImgFile = curImgCompList[curImgCompList.length-1];
						curImgFileName = curImgFile.split('.');
						curImgName = curImgFileName[0];
						
						$("#content-inner").fadeTo(10, .01, function() {
							$("#content-inner").load('/domestic/includes/work/text/' + curImgName + '.html');
						}).fadeTo(500, 1);
						
						window.location = "#" + curImgName;
					}
				}
				
			},
			easing: "easeOutQuad",
			speed: 1000,
			mouseWheel: true,
			circular: false,
			visible: 1
		});
		
		//$(".next").src = "/domestic/about";
		
		slideItDownBig();
		//apply lightbox to links	
		$('#mygaltop a').not('.video').not('.audio').nyroModal();
		$('a.video').nyroModal({ minWidth: 450, minHeight: 390, bgColor: '#000000', padding: 0 });
		$('a.audio').nyroModal({ minWidth: 450, minHeight: 420, bgColor: '#000000', padding: 0 });
		$('a.flash').nyroModal({ minWidth: 310, minHeight: 260, bgColor: '#000000', padding: 0 });
		
		
	} else {
		//$('#expander').flash({ src: '/domestic/swfs/intro2.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'window' });
		
		//hide sub work-by navigation
		$("#work-by").hide();
		slideItDown();
	}

	//fadeIn images with 'first' class
	$('#mygaltop > ul > li > a > img:hidden').livequery('load', function(event) {
		$(this).fadeIn(750);
	});
	
  	//handle youtube video links with jquery.nyroModal
	$.fn.nyroModal.settings.processHandler = function(settings) {
		var from = settings.from;
		if (from && from.href && from.href.indexOf('http://www.youtube.com/watch?v=') == 0) {
			$.nyroModalSettings({
				type: 'swf',
				height: 355,
				width: 425,
				url: from.href.replace(new RegExp("watch\\?v=", "i"), 'v/')
			});
		}
	};
	
	//ajax setup	
	$.ajaxSetup({
	  url: "/xmlhttp/",
	  global: false,
	  type: "POST"
	});
	
	//load home page movie and slide container
	//var urlCheck = window.location.href;
	var urlCheck = window.location.href;
	componentList = urlCheck.split('/');
	szDocument = componentList[componentList.length-1];
	documentFilename = szDocument.split('.');
	pageName = documentFilename[0];
	dirName = componentList[componentList.length-1];
	
	tempParentDir = componentList[componentList.length-3];
	if(tempParentDir == "type")
	{
		$("#work-by").slideDown(500);
		$("#work").addClass("here");
		$("#type").addClass("here");
	}
	
	// if directory/ ending '/' 
	if (dirName.length == 0)
		dirName = componentList[componentList.length-2];
	
	if (!dirName.length)
	{
		switch(pageName){	
			case "":
				 $('#expander').flash({ src: '/domestic/swfs/intro2.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'window' });
				 $("#about").addClass("here");
			break;			
			case "index":
				 $('#expander').flash({ src: '/domestic/swfs/intro2.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'window' });
				 $("#about").addClass("here");
			break;			
			case "work":
				$('#expander').flash({ src: '/domestic/swfs/works.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'window' });
				$("#work-by").slideDown(500);
				$("#work").addClass("here");
				$("#client").addClass("here");
			break;
			case "by-client":
				$('#expander').flash({ src: '/domestic/swfs/works.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'window' });
				$("#work-by").slideDown(500);
				$("#work").addClass("here");
				$("#client").addClass("here");			
			break;
			case "type":
			case "by-type":
				$('#expander').flash({ src: '/domestic/swfs/worksbytype.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'window' });
				$("#work-by").slideDown(500);
				 $("#work").addClass("here");
				 $("#type").addClass("here");			
			break;
			case "about":
			  $('#expander').flash({ src: '/domestic/swfs/about.swf', width: 740, height: 280, base: "/domestic/swfs/" });
				$("#team").addClass("here");		  
			break;
			case "contact":
			   $('#expander').addClass('brown').flash({ src: '/domestic/swfs/contact.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'transparent' });
			   $("#contact").addClass("here");
			 break;
			case "login":
				$("#expander").flash({ src: '/domestic/swfs/client.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'transparent' });
				$("#login").addClass("here");			
			break;
			case "game":
				$("#game").addClass("here");
			break;	
			case "news":
				$("#news").addClass("here");
			break;
			case "careers":
				$("#careers").addClass("here");
			break;
		}
	}
	else
	{
		//alert(dirName);
		switch(dirName){	
				
			case "team":
			case "team.php":
				$('#expander').flash({ src: '/domestic/swfs/about.swf', width: 740, height: 280, base: "/domestic/swfs/" });
				$("#team").addClass("here");		  
				break;
				
			case "work":
				$("#content-inner").fadeTo(500, 1);
				switch (pageName)
				{
					case "":
						$('#expander').flash({ src: '/domestic/swfs/works.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'window' });
						$("#work-by").slideDown(500);
						$("#work").addClass("here");
						$("#client").addClass("here");
						//$("#se-list").remove();
						$("#se-list2").remove();
						break;
						
				}
				break;
			
			case "type":
			case "by-type":
				$("#content-inner").fadeTo(500, 1);
				$('#expander').flash({ src: '/domestic/swfs/worksbytype.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'window' });
				$("#work-by").slideDown(500);
				$("#work").addClass("here");
				$("#type").addClass("here");	
			
				break;
				
			case "contact":
				$("#content-inner").fadeTo(500, 1);
			   $('#expander').addClass('brown').flash({ src: '/domestic/swfs/contact.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'transparent' });
			   $("#contact").addClass("here");
			 	break;
			 
			case "login":
				$("#content-inner").fadeTo(500, 1);	
				$("#expander").flash({ src: '/domestic/swfs/client.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'transparent' });
				$("#login").addClass("here");			
				break;
			
			case "game":
				$("#content-inner").fadeTo(500, 1);
				$('#expander').html('<a href="/domestic/game-loader.php" id="game-link" class="nyroModal"><img src="/domestic/images/game.jpg" alt="Brandthropology Game"/></a>');			
				$("#game").addClass("here");
				$('#game-link').nyroModal();		
				break;
				
				case "news":
				$("#content-inner").fadeTo(500, 1);
				$('#expander').html('<a href="/domestic/game-loader.php" id="game-link" class="nyroModal"><img src="/domestic/images/game.jpg" alt="Brandthropology Game"/></a>');			
				$("#news").addClass("here");	
				break;
				
			case "domestic":
				$("#content-inner").fadeTo(500, 1);
				$("#about").addClass("here")
				$('#expander').flash({ src: '/domestic/swfs/intro2.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'window' });
				break;
				
			case "careers":
				$("#content-inner").fadeTo(500, 1);
			   $('#expander').addClass('brown').flash({ src: '/domestic/swfs/contact.swf', width: 740, height: 280, base: "/domestic/swfs/", wmode: 'transparent' });
			   $("#careers").addClass("here");
			 	break;
				
			default:
				break;
		}
	}
	
	$('a.nyroModal').livequery('mouseover', function(event){
		$(this).nyroModal();
	});
	
	// ajax link load and animation
	 $('.ajaxlink').livequery('click', function(event){
		tempTarget = $(this).attr('href');
		
		//call analytics pageTrack
		//pageTracker._trackPageview(tempTarget);		

			clearExpander();
			slideItUp();
			
			//slideItDown(tempTarget);
	
			$("#content-inner").fadeTo(250, 0, function () 
			{		
				switch(tempTarget)
				{
					case "about":
						var t=setTimeout("window.location = '" + tempTarget + "'",600);
						break;
					default:
						var t=setTimeout("window.location = '" + tempTarget + "'",600);
						break;
				}
				
			});
			
			$("#se-list").fadeTo(250,0);
			
			$("#content-inner").fadeTo(250, 0, function() {
				//$(this).load(tempTarget + ' #content-inner >');
				
				//remove navigation styles
				clearNav();
				
			});	
	
			//}).fadeTo(250, 1);	
			
			//slide work nav
		
			switch(tempTarget)
			{	
				case "work.php":
				$("#work-by").slideDown(500);
				break;		
				case "by-client.php":
				$("#work-by").slideDown(500);
				break;				
				case "by-type.php":
				$("#work-by").slideDown(500);
				break;	
				case "team.php":
				$("#work-by").slideUp(500);
				break;  
				case "contact.php":
				$("#work-by").slideUp(500);
				break; 	
				case "login.php":
				$("#work-by").slideUp(500);
				break;   
				default:$("#work-by").slideUp(500);
			}
			
		return false;
	});

});

//$('#se-list').hide();
$('#se-list2').hide();
