
Sys.Application.add_load(InitJQuery);

var $j = jQuery.noConflict();
var productID;
var onTab = '';
var changeTab = '';

function InitJQuery() {


    var productElement;


    // LeftNav Tabs
    var categoriesHeight = $j('.categories').height();
    var brandHeight = $j('.brands').height();

    if ($j('.catBrand a:last').hasClass('on')) {
        $j('.catBrand a:first').removeClass('on');
        $j('.catBrand a:last').addClass('on');
        $j('.catBrand a img').stop().animate({ opacity: 0 }, 500);
        $j('.categories').css('overflow', 'hidden');
        $j('.categories').stop().animate({ height: 0 }, 500);
		$j('.brands').css('display', 'block');
        $j('.brands').css('overflow', 'hidden');
        $j('.brands').stop().animate({ height: brandHeight }, 500, function () { $j('.brands').css('overflow', 'visible') });
    }

    $j('.catBrand a').click(function () {
        if ($j('.catBrand a:first').hasClass('on')) {
            $j('.catBrand a:first').removeClass('on');
            $j('.catBrand a:last').addClass('on');
            $j('.catBrand a img').stop().animate({ opacity: 0 }, 500);
            $j('.categories').css('overflow', 'hidden');
            $j('.categories').stop().animate({ height: 0 }, 500);
            $j('.brands').css('overflow', 'hidden');
            $j('.brands').css('display', 'block');
            $j('.brands').stop().animate({ height: brandHeight }, 500, function () { $j('.brands').css('overflow', 'visible') });
        } else {
            $j('.catBrand a:first').addClass('on');
            $j('.catBrand a:last').removeClass('on');
            $j('.catBrand a img').stop().animate({ opacity: 1 }, 500);
            $j('.categories').css('overflow', 'hidden');
            $j('.categories').stop().animate({ height: categoriesHeight }, 500, function () { $j('.categories').css('overflow', 'visible') });
            $j('.brands').css('overflow', 'hidden');
            $j('.brands').stop().animate({ height: 0 }, 500);
        }
    });


    jQuery.easing.def = "easeInCubic";

    $j('.categories > li').hover(function () {
        if (!$j('> a', this).hasClass('on')) {
            $j('> a', this).stop().animate({ color: "#e41d3c", backgroundPosition: '-196px bottom' }, { easing: 'easeOutCubic', duration: 300 }).css('textShadow', '#ffaab7 1px 1px 1px')
            $j(this).stop().animate({ backgroundPosition: '-196px top' }, { easing: 'easeOutCubic', duration: 300 })
            if ($j.browser.msie) {
			$j(this).children('.flyout')
				.css({ width: 0, left: 196 })
				.stop()
				.delay(0)
				.animate({ left: 196, width: 453, }, { easing: 'easeOutExpo', duration: 600, complete:
					function () {

					}
				});
			} else {
			$j(this).children('.flyout')
				.css({ width: 0, opacity: 0, left: 196 })
				.stop()
				.delay(0)
				.animate({ left: 196, width: 453, opacity: 1 }, { easing: 'easeOutExpo', duration: 600, complete:
					function () {

					}
				});
			}
        }
    }, function () {
        $j('> a', this).stop().animate({ color: "#ffffff", backgroundPosition: '0px bottom' }, { easing: 'easeInCubic', duration: 300 }).css('textShadow', '#AB132A 1px 1px 1px')
        $j(this).stop().animate({ backgroundPosition: '0px top' }, { easing: 'easeInCubic', duration: 300 })
		if ($j.browser.msie) {
        $j(this).children('.flyout')
			.clearQueue()
			.stop()
			.animate({ left: 260 }, { easing: 'easeInExpo', duration: 600, complete:
				function () {
				    $j(this).css({ width: 0 })
				    $j(this).parent('a').css('color', "#ffffff").css('textShadow', '#AB132A 1px 1px 1px')
				}
			});
		} else {
        $j(this).children('.flyout')
			.clearQueue()
			.stop()
			.animate({ left: 260, opacity: 0 }, { easing: 'easeInExpo', duration: 600, complete:
				function () {
				    $j(this).css({ width: 0, opacity: 0 })
				    $j(this).parent('a').css('color', "#ffffff").css('textShadow', '#AB132A 1px 1px 1px')
				}
			});
		}
    });

    //tool tip
    if ($j(".prItem, .category-item ul a").length) {
        $j(".prItem, .category-item ul a").tooltip({

            onShow: function () {
                //$j('.tooltip').load('test.htm .test2', function() {

                //});
            },

            effect: 'slide',
            relative: 'true',
            position: 'bottom center'

        }).dynamic({ bottom: { direction: 'down', bounce: true} });
    }
    // Dynamic image load for tool tip
    jQuery('a[id*="hypProduct"]').hover(function () {
        jQuery(this).next('.tooltip').find('img[id*="imgProductLarge"]').attr('src', jQuery(this).prev('input[id*="hdnProductImage"]').val());                    
    }, function () { });

    //select style
    $j(".selectContainer").jqTransform();

    //scrolling capsules
    $j(".scroll").scrollable({
        circular: true,
        vertical: true,
        speed: 1000
    });

    //gallery thing for product pages
    $j('.miniNav div').click(function () {
        var divClass = $j(this).attr("class");
        onTab = divClass;

        $j(this).parent().parent().removeClass('featuresDropUl specificationsDropUl equipmentDropUl galleryDropUl videoDropUl deliveryDropUl')
        $j(this).parent().parent().addClass(divClass + 'Ul');
        productElement = "#" + divClass;

        if(divClass == 'equipmentDrop') {
           // FT_Product.ajaxProductData.getProductData(productID, divClass, _miniNavCallBack);
        } else if (($j(productElement).html() == '')) {
          //  FT_Product.ajaxProductData.getProductData(productID, divClass, _miniNavCallBack);
        } 

        divClass = "." + divClass;
        $j(divClass, '.dropdown').slideDown();
        $j(divClass, '.dropdown').siblings().slideUp();

        $j('.miniNav li').removeClass('on');
        $j('.miniNav li').removeClass('prev');
        $j('.miniNav li').removeClass('next');
        
        $j(this).parent().addClass('on');
        $j(this).parent().next().addClass('next');
        $j(this).parent().prev().addClass('prev');

    });

    

    if (onTab!=='') {
        onTab =  onTab.replace('#', '');
        changeTab = ".miniNav ." + onTab;

        $j('.miniNav li').removeClass('on');
        $j('.miniNav li').removeClass('prev');
        $j('.miniNav li').removeClass('next');

        $j('.miniNav div').parent().removeClass('on');
	    $j(changeTab).parent().addClass('on');
        $j(changeTab).parent().next().addClass('next');
        $j(changeTab).parent().prev().addClass('prev');
    } else {

        //set first slide to open
        $j('.miniNav li:first').addClass('on');
        $j('.miniNav li:first').next().addClass('next');
        
    }

    $j('.miniNav li:first').addClass('first');
    $j('.miniNav li:last').addClass('last');
    $j('.dropdown li:first').siblings().slideUp();



    function _miniNavCallBack(response) {


        if (response.error != null) {
            //alert("Error occured" + response.error.Message);
            return;
        }
        
        jQuery(function () {
            $j(productElement).prepend(response.value);
        });
    }


    //login thing
    $j('.loginButton').toggle(function () {
        $j('.loginPanel .ModAuthenticationC').css('display', 'block');
        $j('.loginButton').text('Search');
        $j('.searchContainer').animate({ opacity: 0 }, 300, function () {
            $j('.searchContainer').animate({ height: 0 }, 500);
            $j('.loginPanel .drop').animate({ height: 261 }, 500);
        });
    }, function () {
        $j('.loginButton').text('Login');
        $j('.loginPanel .ModAuthenticationC').fadeOut();
        $j('.loginPanel .drop').animate({ height: 63 }, 500, function () {
            $j('.searchContainer').css({ height: 31 });
            $j('.searchContainer').animate({ opacity: 1 }, 100);
        });
    });

    //cart login thing
    $j('.loginButtonCart').toggle(function () {
        $j('.loginPanel .ModAuthenticationC').css('display', 'block');
        $j('.searchContainer').animate({ opacity: 0 }, 300, function () {
            $j('.searchContainer').animate({ height: 0 }, 500);
            $j('.loginPanel .drop').animate({ height: 261 }, 500);
        });
    }, function () {
        $j('.loginPanel .ModAuthenticationC').fadeOut();
        $j('.loginPanel .drop').animate({ height: 63 }, 500, function () {
            $j('.searchContainer').css({ height: 31 });
            $j('.searchContainer').animate({ opacity: 1 }, 100);
        });
    });

    $j('.search, .enewsletter .input, #dnn_ctr457_Login_Login_DNN_txtUsername, #dnn_ctr457_Login_Login_DNN_txtPassword').inputClearer();

    //vertically center itesm in flyout menu
    $j('.info').each(function () {
        var ah = $j(this).height()
        var ph = $j(this).parent().height();
        var mh = (ph - ah) / 2;
        $j(this).css('margin-top', mh);
    });

    //fixing some top navigation stuff
    $j('[name*=475]').css('display', 'none');
    $j('.SXMenuEnabled:first a, .SXMenuActive:first').css('border-left', '0px');
    $j('.SXMenuEnabled:last a, .SXMenuActive:last').css('border-right', '0px');

    if ($j('.SXMenuItem:first .SXMenuActive').length) {
        $j('.nav').css('background-position', 'center -35px');
        $j('.SXMenuActive:first').css('border-left', '0px');
    }
    if ($j('.SXMenuItem:last .SXMenuActive').length) {
        $j('.nav').css('background-position', 'center -70px');
        $j('.SXMenuEnabled:last a, .SXMenuActive:last a').css('border-right', '0px');
    }

    $j('.SXMenuItem:first').hover(function () {
        if ($j('.SXMenuItem:first .SXMenuActive').length) {
            $j('.nav').css('background-position', 'center -35px');
        } else {
            $j('.nav').css('background-position', 'center -35px');
        }
        if ($j('.SXMenuItem:last .SXMenuActive').length) {
            $j('.nav').css('background-position', 'center -105px');
        } else {
            $j('.nav').css('background-position', 'center -35px');
        }
    }, function () {
        if ($j('.SXMenuItem:first .SXMenuActive').length) {
            $j('.nav').css('background-position', 'center -35px');
        } else {
            $j('.nav').css('background-position', 'center 0px');
        }
        if ($j('.SXMenuItem:last .SXMenuActive').length) {
            $j('.nav').css('background-position', 'center -70px');
        }
    });

    $j('.SXMenuItem:last').hover(function () {
        if ($j('.SXMenuItem:first .SXMenuActive').length) {
            $j('.nav').css('background-position', 'center -105px');
        } else {
            $j('.nav').css('background-position', 'center -70px');
        }
    }, function () {
        if ($j('.SXMenuItem:first .SXMenuActive').length) {
            $j('.nav').css('background-position', 'center -35px');
        } else {
            $j('.nav').css('background-position', 'center top');
        }
    });

    //category corners, first set of rules for one line
    $j('.category-item > ul li:first-child').addClass('first');
    $j('.category-item > ul li:last-child').addClass('last');

    //category corners, second set of rules for two lines
	var liCount = 0
    $j('.category-item > ul').each(function () {
		$j('li:eq(4)', this).addClass('fifth');
        $j('li:eq(4)', this).addClass('fifth');
        $j('li:eq(5)', this).addClass('sixth');
        $j('li:eq(9)', this).addClass('tenth');
        $j('li:eq(10)', this).addClass('eleventh');
        $j('li:eq(14)', this).addClass('fifteenth');
		$j('li:eq(15)', this).addClass('sixteenth');
		$j('li:eq(19)', this).addClass('twentyth');
        if ($j(this).children('li').length > 5) {
            $j(this).addClass('twoLines');
        }
        if ($j(this).children('li').length > 10) {
            $j(this).addClass('threeLines');
            $j(this).removeClass('twoLines');
        }
        if ($j(this).children('li').length > 15) {
            $j(this).addClass('fourLines');
            $j(this).removeClass('threeLines');
        }
        if ($j(this).children('li').length > 20) {
            $j(this).addClass('fiveLines');
            $j(this).removeClass('fourLines');
        }

        //var iteml = $j(this).children('li').length
        
    });

    //events style
    $j('#dnn_ctr481_Events_EventDetails_divEventDetails3 tr:odd').css('background', '#f5f5f5');

    //fix size issue on homepage
    $j('.homeFeature h1 span').each(function () {
        if ($j(this).height() > 19) {
            $j(this).css('font-size', '13px');
        }
    });

    //fix height for small captions on product list page
    $j('.caption span').each(function () {
        if ($j(this).height() < 13) {
            $j(this).css('padding-top', '5px');
        }
    });

    if ($j.browser.msie && $j.browser.version == "7.0") {
        var zIndexNumber = 1000;
        $j('div .categories > li').each(function () {
            $j(this).css('zIndex', zIndexNumber);
            zIndexNumber -= 10;
        });
    }

    //fix height for intro on product pages
    var productImgHeight = $j('.productThumbs').height() - 16;
    $j('.indexIntro').css('min-height', productImgHeight);

	
}
