//global section
var globalSection = "";
var cases_interval;
var execute = true;
var once = 1;

//hide More info button
function hideMore(){
	$("#moreButton").fadeOut();
	$("#moreInfo").fadeIn();
	
	var p = $("#wn").height();
	var q = $("#lyr1").height();
	
	$("#wn").css("height",525);
	
	if(p+10<q){
		$("#scrollbar").css("display","block");	
		$("#wn").css("height",500);
	}
	init_dw_Scroll();
	
}
//end hide More info button

function hideMoreE(){	
		$("#emoreButton").fadeOut();
		$("#emoreInfo").fadeIn();
		$("#scrollbar1").fadeIn();		
		init_dw_Scroll1();		
}

function hideUnavailable(section){
	if(section!='home'){
		$("#creative_concept").fadeOut();
	}
	if(section!='team'){
		$("#teammenu").fadeOut();
		$("#teamimg").fadeOut();
	}
	if(section!='work'){
		$("#workimg").fadeOut();
		$("#workmenu").fadeOut();
	}
	if(section!='cases'){
		$("#casesmenu").fadeOut();
		$("#caseimg").fadeOut();
		$("#current_page").fadeOut();
	}
	if(section!='clients'){
		$("#clientsmenu").fadeOut();
		$("#clientsimg").fadeOut();		
	}
	if(section!='process'){
		$("#processimg").fadeOut();
	}
	if(section!='cases_transamerica'){
		$("#slidecases_transamerica").fadeOut();
	}
	if(section!='cases_omwarrior'){
		$("#slidecases_omwarrior").fadeOut();
	}
	if(section!='cases_genzyme'){
		$("#slidecases_genzyme").fadeOut();
	}
	if(section!='cases_plexus'){
		$("#slidecases_plexus").fadeOut();
	}	
	if(section!='primedica'||section!='prezza :: fine dining'||section!='north cambridge catholic high school'){
		$("#static_image").fadeOut();
		$("#photo").fadeOut();
		$("#content").css("opacity",1);
		$("#content").fadeIn();
	}
}

/*meniu color*/
function showColorFont(section){
	if(section!='process'){
		$("#process").removeClass("selected");
	} else{
		$("#process").addClass("selected");
	}	
	if(section!='team'){
		$("#team").removeClass("selected");
	}
	if(section!='work'){
		$("#work").removeClass("selected");
	} else{
		$("#work").addClass("selected");
	}
	if(section!='cases'){
		$("#cases").removeClass("selected");
	} else{
		$("#cases").addClass("selected");
	}
	if(section!='clients'){
		$("#clients").removeClass("selected");
	} else {
		$("#clients").addClass("selected");
	}	
	/*color for submenu -> team menu*/
	if(section=='team_creative'){
		$("#team").addClass("selected");
		$("#team_creative").addClass("selected");
	} else {
		$("#team_creative").removeClass("selected");
	}
	if(section=='team_talent'){
		$("#team").addClass("selected");
		$("#team_talent").addClass("selected");
	} else{
		$("#team_talent").removeClass("selected");
	}
	if(section=='team_concept'){
		$("#team").addClass("selected");
		$("#team_concept").addClass("selected");
	} else{
		$("#team_concept").removeClass("selected");
	}	
	/*color for submenu -> work menu*/
	if(section=='work_branding'){
		$("#work").addClass("selected");
		$("#work_branding").addClass("selected");
	} else{
		$("#work_branding").removeClass("selected");
	}
	if(section=='work_logos'){
		$("#work").addClass("selected");
		$("#work_logos").addClass("selected");
	} else{
		$("#work_logos").removeClass("selected");
	}
	if(section=='work_electronica'){
		$("#work").addClass("selected");
		$("#work_electronica").addClass("selected");
	} else{
		$("#work_electronica").removeClass("selected");
	}
	if(section=='work_print'){
		$("#work").addClass("selected");
		$("#work_print").addClass("selected");
	} else{
		$("#work_print").removeClass("selected");
	}	
	/*color for submenu -> cases menu*/
	if(section=='cases_transamerica'){
		$("#cases").addClass("selected");
		$("#cases_transamerica").addClass("selected");
	} else{
		$("#cases_transamerica").removeClass("selected");
	}
	if(section=='cases_omwarrior'){
		$("#cases").addClass("selected");
		$("#cases_omwarrior").addClass("selected");
	} else{
		$("#cases_omwarrior").removeClass("selected");
	}
	if(section=='cases_genzyme'){
		$("#cases").addClass("selected");
		$("#cases_genzyme").addClass("selected");
	} else{
		$("#cases_genzyme").removeClass("selected");
	}
	if(section=='cases_plexus'){
		$("#cases").addClass("selected");
		$("#cases_plexus").addClass("selected");
	} else{
		$("#cases_plexus").removeClass("selected");
	}	
	/*color for submenu -> clients menu*/
	if(section=='clients_byindustry'){
		$("#clients").addClass("selected");
		$("#clients_byindustry").addClass("selected");
	} else{
		$("#clients_byindustry").removeClass("selected");
	}
	if(section=='clients_alphabetical'){
		$("#clients").addClass("selected");
		$("#clients_alphabetical").addClass("selected");
	} else{
		$("#clients_alphabetical").removeClass("selected");
	}
}
/*end menu*/

