
$(document).ready(function() {
if ($.browser.msie && $.browser.version <= 8) {
    $("#logo-wrap").css({marginTop: 0});
    // $("#mainFooter").css({bottom: 0});
} else {
    /*
    * All animations which aren't IE
    * Compatible should go here
    */
    setTimeout(function() {
		
		// Show logo
		$("#logo-wrap").animate({
			"margin-top" : "0px",
			"opacity": 1.0
		}, 4000, "easeOutExpo");
		
	}, 500);
    
}


/*
*   All Gobal, IE Compatible animations should go below
*   this comment block
*/

setTimeout(function() {
	// Hide Services
	$(".service, .service2, .service3").delay(0).animate({
		"opacity" : "0.0"
	}, 0, "easeOutCirc");
	
}, 0);


setTimeout(function() {
	// Show footer
	$("#mainFooter").delay(1300).animate({
		"bottom" : "-5px"
	}, 800, "easeOutCirc");
	
}, 2000);


setTimeout(function() {
	// Load Killswitch
	$("#killswitch").delay(900).animate({
		"top" : "2500px"
	}, 800, "easeOutCirc");
	
}, 2000);

//Veritcal alignment

verticalAlignHome();

$(window).resize(function() {
    verticalAlignHome()
});

function verticalAlignHome() {
    $("#home .wrap .section .content").css({marginTop: ($(window).height() - $("#home .wrap .section .content").height()) /5});
    if (parseInt( $("#home .wrap .section .content").css("margin-top") ) <= 3) $("#home .wrap .section .content").css({marginTop: 3}); 
}


//Disable dragging images
$("img").mousedown(function(){return false;});
});



var google = google || {};
    google.mfj = google.mfj || {};
    
google.mfj.HomePage = function() {
    this.self = this;
    
    if ($.browser.msie && $.browser.version <= 8) {
        $(".content", ".section").css({
            top: 0
        });
        
        return;
    }
    
    this.sections = {
        "left":   $("#left"),
        "center": $("#center"),
        "right":  $("#right")
    };
    
    this.expanded = null;
    this.initialise();
    this.configureListeners();
}

google.mfj.HomePage.WIDTH_DEFAULT = 320;
google.mfj.HomePage.WIDTH_EXPANDED = 360;//420;
google.mfj.HomePage.WIDTH_CONTRACTED = 300;//270;

google.mfj.HomePage.prototype.initialise = function() {
    
    var delay;
    var section;
    var sections = $(".content", ".section");
    
    for(var i = 0; i < sections.length; ++i) {
        
        delay = 1000 + (i * 350);
        section = $(sections[i]);

      
       section.delay(delay).animate({
            "opacity": 1.0,
            "top": "-95"
        }, 500, "easeOutBack");
        
        $(".circle", section).delay(delay + 250).animate({
            "opacity": 1.0
        }, 400);
		
$(".hide1, .hide2, .hide3", section).animate({"opacity": 0.0}, 0);
$(".hide1, .hide2, .hide3", section).delay(delay + 550).animate({"opacity": 1.0}, 400);
        
        //section.bind("mouseleave", this.delegate(this, this.onSectionOut));
    }
    
    $(window).bind("mouseout", this.delegate(this, this.onMouseOut));

}


google.mfj.HomePage.prototype.configureListeners = function() {
    var section;
    for(var id in this.sections) {
    	section = this.sections[id];
        section.bind( "mouseover", this.delegate(this, this.onSectionOver) );
    }
}

