/*  
 All Jquery animations
 */


jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$.preloadImages("../box_back_roll2.gif", "../bluebox.jpg", "../images/box_back.gif", "../images/header.jpg", "../images/close.jpg", "../images/closewhite.jpg", "../images/shadow.png", "../images/bioback.jpg", "../images/whitebox.jpg");

function loadFlash(){
    /* Intro SWF OBJECT file*/
    $('#flashHeader').flash({
        swf: 'thread.swf',
        height: 171,
        width: 981,
        params: {
            wmode: "transparent"
        }
    });
}

var dimBoxAnimating = false;
var bioAnim = false;
var bioShowing = false;
var bioLink1 = false;
var bioLink2 = false;
var bioLink3 = false;
var currentBox;
var gotoEnd = true;
var clearQueue = true;
var btnBox;



function dimBoxDone() 
{
	dimBoxAnimating = false;
}

function fadeOutDimBox()
{
	dimBoxAnimating = true;
	$("#dimbox").fadeOut(1200, dimBoxDone);
}

function fadeInDimBox()
{
	dimBoxAnimating = true;
	$("#dimbox").fadeIn("slow", dimBoxDone);
}


function showCurrentBox()
{
	// set the current content box opacity to 0 before showing it
	$(currentBox).css("opacity",0);
	$(currentBox).show();
}

function hideCurrentBox() 
{
	$(currentBox).hide();
}

function down()
{
	if (dimBoxAnimating) return;
	showCurrentBox(); // show the contetn box, but opacity 0
	fadeInDimBox(); // begin fading out the bg
	
	// chain together the fade on and slide open animations
	var btnBoxOpenAnim = new Animator({duration:1000}).addSubject(new CSSStyleSubject($(currentBox), "height:440px;"));
	var btnBoxFadeAnim = new Animator({duration:500}).addSubject(new NumericalStyleSubject($(currentBox), 'opacity', 0, 1));
	btnBoxDown = new AnimatorChain([btnBoxFadeAnim, btnBoxOpenAnim]);
	btnBoxDown.play(); // play the animations
}



function up()
{
	if (dimBoxAnimating) return;
	showCurrentBox(); // show the contetn box, but opacity 0
	fadeInDimBox(); // begin fading out the bg
	
	// chain together the fade on and slide open animations
	var btnBoxOpenUpAnim = new Animator({duration:1000}).addSubject(new CSSStyleSubject($(currentBox), "height:440px; top:171px;"));
	var btnBoxFadeUpAnim = new Animator({duration:500}).addSubject(new NumericalStyleSubject($(currentBox), 'opacity', 0, 1));
	btnBoxUp = new AnimatorChain([btnBoxFadeUpAnim, btnBoxOpenUpAnim]);
	btnBoxUp.play(); // play the animations
}


function closeBlueBox(dir)
{
	if (dimBoxAnimating) return;
	
	var animCSS = "height:220px;"
	if (dir == "up") animCSS = "height:220px; top:391px;"
	
	// chain together the slide closed and fading animations
	var btnBoxOutAnim = new Animator({duration:800}).addSubject(new CSSStyleSubject($(currentBox), animCSS));
	var btnBoxFadeOutAnim = new Animator({duration:300, onComplete:hideCurrentBox}).addSubject(new NumericalStyleSubject($(currentBox), 'opacity', 1, 0));
	btnBoxOut = new AnimatorChain([btnBoxOutAnim, btnBoxFadeOutAnim]);
	btnBoxOut.play(); // play the animation chain
	
	// hide the dim box
	fadeOutDimBox();
}

function closeClick()
{
	if (currentBox == "#discretionContent" || currentBox == "#reachContent" || currentBox == "#methodsContent") closeBlueBox("up");
    if (currentBox == "#talentContent" || currentBox == "#clientsContent") closeBlueBox();
    if (currentBox == "#partnersContent") partnersContentClose();
	pageTracker._trackPageview('/');
}

function partnersContentClose()
{
	if (bioLink1 == true || bioLink2 == true || bioLink3 == true) {
		closeAllBio(0, true).closeBlueBox();
		bioShowing = false;
	}else{
		if (bioShowing == true) return{}
		closeBlueBox();
	}
}