function showprocess(section){
	if(execute == true){
		execute = false;
	
		hideUnavailable('process');
		showColorFont('process');
		showInfo('process');		
		
		setArrayIndexOf();
		k = pages.indexOf(section);	
		
		
		$("#processimg").css("top",55);
		$("#processimg").css("opacity",0);
		$("#processimg").css("display","block");
		$("#mainmenu").animate({
			top:70
			}, 500, 'easeOutCubic', function() {		
		});
		$("#processimg").animate({
			top:370,
			opacity:1
		}, 800, 'easeOutCubic', function() {		
		});	
		
		$("#case_bottom_images").css("display","none");
		$("#bottom_images").css("display","none");	
		
		$("#content").css("display","none");		
		
		
		$.ajax({		
			url: 'process.php',
			success: function(data) {					
				$("#content").html(data);
				$("#content").fadeIn();
				execute = true;				
			}		
		});
	}/**/
}

function showTeam(section){
	if(execute == true){		
		execute = false;
		
		hideUnavailable('team');
		showInfo('team');	
		
		setArrayIndexOf();
		k = pages.indexOf(section);	
		
		showColorFont(section);	
		
		if(section == 'team_concept'){
			$("#teamimg").css("top",55);	
			$("#teamimg").css("opacity",0);
			$("#teamimg").css("display","block");
			$("#mainmenu").animate({top:70}, 500, 'easeOutCubic', function() {	});
			$("#teamimg").animate({
				top:420,
				opacity:1
			}, 800, 'easeOutCubic', function() {		
			});		
		
			$("#teammenu").css("top",510);
			$("#teammenu").css("opacity",0);
			$("#teammenu").css("display","block");
			$("#teammenu").animate({ top:400, opacity:1 }, 500, 'easeOutCubic', function() {});		
		}
		
		$("#case_bottom_images").css("display","none");
		$("#bottom_images").css("display","none");	
		
		$("#content").css("display","none");		
			
		$.ajax({
			type: "POST",
			url: 'team.php',
			data: "section="+section,
			success: function( data ) {			
				
				$("#content").html(data);
				$("#content").fadeIn();				
				execute = true;				
			}
		});
	}
}

function showWork(section){
	hideUnavailable("work");
	slideBack();
	showInfo('work');	
	
	setArrayIndexOf();
	k = pages.indexOf(section);		
	
	showColorFont(section);		
	
	$("#info_div").fadeOut();
	$("#bottom_images").css("left",440);
	
	//see if I'm in the submenu
	if(section == "work"){		
			$("#workimg").css("top",55);	
			$("#workimg").css("opacity",0);
			$("#workimg").css("display","block");
			$("#mainmenu").animate({top:70}, 500, 'easeOutCubic', function() {	});
			$("#workimg").animate({
				top:420,
				opacity:1
			}, 800, 'easeOutCubic', function() {		
			});		
		
			$("#workmenu").css("top",510);
			$("#workmenu").css("opacity",0);
			$("#workmenu").css("display","block");
			$("#workmenu").animate({ top:400, opacity:1 }, 500, 'easeOutCubic', function() {});		
	}
		
	$("#case_bottom_images").css("display","none");
	$("#bottom_images").css("display","none");		
	
	$("#content").css("display","none");	
		
	$.ajax({		
		url: section+'.php',		
		success: function( data ) {				
			
			$("#content").html(data);
			$("#content").fadeIn();			
		}
	});	
	
	if(section!="work")
	{			
		$.ajax({
		type: "POST",
		url: 'bottom_work_thumbs.php',			
		data: 'section='+section,
		success: function( data ) {
			$("#bottom_images").html(data);
			$("#bottom_images").fadeIn();
		}
	});
	}
}

