// JavaScript Document

$(document).ready(function() {
    $('body').addClass('hasJS');



    // Accordion Panel	
    $("div.more").each(function() {
        $(this).css("height", $(this).height() + "px");
        $(this).hide();
    });

    $(".accordion h3").css("cursor", "pointer");
    $(".readMore").css("cursor", "pointer");
    $('<div class="toggleSprite">learn more</div>').appendTo('p.readMore');
    $(".accordion h3").hover(
		function() {
		    $(this).css({ color: "#4ab6d6" }); //mouseover
		},
		function() {
		    $(this).css({ color: "#666666" }); // mouseout
		}
	);

    $("#mainContent .accordion h3").click(function() {
        $(this).siblings("div.more").slideToggle(1000);
        $(this).siblings("p.readMore").children("div.toggleSprite").toggleClass("close");
    });

    $("#sideContent2 .accordion h3").click(function() {
        $(this).siblings("div.more").slideToggle(500);
        $(this).siblings("p.readMore").children("div.toggleSprite").toggleClass("close");
    });

    $(".readMore").click(function() {
        $(this).siblings("div.more").slideToggle(1000);
        $(this).children("div.toggleSprite").toggleClass("close");
    });

    $('.imageRotate').children('script').remove();
    $('.imageRotate').children('ul').remove();
    $('.imageRotate').children('a').remove();
    $('.imageRotate').children('input').remove();

    $(".imageRotate").cycle({
        fx: 'fade',
        sync: 0,
        delay: -1000,
        cleartype: 1,
        cleartypeNoBg: true,
        speed: 2500,
        timeout: 7500
    });

    // Tab Switchers
    $(function() {
        var tabContainers = $('div.tabContainer > div');

        $('div.tabs ul.tabNavigation a').click(function() {
            tabContainers.hide().filter(this.hash).show();

            $('div.tabs ul.tabNavigation a').removeClass('selected');
            $(this).addClass('selected');

            return false;
        }).filter(':first').click();
    });

    //Fancybox
    $("a.fancybox").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true,
        'titleShow': false,
        'hideOnOverlayClick': true,
        'centerOnScroll': true,
        'autoDimensions': false,
        'autoScale': true,
        'enableEscapeButton': true,
        'type': 'ajax',
        'scrolling': 'no'
    });

    //Fancybox
    $("a.fancyboxiframe").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true,
        'titleShow': false,
        'hideOnOverlayClick': true,
        'centerOnScroll': true,
        'autoDimensions': false,
        'autoScale': true,
        'enableEscapeButton': true,
        'type': 'iframe',
        'scrolling': 'no',
        'width': 275,
        'height': 300
    });

    $(".productList .productGroup").each(function(idx, value) {
        var pHeight = 0;

        $(this).children().each(function(idx, value) {
            pHeight += $(this).height() + 60;
        });

        $(this).height(pHeight);
    });

    var startingSlide;
    $.get('/ajax.aspx?f=GETPRODUCTPAGE', function(data) {
        if (data != null) { startingSlide = parseInt(data); } else { startingSlide = 0; }
        $(".productList").cycle({
            fx: 'fade',
            sync: 0,
            delay: -1000,
            cleartype: 1,
            cleartypeNoBg: true,
            speed: 0,
            timeout: 0,
            pagerAnchorBuilder: function(idx, slide) { return '<li><a href="#">' + (idx + 1) + '</a></li>'; },
            pager: '.productPager',
            startingSlide: startingSlide
        });

        $(".productPager a").click(function() { window.scrollTo(0, 310); });

        //$(".productPager").clone(true).prependTo(".productList");
    });
});

function SetProductPage(pageNumber) {
    $.ajax({
        url: '/ajax.aspx?f=SETPRODUCTPAGE&page=' + pageNumber,
        async: false
    });
}


//Moved from dynapar.com to support Territory Manager map. Modified to improve performance but otherwise left as-is...
function doCSS(theTab, theGroup, thestyle, theaction, theopposite) {
    //Populate the array with all the page tags
    var allPageTags = $("[class*=" + theGroup + "]");
    //Cycle through the tags using a for loop

    for (i = 0; i < allPageTags.length; i++) {
        //Pick out the tags with our class name

        if (allPageTags[i].className == theGroup + theTab) {
            eval("allPageTags[i].style." + thestyle + "='" + theaction + "'");
        }
        else {
            eval("allPageTags[i].style." + thestyle + "='" + theopposite + "'");
        }
    }
    for (x = 1; x <= 4; x++) {
        if (x == parseInt(theTab)) {
            document.getElementById(theGroup + x.toString()).bgColor = '#FFFFFF';
        }
        else {
            document.getElementById(theGroup + x.toString()).bgColor = '#D9ECD9';
        }
    }

}



