var featurestate = 0;
var strMore;
var strLess;

$(document).ready(function() {
    $("#ff").hide();
    $("#accordianbar").text(strMore);
    $("#tt").click(function() {

        $("#ff").slideToggle("slow");
        $("#accordianbar").toggleClass("arrowup");
        $("#accordianbar").text($("#accordianbar").text() == strMore ? strLess : strMore);
    });
    jQuery('#mycarousel').jcarousel({
        wrap: 'circular'

    });
    jQuery('#herocarousel').jcarousel({
        wrap: 'circular'

    });

    //  product tabs onready scripts -->
    //Default Action
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $("ul.tabswhite li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content



    //check to see if a tab is called onload via da anchor in the url
    if (location.hash != "") {
        var activeTab = location.hash;
        var activeTabID = activeTab.replace("#tab", "#t");
        //alert("activetab=" + $("#ptabs").find(activeTabID).attr("name"));
        if ($("#ptabs").find(activeTabID).attr("name") != undefined) {
            updateProductHeader($("#ptabs").find(activeTabID).attr("name"));
            changeTab(activeTab);
            //scrollToId("_top");
            $('html, body').animate({ scrollTop: 0 }, 'slow');
        }
        

    } //	

    $('.tabs li').each(function(i) {
        var thisId = $(this).find("a").attr("href");
        thisId = thisId.substring(1, thisId.length) + '_top';
        $(this).attr("id", thisId);
    });
    //repeat for the black background settings
    $('.tabswhite li').each(function(i) {
        var thisId = $(this).find("a").attr("href");
        thisId = thisId.substring(1, thisId.length) + '_top';
        $(this).attr("id", thisId);
    });

    function changeTab(activeTab) {

        if ($(activeTab)) {
            $("ul.tabswhite li").removeClass("active"); //Remove any "active" class
            $("ul.tabs li").removeClass("active"); //Remove any "active" class
            $(activeTab + '_top').addClass("active"); //Add "active" class to selected tab
            $(".tab_content").hide(); //Hide all tab content

            $(activeTab).show(); //Fade in the active content
            if (activeTab == "#tab30") {
                scrollToId("_top");
            }
            // window.location = activeTab;
            scrollToId("_top");
        }
        return false;
    }


    //On Click Event
    $("ul.tabs li").click(function() {
        updateProductHeader($(this).find("a").attr("name"));
        //call above function
        changeTab($(this).find("a").attr("href"));
        return false;
    });

    //On Click Event
    $("ul.tabswhite li").click(function() {
        updateProductHeader($(this).find("a").attr("name"));
        //call above function
        changeTab($(this).find("a").attr("href"));
        return false;
    });

    $(".changetabs").click(function() {

        //call above function
        var activeTab = $(this).attr("href");
        var activeTabID = activeTab.replace("#tab", "#t");
        updateProductHeader($("#ptabs").find(activeTabID).attr("name"));
        changeTab(activeTab);
        return false;
    });



});
//=================================================================================================
//END of document onready
//=================================================================================================

//Generic JQ scroll to for anchored links
function scrollToId(id) {
    window.scrollTo(0, $("#" + id).offset().top);
}


//========================================================
// show today's date in the header part
//========================================================
function showDate(plaintext) {
    // CB Global Edge - changed this to call GetDateString for localized date string
    var time = new Date();
    strToday = GetDateString(time);


    if (plaintext == 1) {
        document.write(strToday);
    }
    else {
        document.write("<span class=date>" + strToday + "</span>");
    }

}
function GetDateString(time) {
    // CB Global Edge - added this function for international date formatting
    var intYear = time.getFullYear();
    var intMonth = time.getMonth();
    var intDate = time.getDate();
    var strToday = "%M %d, %Y"; // date formatting

    switch (intMonth) {
        case 0:
            strMonth = "January";
            break;
        case 1:
            strMonth = "February";
            break;
        case 2:
            strMonth = "March";
            break;
        case 3:
            strMonth = "April";
            break;
        case 4:
            strMonth = "May";
            break;
        case 5:
            strMonth = "June";
            break;
        case 6:
            strMonth = "July";
            break;
        case 7:
            strMonth = "August";
            break;
        case 8:
            strMonth = "September";
            break;
        case 9:
            strMonth = "October";
            break;
        case 10:
            strMonth = "November";
            break;
        case 11:
            strMonth = "December";
            break;
    }

    re = /%M/;
    strToday = strToday.replace(re, strMonth);
    re = /%d/;
    strToday = strToday.replace(re, intDate);
    re = /%Y/;
    strToday = strToday.replace(re, intYear);
    return strToday;
}
//==========================================================================
function updateProductHeader(styleChange) {
    //remove all classes for the product header

    $('#productheader').removeClass("prodhdrbgblack")
    $('#psubTitle').removeClass('prodpagescattitle');
    $('#pTitle').removeClass('prodpagetitle');
    $('#ptabs').removeClass('tabs');
    $('#productheader').removeClass("prodhdrbgwhite")
    $('#psubTitle').removeClass('prodpagescattitlewht');
    $('#pTitle').removeClass('prodpagetitlewht');
    $('#ptabs').removeClass('tabswhite');


    if (styleChange == "#000000") {
        $('#productheader').addClass('prodhdrbgblack');
        $('#psubTitle').addClass('prodpagescattitlewht');
        $('#pTitle').addClass('prodpagetitlewht');
        $('#ptabs').addClass('tabswhite');
    }
    else {
        $('#productheader').addClass('prodhdrbgwhite');
        $('#psubTitle').addClass('prodpagescattitle');
        $('#pTitle').addClass('prodpagetitle');
        $('#ptabs').addClass('tabs');
    }
}
//===============================================================================
var nw
function openAnyWindow(url, name, w, h) {
    if (!nw || nw.closed) {
        nw = window.open(url, name, 'scrollbars=yes,resizable=yes,status=no,location=no,menubar=yes,width=' + w + ',height=' + h);
        if (!nw.opener) {
            nw.opener
        }
        //nw.document.close()
    }
    else {
        nw.close()
        nw = window.open(url, name, 'scrollbars=yes,resizable=yes,status=no,location=no,menubar=yes,width=' + w + ',height=' + h);
        nw.focus()
    }
}
	