function showCases(section){		
	hideUnavailable('cases');	
	
	setArrayIndexOf();
	k = pages.indexOf(section);
	
	showColorFont(section);		
	$("#info_div").fadeOut();
		
	clearInterval(cases_interval);
	globalSection = section;	
	cases_interval = setInterval("slideSwitch()",3000);
	
	//see if I'm in the submenu
	if(section == "cases"){
		$("#current_page").css("display","none");
		
		$("#caseimg").css("top",55);	
		$("#caseimg").css("opacity",0);
		$("#caseimg").css("display","block");
		$("#mainmenu").animate({top:70}, 500, 'easeOutCubic', function() {	});
		$("#caseimg").animate({
			top:260,
			opacity:1
		}, 800, 'easeOutCubic', function() {		
		});
		
		$("#casesmenu").css("top",510);
		$("#casesmenu").css("opacity",0);
		$("#casesmenu").css("display","block");
		$("#casesmenu").animate({ top:400, opacity:1 }, 500, 'easeOutCubic', function() {});		
		slideBack();
	}
	
	$("#case_bottom_images").css("display","none");  
	$("#bottom_images").css("display","none");
	
	$("#content").css("display","none");	
	
	$.ajax({		
		url: section+'.php',		
		success: function( data ) {			
			
			$("#content").html(data);
			$("#content").fadeIn();			
			
			if(section !="cases"){
				slideRight();
				$('#slide'+section).fadeIn();				
				$("#info_div").delay(500).fadeIn();
				
				$("#current_page").css("display","block");				
				$("#current_page").html(section.substring(section.indexOf('_')+1));					
				
			}	
		}
	});	
	$("#case_bottom_images").fadeIn();
}

function showClients(section){
	if(execute == true){		
		execute = false;
		
		hideUnavailable("clients");		
		
		setArrayIndexOf();
		k = pages.indexOf(section);
		
		showColorFont(section);
		slideBack();
		showInfo('clients');
		
		if(section == "clients"){		
				$("#clientsimg").css("top",55);	
				$("#clientsimg").css("opacity",0);
				$("#clientsimg").css("display","block");
				$("#mainmenu").animate({top:70}, 500, 'easeOutCubic', function() {	});
				$("#clientsimg").animate({
					top:385,
					opacity:1
				}, 800, 'easeOutCubic', function() {		
				});
				
				$("#clientsmenu").css("top",510);
				$("#clientsmenu").css("opacity",0);
				$("#clientsmenu").css("display","block");
				$("#clientsmenu").animate({ top:400, opacity:1 }, 500, 'easeOutCubic', function() {});				
		}	
		$("#case_bottom_images").css("display","none");
		$("#bottom_images").css("display","none");	
		
		$("#content").css("display","none");	
		
		$.ajax({
			url: section+'.php',		
			success: function( data ) {		
				
				$("#content").fadeIn();
				$("#content").html(data);			
				
				$(".incontent").animate({ width:500, opacity:1 }, 500, 'easeOutCubic', function() {});
				
				execute = true;
			}
		});
	}
}

function gotohome(section){
	if(execute == true){
		hideUnavailable("home");
		showColorFont('home');
		
		setArrayIndexOf();
		k = pages.indexOf(section);
		
		$("#case_bottom_images").css("display","none");
		$("#content").css("display","none");
		$("#bottom_images").css("display","none");
		
		$("#processimg").animate({		
				opacity:0
			}, 500, 'easeOutCubic', function() {
				$("#processimg").css("display","none");
				$("#creative_concept").fadeIn();
				$("#mainmenu").animate({		
					top:300
					}, 500, 'easeOutCubic', function() {				
				});	
		});	
	}
}

