﻿// JScript File
//rotating advert widget
//$(document).ready(function(){
//    $("#featured").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
//    $("#featured").hover(
//        function() {
//	        $("#featured").tabs("rotate",0,true);
//        },
//        function() {
//	        $("#featured").tabs("rotate",5000,true);
//        }
//    );
//});

//share widget
//$(document).ready(function(){
//    $('#selectBookmark').bookmark({sites:['facebook', 'twitter', 'linkedin', 'delicious', 'digg'], addEmail: true
//    });
//});

//menu functions
$(document).ready(function(){
    var t;
    
    $("#banner").click(function(){
        var path = window.location.pathname;
        if(path.indexOf('webSiteV02') != -1){
            window.location.href = '/webSiteV02/';
        }
        else{
            window.location.href = '/';
        };
    });
    
    //rotating advert widget
    $("#featured").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
    $("#featured").hover(
        function() {
	        $("#featured").tabs("rotate",0,true);
        },
        function() {
	        $("#featured").tabs("rotate",5000,true);
    });

    //share widget
    $('#selectBookmark').bookmark({sites:['facebook', 'twitter', 'linkedin', 'delicious', 'digg'], addEmail: true
    });
    
    //navigation
    resetSubMenu();
    
    $("#navMain").mouseenter(
        function(){
            clearTimeout(t);
    });    
    $("#navMain").mouseleave(
        function(){
            t = setTimeout("$('#navSub').slideUp()", 1500);
    });
    $("#navSub").mouseenter(
        function(){
            clearTimeout(t);
    });
    $("#navSub").mouseleave(
        function(){
            t = setTimeout("$('#navSub').slideUp()", 1500);
    });
    
    $("#services").mouseenter(
        function(){
            resetSubMenu();
            $('#navSub').show();
            $("#subNavContainerServices").show();
    });    
    $("#quantitative").mouseenter(
        function(){
            resetSubMenu();
            $('#navSub').show();
            $("#subNavContainerQuantitative").show();
    });    
    $("#qualitative").mouseenter(
        function(){
            resetSubMenu();
            $('#navSub').show();
            $("#subNavContainerQualitative").show();
    });    
    $("#support").mouseenter(
        function(){
            resetSubMenu();
            $('#navSub').show();
            $("#subNavContainerSupport").show();
    });    
    $("#partners").mouseenter(
        function(){
            resetSubMenu();
            $('#navSub').show();
            $("#subNavContainerPartner").show();
    });    
    $("#community").mouseenter(
        function(){
            resetSubMenu();
            $('#navSub').show();
            $("#subNavContainerCommunity").show();
    });    
    $("#about").mouseenter(
        function(){
            resetSubMenu();
            $('#navSub').show();
            $("#subNavContainerAbout").show();
    });    
    
    function resetSubMenu(){    
        $("#subNavContainerServices").hide();
        $("#subNavContainerQuantitative").hide();
        $("#subNavContainerQualitative").hide();
        $("#subNavContainerSupport").hide();
        $("#subNavContainerPartner").hide();
        $("#subNavContainerCommunity").hide();
        $("#subNavContainerAbout").hide();        
    };
    
    //initialize subNav div
    $("#subNavContainerServices").css('visibility', 'visible');
    $("#subNavContainerQuantitative").css('visibility', 'visible');
    $("#subNavContainerQualitative").css('visibility', 'visible');
    $("#subNavContainerSupport").css('visibility', 'visible');
    $("#subNavContainerPartner").css('visibility', 'visible');
    $("#subNavContainerCommunity").css('visibility', 'visible');
    $("#subNavContainerAbout").css('visibility', 'visible');
    
    //When you click on a link with class of poplight and the href starts with a # 
    $('a.poplight[href^=#]').click(function() {
        var popID = $(this).attr('rel'); //Get Popup Name
        var popURL = $(this).attr('href'); //Get Popup href to define size

        //Pull Query & Variables from href URL
        var query= popURL.split('?');
        var dim= query[1].split('&');
        var popWidth = dim[0].split('=')[1]; //Gets the first query string value

        //Fade in the Popup and add close button
        $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

        //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
        var popMargTop = ($('#' + popID).height() + 80) / 2;
        var popMargLeft = ($('#' + popID).width() + 80) / 2;

        //Apply Margin to Popup
        $('#' + popID).css({
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });

        //Fade in Background
        $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
        $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

        return false;
    });
    
    //Close Popups and Fade Layer
    $('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
        $('#fade , .popup_block').fadeOut(function() {
            $('#fade, a.close').remove();  //fade them both out
        });
        return false;
    });

});


