$(document).ready(function() {
    // do stuff when DOM is ready
    // bind the navigation links to update the selected nav:
    $('#tabsPanel #tabNav').find('a').bind('click', function(event){
        event.preventDefault(); //stop the link from going to href
        selectNav(this);
    });

    //hide all tabContent divs save the first one
    $('#tabsPanel .tabContent').hide();
    $('#tabsPanel .tabContent:first').show();
});

// handle nav selection - lots of nice chaining :-)
function selectNav(e) {
    // apply selected class to link
  $(e)
    .parents('ul:first') // find the first UL parent
      .find('a') // find all the A elements
        .removeClass('selected') // remove from all
      .end() // go back to all A elements
    .end() // go back to 'this' element
    .addClass('selected');

    //hide all divs
    $('#tabsPanel .tabContent').hide();
    
    // This is the links href. Like href="#tabOne"
    var linkHashId = e.hash.substr(1);
    
    $('#tabsPanel').removeClass().addClass(linkHashId);
    $('#' + linkHashId).fadeIn("slow");

    if (initTab2 == true && linkHashId == "tabTwo") {
        $("#slider2").PerfectSlider();
        initTab2 = false;
    } else if (initTab3 == true && linkHashId == "tabThree") {
        $("#slider3").TestimonialSlider();
        initTab3 = false;
    }

}

//SETTING UP Video POPUP, uses similiar function FastMailSignUp.js, reuses background overlay fill, #FastMailSignUpbackgroundPopup
//0 means disabled; 1 means enabled;
var videoupopupStatus = 0;

//loading popup with jQuery magic!  
function loadVideoPopup(displayDiv) {
    //loads popup only if it is disabled
    if (videoupopupStatus == 0) {
        $("#VideoBackgroundPopup").css({
            "opacity": "0.7"
        });
        $("#VideoBackgroundPopup").fadeIn("slow");
        $(displayDiv).fadeIn("slow");
        videoupopupStatus = 1;
    }
}

//disabling popup with jQuery magic!  
function disableVideoPopup(displayDiv) {
    //disables popup only if it is enabled
    if (videoupopupStatus == 1) {
        var flashvars = {}; flashvars.vidName = ""; var params = { wmode: 'transparent' }; var attributes = {};
        swfobject.embedSWF("/App_Themes/FASTSIGNS/swfs/video.swf", "homePageVideoContainer", "250", "233", "10.0.0", "/App_Themes/FASTSIGNS/swfs/expressInstall.swf", flashvars, params, attributes);
        $("#VideoBackgroundPopup").fadeOut("slow");
        $(displayDiv).fadeOut("slow");
        videoupopupStatus = 0;
    }
}

//centering popup
function centerVideoPopup(displayDiv) {
    //request data for centering  
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(displayDiv).height();
    var popupWidth = $(displayDiv).width();
    //centering
    $(displayDiv).css({
        "position": "fixed",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });

    //only need force for IE6

    $("#VideoBackgroundPopup").css({
        "height": windowHeight,
        "width": windowWidth,
        "left": "0"        
    });
    $("#VideoPopup").css({
        "position":"absolute"
    });
}

function setVideo(videoSource, videoDesc) {
    //LOADING POPUP
    //centering with css
        centerVideoPopup("#VideoPopup");
    //load popup
        loadVideoPopup("#VideoPopup");
        //set Video
        var flashvars = {}; flashvars.vidName = videoSource; var params = {wmode: 'transparent'}; var attributes = {};
        swfobject.embedSWF("/App_Themes/FASTSIGNS/swfs/video.swf", "homePageVideoContainer", "250", "233", "10.0.0", "/App_Themes/FASTSIGNS/swfs/expressInstall.swf", flashvars, params, attributes);
        $("#videoDescription").html(videoDesc);
}

$(document).ready(function() {
    //CLOSING Contact POPUP  
    //Click the x event!
    $("#VideoPopupClose").click(function() {
        disableVideoPopup("#VideoPopup");
    });
});

$(document).ready(function() {
    $("input").bind("keypress", function(event) {
        if (event.keyCode == "13") {
            event.preventDefault();
        }
    });
});

var initTab2 = true;
var initTab3 = true;