function animateintro(){
	$("#hl1").animate({
		width:1000
	}, 1000, 'easeOutCubic', function() {
		$("#ol1").animate({
		left:900, 
		}, 1500, 'easeOutCubic', function() {
			// Animation complete.						
			$("#ol1").animate({
				left:980, 
				}, 1000, 'easeOutCubic', function() {
				// Animation complete.
			});
			$("#mainbgimage").animate({
				left:219, 
				}, 1000, 'easeOutCubic', function() {
				// Animation complete.
			});
			$("#logoimage").delay(900).animate({
				left:780, 
				}, 800, 'easeOutCubic', function() {
				// Animation complete.
			});
			$("#menubgimage").delay(1200).animate({
				left:15, 
				}, 1200, 'easeOutCubic', function() {
				// Animation complete.
				$("#toptext").fadeIn();
				$("#mainmenu").fadeIn();
				$("#qrcode").fadeIn();
				$("#creative_concept").fadeIn();
				$("#arrows").fadeIn();				
			});
		});
	});
	$("#hl2").animate({
		width:1000
	}, 1000, 'easeOutCubic', function() {
	// Animation complete.
	});
}

function slideSwitch() {
	var $active = $('#slide'+globalSection+' img.active');	
	
    if ( $active.length == 0 ) $active = $('#slide'+globalSection+' img:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slide'+globalSection+' img:first');
		
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
			if($('#slide'+globalSection+' img').length==1) clearInterval(cases_interval);
        });
}

function showInfoH(){	
	$("#info_div").delay(200).fadeOut();	
	slideBack();
}

function showInfo(section){
	$("#info_div").css("display","none");	
	$("#content").css("position","relative");
	$("#content").css("background","transparent");	
	$("#content").css("width","600px");
	$("#content").css("overflow","hidden");
	$("#content").css("height","547px");
	$("#content").css("top","-2px");
	$("#content").css("z-index",0);
	$("#content").css("left",0);	
}

function show_work_desc(title){	
	
	setArrayIndexOf();
	k = pages.indexOf(title);
	
	if(title=='primedica'||title=='prezza :: fine dining'||title=='north cambridge catholic high school'){	
		$("#current_page").css("display","block");
		$("#current_page").html(title);	
		$("#moreInfo").css("display","none");	
		$("#moreButton").fadeIn();		
		$("#static_image").fadeIn();
		$("#photo").fadeIn();
		$("#info_div").delay(800).fadeIn();
		$('#emoreInfo').css("display","none");
				
		if(once == 1){
			slideRight();
			once++;
		}
		
		$.ajax({		
			type: "POST",
			dataType: "json",
			url: 'workcontent.php',
			data: "title="+title,		
			success: function( json ) {			
				$('#photo').attr('src', json.image);				
				$('#prev').html(json.prev);				
				$('#moreInfo').html(json.more);				
			}
		});
	}
	
	if(title=='primedica1'||title=='agilux'||title=='peapod fitness'||title=='peapod fitness'||title == 'agave mexican bistro'){
		$("#current_page").css("display","block");
		$("#current_page").html(title);
		$("#moreButton").fadeOut();
		$("#moreInfo").fadeOut();
		$('#emoreInfo').css("display","none");
		
		$.ajax({		
			type: "POST",
			dataType: "json",
			url: 'workcontent.php',
			data: "title="+title,		
			success: function( json ) {				
				$("#logoImage").fadeIn();
				$("#logoImages").fadeIn();
				$('#logoImages').attr('src', json.image);
				$('#prev').html(json.prev);				
			}
		});
	}
	
	if(title=='om warrior'||title=='master packaging'||title=='transamerica retirement services'||title=='tufts university'){
		$("#work_text").fadeOut();
		$("#current_page").css("display","block");
		$("#current_page").html(title);
		$("#etop").css("display","block");		
		$("#emoreButton").css("display","block");
		$('#emoreInfo').css("display","none");		
		$('#elect_bottom').fadeIn();		
		$("#scrollbar1").css("display","none");	
		
		$.ajax({		
			type: "POST",
			dataType: "json",
			url: 'workcontent.php',
			data: "title="+title,		
			success: function( json ) {			
				$('#eimg').attr('src', json.image);				
				$('#preview').html(json.prev);
				$('#emoreInfo').html(json.more);			
			}
		});
		
	}
	
	if(title=='protonex'||title=='charles schwab'||title=='the hartford'){		
		$("#current_page").css("display","block");
		$("#current_page").html(title);
		$('#emoreInfo').css("display","none");
		$("#moreButton").fadeOut();
		$("#moreInfo").fadeOut();		
		$("#static_image").fadeIn();
		$("#photo").fadeIn();
		$("#info_div").delay(800).fadeIn();		
		
		if(once == 1 || once == 2){
			slideRight();
			once = once+2;
		}
		
		
		$.ajax({		
			type: "POST",
			dataType: "json",
			url: 'workcontent.php',
			data: "title="+title,		
			success: function( json ) {			
				$('#photo').attr('src', json.image);			
				$('#prev').html(json.prev);				
			}
		});
	}
}

