﻿var section = "home";
var selected = 0;
var oldhdr = "#header-" + section;
var newhdr = "#header-" + section;
var subnav = "";
var oldsubnav = "";
var container = "#" + section + "-container";
var page = "";
var bgImg = "";
var initFlash = 0;

$(document).ready(function () {
    $('#accordion').accordion({
        active: false,
        collapsible: true,
        autoHeight: false

    }).bind("accordionchange", function (event, ui) {

        selected = $("#accordion").accordion("option", "active");
        //alert(selected);
        switch (selected) {
            case 0:
                section = 'meet';
                break;
            case 1:
                section = 'what';
                break;
            case 2:
                section = 'see';
                break;
            case 3:
                section = 'connect';
                break;
            default:
                section = 'home';
                break;
        }
        
        if(initFlash==0)
        {
            $("#flash1").fadeOut(0);
            $("#flash2").addClass("display-none").fadeIn(0);
        }

        newhdr = "#header-" + section;
        subnav = "#subnav-" + section;
        
        //fade out/in headers
        $(oldhdr).fadeOut(100);
        $(newhdr).fadeIn(1000);

        //fade in/out section subnav
        $(subnav).fadeIn(500);
        $(oldsubnav).fadeOut(800);

        oldhdr = newhdr;
        oldsubnav = subnav;

        //reset all sections to their default page
        $("div[id*=page-]").css("display", "none");
        $("div[id*=page-1]").css("display", "block");
        $("ul[id*=subnav] li a").removeClass().addClass("unselected");
       
        //select the first li a in each subnav
        //$("ul[id*=subnav] li:nth-child(1) a").addClass("selected");

        //        $("div[id*=-page-]").removeClass().addClass("display-none");
        //        $("div[id*=-page-1]").removeClass().addClass("display-block");


        // align the page background div to the selected page
        if (section != "home") {
            container = "#" + section + "-container";
            $("#page-bg").fadeOut(0);
            $("#page-bg").css("top", $(container).offset().top).css("height", $(container).height())
            
             setTimeout(function () {
               $("#page-bg").addClass("display-block").fadeIn(500);
            }, 50);
            
        } else {
            
            //reset the default bg images
            $("#meet-container").css("background-image", "url(images/meetthepeople.jpg)");
            $("#what-container").css("background-image", "url(images/whatwedo.jpg)");
            $("#see-container").css("background-image", "none");
                          
            //fade out the page bg
            $("#page-bg").fadeOut(150);
            
           
           
          
        }

    });

    //video reel lightbox
//    $("#aReel").fancybox({
//        'padding': 0,
//        'margin': 0,
//        'width': 750,
//        'height': 420,
//        'titleShow': false,
//        'autoScale': false,
//        'transitionIn': 'elastic',
//        'transitionOut': 'fade',
//        'showCloseButton': true,
//        'overlayOpacity': 1,
//        'overlayColor': '#000'
    //    });

    $("#aReel").click(function () {
        $.fancybox({
            'padding': 0,
            'autoScale': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'title': this.title,
            'width': 680,
            'height': 495,
            'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type': 'swf',
            'swf': {
                'wmode': 'transparent',
                'allowfullscreen': 'true'
            }
        });

        return false;
    });


    $("#aVideo").fancybox({
        'padding': 0,
        'scrolling': 'no',
        'autoScale': true,
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'title': this.title,
        'swf': { wmode: 'transparent' },
        'titleShow': false
    });


    $("#castrol").click(function() {
		$.fancybox([
			'images/gallery/castrol/castrol1.jpg',
			'images/gallery/castrol/castrol2.jpg',
			'images/gallery/castrol/castrol3.jpg',
			'images/gallery/castrol/castrol4.jpg',
			'images/gallery/castrol/castrol5.jpg',
			'images/gallery/castrol/castrol6.jpg'
		], {
			'padding'			: 0,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'type'              : 'image',
			'changeFade'        : 'fast',
			'overlayOpacity': 1,
            'overlayColor': '#000',
            'showNavArrows': true
		});
		
	});
	
	$("#dial").click(function() {
		$.fancybox([
			'images/gallery/dial/dial1.jpg',
			'images/gallery/dial/dial2.jpg',
			'images/gallery/dial/dial3.jpg',
			'images/gallery/dial/dial4.jpg',
			'images/gallery/dial/dial5.jpg',
			'images/gallery/dial/dial6.jpg'
		], {
			'padding'			: 0,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'type'              : 'image',
			'changeFade'        : 'fast',
			'overlayOpacity': 1,
            'overlayColor': '#000',
            'showNavArrows': true
		});
	});
	
	$("#nuk").click(function() {
		$.fancybox([
			'images/gallery/nuk/nuk1.jpg',
			'images/gallery/nuk/nuk2.jpg',
			'images/gallery/nuk/nuk3.jpg',
			'images/gallery/nuk/nuk4.jpg',
			'images/gallery/nuk/nuk5.jpg',
			'images/gallery/nuk/nuk6.jpg'
		], {
			'padding'			: 0,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'type'              : 'image',
			'changeFade'        : 'fast',
			'overlayOpacity': 1,
            'overlayColor': '#000',
            'showNavArrows': true
		});
	});
	
	
	$("#pfizer").click(function() {
		$.fancybox([
			'images/gallery/pfizer/pfizer1.jpg',
			'images/gallery/pfizer/pfizer2.jpg',
			'images/gallery/pfizer/pfizer3.jpg',
			'images/gallery/pfizer/pfizer4.jpg',
			'images/gallery/pfizer/pfizer5.jpg',
			'images/gallery/pfizer/pfizer6.jpg'
		], {
			'padding'			: 0,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'type'              : 'image',
			'changeFade'        : 'fast',
			'overlayOpacity': 1,
            'overlayColor': '#000',
            'showNavArrows': true
		});
	});
	


    //privacy lightbox
    $("#privacy").fancybox({
        'margin': 0,
        'padding': 0,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic'
    });
    
    

$('.subnav a').click(function () {
    //disable the accoridon expand/collapse
    $('#accordion').accordion('disable');

    container = "#" + section + "-container";

    for (p = 1; p <= 4; p++) {
        $("#" + section + "-page-" + p).addClass("display-none").fadeOut(0);
    }

    page = "#" + this.name;
    $(page).addClass("display-block").fadeIn(500);

    $("#subnav-" + section + " li  a").removeClass().addClass("unselected");
    $(this).removeClass().addClass("selected");

    if(section=="meet"){
    bgImg = "url(images/meetthepeople.jpg)";
        switch(this.name)
        {
            case "meet-page-2":
                bgImg = "url(images/legacy.jpg)";
                break;
            case "meet-page-3":
                bgImg = "url(images/principals.jpg)";
                break;
            case "meet-page-4":
                bgImg = "url(images/culture.jpg)";
                break;
            default:
                bgImg = "url(images/meetthepeople.jpg)";
                break;    
        }
       
        $("#meet-container").css("background-image", bgImg).fadeIn(800);
        
    }
    
    if(section=="see")
    {
    bgImg = "url(images/seeourwork.jpg)";
        switch(this.name)
        {
            case "see-page-2":
                bgImg = "url(images/seeourwork.jpg)";
                break;
            default:
                bgImg = "none";
                break;    
        }
       
        $("#see-container").css("background-image", bgImg).fadeIn(800);
        
    }
    
    //re-align the page background div to the selected page 
    $("#page-bg").css("top", $(container).offset().top).css("height", $(container).height()).addClass("display-block").fadeIn(200);

    // re-enable the accordion expand/collapse
    setTimeout(function () {
        $('#accordion').accordion('enable');
    }, 150);
});

$('#aHomeMore').click(function () {
    $("#accordion").accordion('activate', 1); 
    });
    
//fade in main page
$("#body").addClass("display-block").fadeIn(1000);

//fade in the home header content after the flash loads
 setTimeout(function () {
        $("#header-home-content").addClass("display-block").fadeIn(2000);
    }, 2000);


    (function ($) {

        $.fn.konami = function (callback, code) {
            if (code == undefined) code = "38,38,40,40,37,39,37,39,66,65";

            return this.each(function () {
                var kkeys = [];
                $(this).keydown(function (e) {
                    kkeys.push(e.keyCode);
                    if (kkeys.toString().indexOf(code) >= 0) {
                        $(this).unbind('keydown', arguments.callee);
                        callback(e);
                    }
                }, true);
            });
        }

    })(jQuery);

    $(document).ready(function () {
        $(window).konami(function () {
            //alert('Konami Code Activated');
            $.fancybox(
		    '<img src=images/werk.jpg>',
		    {
		        'autoDimensions': false,
		        'width': 500,
		        'height': 560,
		        'scrolling': 'no',
		        'transitionIn': 'fade',
		        'transitionOut': 'fade'
		    }
	    );

        });
    });

});

            