$(document).ready(function(){

    /*DIMBOX clicking*/
    $("#dimbox").click(function(){
		if (dimBoxAnimating) return;
        closeClick();
    });   
    
    /*Intro Animation with delays*/
    
    $("#header").show("blind", {
        direction: "vertical"
    }, 1000, loadFlash);
    
    $(this).delay(1000, function(){
        $("#partners").show("blind", {
            direction: "vertical"
        }, 1000);
        
        $(this).delay(300, function(){
            $("#talent").show("blind", {
                direction: "vertical"
            }, 1000);
            
            $(this).delay(300, function(){
                $("#clients").show("blind", {
                    direction: "vertical"
                }, 1000);
                
                $(this).delay(1000, function(){
                    $("#methods").show("blind", {
                        direction: "vertical"
                    }, 1000);
                    
                    $(this).delay(300, function(){
                        $("#reach").show("blind", {
                            direction: "vertical"
                        }, 1000);
                        
                        $(this).delay(300, function(){
                            $("#discretion").show("blind", {
                                direction: "vertical"
                            }, 1000);
                            
                            $(this).delay(300, function(){
                                $("#shadow").show("blind", {
                                    direction: "vertical"
                                }, 1000);
                            });
                        });
                    });
                });
            });
        });
    });
    
    /* Hovering Effect for Box Rollovers*/
	
$('.boxIdle').show(); 

	$(".box").hover(function(e){
        $(".boxIdle", this).hoverFlow(e.type, {
			'opacity': 'hide'
		}, 300);
        
    }, function(e){
         $(".boxIdle", this).hoverFlow(e.type, {
			'opacity': 'show'
		}, 500);
		});
    
    /* Blue Box Rollouts for Box Elements*/
    
    $("#discretion").click(function(){
        currentBox = "#discretionContent";
		up();
		pageTracker._trackPageview('/discretion/');
    });
    
    $("#reach").click(function(){
        currentBox = "#reachContent";
		up();
		pageTracker._trackPageview('/reach/');
    });
    
    $("#methods").click(function(){
        currentBox = "#methodsContent";
		up();
		pageTracker._trackPageview('/methods/');
    });
    
    $("#clients").click(function(){
		if (dimBoxAnimating) return;
        currentBox = "#clientsContent";
        down();
		pageTracker._trackPageview('/clients/');
    });
    
    $("#talent").click(function(){
		if (dimBoxAnimating) return;
        currentBox = "#talentContent";
        down();
		pageTracker._trackPageview('/talent/');
        
    });
    
    $("#partners").click(function(){
		if (dimBoxAnimating) return;
        currentBox = "#partnersContent";
		down();
		pageTracker._trackPageview('/partners/');
    });
    
    
    
    /* White Box Rollouts for Bios*/
    $(".biolink1").click(function(){
		if (bioAnim == true) return;
		bioAnim = true;
        $(this).delay(bioLink2 || bioLink3 ? 1000 : 0, function(){
            $(".bioroll1").show("blind", {
                direction: "horizontal"
            }, 1000)
        });
        bioLink1 = true;
		bioShowing = true;
		bioAnim = false;
        closeAllBio(1);
		pageTracker._trackPageview('/partners/patrizia');
    });
    
    $(".biolink2").click(function(){
		if (bioAnim == true) return;
		bioAnim = true;
        $(this).delay(bioLink1 || bioLink3 ? 1000 : 0, function(){
            $(".bioroll2").show("blind", {
                direction: "horizontal"
            }, 1000)
        });
        bioLink2 = true;
        bioShowing = true;
		bioAnim = false;
        closeAllBio(2);
		pageTracker._trackPageview('/partners/sarah');
    });
    
    $(".biolink3").click(function(){
		if (bioAnim == true) return;
		bioAnim = true;
        $(this).delay(bioLink1 || bioLink2 ? 1000 : 0, function(){
            $(".bioroll3").show("blind", {
                direction: "horizontal"
            }, 1000)
        });
        bioLink3 = true;
        bioShowing = true;
		bioAnim = false;
        closeAllBio(3);
		pageTracker._trackPageview('/partners/angela');
    });
    
    /* Hover Events for Bio Links*/
    $(".biolink1").hover(function(){
        $(this).effect("highlight", {
            color: "#87d1e8"
        }, 500);
    });
    $(".biolink2").hover(function(){
        $(this).effect("highlight", {
            color: "#87d1e8"
        }, 500);
    });
    $(".biolink3").hover(function(){
        $(this).effect("highlight", {
            color: "#87d1e8"
        }, 500);
    });
    
    
    /* Close Buttons for Bio Elements*/
    $(".closewhite").click(function(){
        closeAllBio();
        bioShowing = false;	
        bioLink1 = bioLink2 = bioLink3 = false;
        currentBox = "#partnersContent";
    });
    
    /* Close Buttons for Box Elements*/
    $(".closeReverse").click(function(){
        if (dimBoxAnimating) return;
		closeClick();
    });
    $(".close").click(function(){
		if (dimBoxAnimating) return;
		closeClick();
    });
});


function closeAllBio(bioToSkip, callBack){
    if (bioToSkip != 1 && bioLink1) {
        $(".bioroll1").hide("blind", {
            direction: "horizontal"
        }, 1000, callBack ? closeBlueBox : null);
        bioLink1 = false;
		bioAnim = false;
    }
    if (bioToSkip != 2 && bioLink2) {
        $(".bioroll2").hide("blind", {
            direction: "horizontal"
        }, 1000, callBack ? closeBlueBox : null);
        bioLink2 = false;
		bioAnim = false;
    }
    if (bioToSkip != 3 && bioLink3) {
        $(".bioroll3").hide("blind", {
            direction: "horizontal"
        }, 1000, callBack ? closeBlueBox : null);
        bioLink3 = false;
		bioAnim = false;
    }
	if (bioToSkip != 1 && bioToSkip != 2 && bioToSkip != 3) {
		pageTracker._trackPageview('/partners/');
	}
}