google.mfj.HomePage.prototype.reset = function() {
     $(".count").removeClass("selected");
    
    if( this.expanded == null ) {
        return;
    }
    
    var section;
    
    var time = 380;
    var ease = "easeInOutQuad";
    
    for(var id in this.sections) {
        
        section = this.sections[id];
        section.stop().animate({width: google.mfj.HomePage.WIDTH_DEFAULT}, time, ease);
        $("h1", section).stop().animate({color:"#93abb9"}, time);
        $("a", section).stop().animate({color:"#93abb9"}, time);
        $("p", section).stop().animate({color:"#93abb9"}, time);
        $(".big, .big2, .big3", section).stop().animate({opacity:1.0}, time * 0.5);
        $(".off, .off2, .off3", section).stop().animate({opacity:0.0}, time * 0.5);
        $(".service, .service2, .service3", section).stop().animate({opacity:0.0, top:-120}, time * 1.5);
		$(".hide1, .hide2, .hide3", section).stop().animate({opacity:1.0}, time * 1.0);
        section.removeClass("expanded");
    }
    
    this.expanded = null;
}

google.mfj.HomePage.prototype.expand = function( target ) {
    
    var time = 380;
    var ease = "easeInOutQuad";
    
    target.stop().animate({width: google.mfj.HomePage.WIDTH_EXPANDED}, time, ease);
    $("h1", target).stop().animate({color:"#014569"}, time);
    $("a", target).stop().animate({color:"#014569"}, time);
    $("p", target).stop().animate({color:"#666666"}, time);
    $(".big, .big2, .big3", target).stop().animate({opacity:1.0}, time * 0.25);
    $(".off, .off2, .off3", target).stop().animate({opacity:0.0}, time * .25);
    $(".service, .service2, .service3", target).stop().animate({opacity:1.0, top:-220}, time * 1.);
	$(".hide1, .hide2, .hide3", target).stop().animate({opacity:0.0}, time * 0.75);
    target.addClass("expanded");
    this.expanded = target;
    
}

google.mfj.HomePage.prototype.contract = function( target ) {
    
    var time = 380;
    var ease = "easeInOutQuad";
    
    target.stop().animate({width: google.mfj.HomePage.WIDTH_CONTRACTED}, time, ease);
    $("h1", target).stop().animate({color:"#8d9da6"}, time);
    $("a", target).stop().animate({color:"#999999"}, time);
    $("p", target).stop().animate({color:"#999999"}, time);
    $(".big, .big2, .big3", target).stop().animate({opacity:0.0}, time);
    $(".off, .off2, .off3", target).stop().animate({opacity:1.0}, time);
    $(".service, .service2, .service3", target).stop().animate({opacity:0.0, top:-120}, time);
    $(".hide1, .hide2, .hide3", target).stop().animate({opacity:1.0}, time);
    $(".count", target).removeClass("selected");
    target.removeClass("expanded");
}

google.mfj.HomePage.prototype.onSectionOver = function( event ) {
    
    var targetID = $(event.currentTarget).attr("id");
       
    if( this.expanded !== this.sections[targetID] ) {
      
        var section;
        
        for(var sectionID in this.sections) {
            
            section = this.sections[ sectionID ];
            
            if( sectionID === targetID ) {
                this.expand( section );
                $(window).bind( "mousemove", this.delegate(this, this.onMouseMove) );
            } else {
                this.contract( section );
            }
        }
    }
}






google.mfj.HomePage.prototype.onMouseMove = function( event ) {

    var minX = this.sections["left"].offset().left;
    var maxX = this.sections["right"].offset().left + this.sections["right"].width();
    
    if( event.pageX < minX || event.pageX > maxX ) {
        $(window).unbind( "mousemove" );
        this.reset();
    }
}

google.mfj.HomePage.prototype.onMouseOut = function( event ) {
    var win = $(window);
    var mx = event.clientX;
    var my = event.clientY;
    if( mx < 2500 || mx > win.width() || my < 2500 || my > win.height() ) {
        this.reset();
    }
}




google.mfj.HomePage.prototype.onSectionOut = function( event ) {
    this.reset();
}




google.mfj.HomePage.prototype.delegate = function(scope, method) {
    var fn = function() {
        var target = arguments.callee.target;
        var func = arguments.callee.func;
        return func.apply(target, arguments);
    }
    fn.target = scope;
    fn.func = method;
    return fn;
}


$(document).ready(function() {
    new google.mfj.HomePage();
});


