// 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">+/-</div>').appendTo('.accordion h3');
	//$('<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");
//    });
    
    $(".accordion h3").click(function() {
        $(this).siblings("div.more").slideToggle(500);
		$(this).parent().toggleClass("close");
    });

    $(".readMore").click(function() {
        $(this).siblings("div.more").slideToggle(1000);
		$(this).children("div.toggleSprite").toggleClass("close");
    });
	
	// 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();
    });

    $('#banner').children('script').remove();
    $('#banner').children('ul').remove();
    $('#banner').children('a').remove();
    $('#banner').children('input').remove();

    $("#banner").cycle({
        fx: 'fade',
        sync: 0,
        delay: -1000,
        cleartype: 1,
        cleartypeNoBg: true,
        speed: 500,
        timeout: 7500,
        pagerAnchorBuilder: function(idx, slide) { return '<li><a href="#">' + (idx + 1) + '</a></li>'; },
        pager: '.rotatorPager'
    });


    $("a.fancybox").fancybox({
        'autoDimensions': true,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'scrolling': 'no',
        'autoScale': true,
        'centerOnScroll': true,
        'type': 'iframe',
        'width': 550,
        'height': 140
    });



});





$(window).load(function() {

    $(".productList .productGroup").each(function(idx, value) {
        var pHeight = 0;

        $(this).children().each(function(idx, value) {
            pHeight += $(this).height() + 25;
        });

        $(this).height(pHeight);
    });

    //$(".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'

    //        });
    if ($(".productList").length > 0) {
        var startingSlide;
        $.get('/ajax.aspx?f=GETPRODUCTPAGE&filterTax=' + filterTaxRoot, 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
            });
        });
    }

});

function SetProductPage(filterTax,pageNumber) {
    $.ajax({
        url: '/ajax.aspx?f=SETPRODUCTPAGE&page=' + pageNumber + '&filterTax=' + filterTax,
        async: false
    });
}