var k = 0;
var pages = new Array();
var current_page = pages[k];

pages = ["home","process","team_concept","team_creative","team_talent","work","work_branding","primedica","prezza :: fine dining",
		 "north cambridge catholic high school","work_logos","agave mexican bistro","peapod fitness","agilux","primedica1","work_electronica","om warrior",
		 "master packaging","transamerica retirement services","tufts university","work_print","protonex","charles schwab","the hartford",
		 "cases","cases_transamerica","cases_omwarrior","cases_genzyme","cases_plexus","clients","clients_byindustry",
		 "clients_alphabetical"]; 		 

current_page = pages[k];

function menu_change(n){	
	if(execute == true){
		k=k+n;
		if(k<0) k=0;
		if(k>pages.length-1) k = pages.length-1;
		current_page = pages[k];
		switchPages(current_page);
		
		if(n<0) {		
			preview_menu(current_page);
		}
	}
}

function switchPages(page){	
	if(page == 'home'){
		gotohome('home');
	}
	if(page == 'process'){		
		showprocess(page);		
	}
	if(page == 'team_concept' || page == 'team_creative' || page == 'team_talent'){	
		showTeam(page);		
	}
	if(page == 'work' || page == 'work_branding' || page == 'work_logos' || page == 'work_electronica' || page == 'work_print'){	
		showWork(page);		
	}
	if(page == 'cases' || page == 'cases_transamerica' || page == 'cases_omwarrior' || page == 'cases_genzyme' || page == 'cases_plexus'){		
		showCases(page);
		
	}
	if(page == 'clients' || page == 'clients_byindustry' || page == 'clients_alphabetical'){	
		showClients(page);		
	}
	if(page == 'primedica' || page == 'prezza :: fine dining' || page == 'north cambridge catholic high school' 
	|| page == 'agave mexican bistro' || page == 'peapod fitness' || page == 'agilux' || page == "primedica1" || page == "om warrior" || page == "master packaging" 
	|| page == "transamerica retirement services"|| page == "tufts university" || page == "protonex" || page == "charles schwab" 
	|| page == "the hartford"){	
		show_work_desc(page);		
	}
}

function preview_menu(page) {	
	if(page == "team_talent" || page == "work_print" || page == "cases_plexus" || page == "clients_alphabetical"){
		var submenu = page.substr(0,page.indexOf('_'));		
		$("#"+submenu+"menu").css("top",510);
		$("#"+submenu+"menu").css("opacity",0);
		$("#"+submenu+"menu").css("display","block");
		$("#"+submenu+"menu").animate({ top:400, opacity:1 }, 500, 'easeOutCubic', function() {});
	}
	
	if(page == "home"){
		$("#content").css("display","none");
	}
	
	if(page == "the hartford"){		
		showWork("work");
		showWork("work_print");
		$("#info_div").fadeOut();
	}
	if(page == "tufts university"){
		showWork("work_electronica");
		$("#info_div").fadeOut();
	}
	if(page == "primedica1"){
		showWork("work_logos");
		$("#info_div").fadeOut();
	}
	if(page == "north cambridge catholic high school"){
		showWork("work_branding");
		$("#info_div").fadeOut();
	}
}


function slideRight(){	
	$("#content").animate({
		left:400,		
	    }, 2000, 'easeOutCubic', function() {
		// Animation complete.
	});
}

function slideBack(){
	$("#content").animate({
		left:0, 	
	    }, 2000, 'easeOutCubic', function() {
		// Animation complete.
	});
	$("#content").css("z-index",99);
	once = 1;
}

function setArrayIndexOf(){
	if(!Array.indexOf){
			Array.prototype.indexOf = function(obj){
				for(var i=0; i<this.length; i++){
					if(this[i]==obj){
					return i;
					}
				}
				return -1;
			}
		}
}
