$(document).ready(function () {

    /**Qtabs**/
    var tabContainers = $('div.tabs > div');
    //show the first div container //
    tabContainers.eq(0).show();
    //on click
    $('div.tabs ul.tabNavigation a').click(function () {
        tabContainers.hide(); //hide containers
        tabContainers.filter(this.hash).show(); //show clicked container
        $('div.tabs ul.tabNavigation a').removeClass('selected'); //remove "selected" class from previous selection
        $(this).addClass('selected'); // add "selected" class to a element 
		//track event
		eventTracker($(location).attr('href'),'Click',this.hash);
        return false; // return false so any link destination is not followed
    }).filter(':first').click(); //else first is clicked

    /**Qtabs2**/
    var tabContainers = $('div.tabs > div');
    //show the first div container tabContainers.hide().eq(0).show();//
     tabContainers.hide().filter(':first').show();
    //on click
    $('div.tabs ul.tabNavigation2 a').click(function () {
        tabContainers.hide(); //hide containers
        tabContainers.filter(this.hash).show(); //show clicked container
        $('div.tabs ul.tabNavigation2 a').removeClass('selected'); //remove "selected" class from previous selection
        $(this).addClass('selected'); // add "selected" class to a element 
		//track event
		eventTracker($(location).attr('href'),'Click',this.hash);
        return false; // return false so any link destination is not followed
    }).filter(':first').click(); //else first is clicked

    /** Table Striping **/
    $(".defaultTable tr:nth-child(odd) td").css({
        backgroundColor: "#F2F7FC"
    });


    /** Table Column Header First Left **/
    $(".defaultTable th:nth-child(1)").css("text-align", "left");

    /** Accordions  **/
    $('div.textcontent').hide(); //Hide/close all containers
    $('div.accordion> span.textheader').eq(0).addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

    //on Click
    $('div.accordion> span.textheader').click(function () {
        if ($(this).next().is(':hidden')) { //If immediate next container is closed...
            $('div.accordion> span.textheader').removeClass('active').next().slideUp(); //Remove all .texteheader classes and slide up the immediate next container
            $(this).toggleClass('active').next().slideDown(); //Add triggering class to clicked trigger and slide down the immediate next container
        }
        return false; //Prevent the browser jump to the link anchor
    });

    // Email Subscription Popups
    var popupStatus = 0;

    //Popup function
    function loadPopup() {
        //loads popup only if it is disabled
        if (popupStatus == 0) {
            $("#popupUpdate").fadeIn("slow");
            popupStatus = 1;
        }
    }

    //disabling popup with jQuery magic!
    function disablePopup() {
        //disables popup only if it is enabled
        if (popupStatus == 1) {
            $("#popupUpdate").fadeOut("slow");
            popupStatus = 0;
        }
    }
    //centering popup
    function centerPopup() {

        //centering
        $("#popupUpdate").css({
            "position": "absolute",
            "top": 40,
            "right": -15
        });
    }
    $(document).ready(function () {
        //Loading Popup
        //Click the button event!
        $(".sendemail").click(function () {
            //centering with css
            centerPopup();
            //load popup
            loadPopup();
        });
        //Closing Popup
        //Click the x event!
        $("#popupUpdateClose").click(function () {
            disablePopup();
        });
        //Click out event!
        //Press Escape event!
        $(document).keypress(function (e) {
            if (e.keyCode == 27 && popupStatus == 1) {
                disablePopup();
            }
        });
    });


});

function eventTracker(strURL, strAction, strLabel)
{
	/*
	Function for logging events for analytics
	Logs Google Analytics & GetClicky 
	*/
	_gaq.push(['_trackEvent', strURL, strAction, strLabel]);
	clicky.log(strURL, strLabel, strAction);
	return false;
}
