﻿/*
Cufon.replace('ul.mainmenu li a',{
        hover: false,
        fontSize: '16px'
});
Cufon.replace('div.rotatorHolder ul li a span',{
        hover: false
});
Cufon.replace('ul.mainmenu li ul li a',{
        hover: true
});*/

$(document).ready(function () {
    /*Set width on submenu*/


    var ie6flag = false;
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
        if (ieversion < 7) {
            ie6flag = true;
        }
    }

//    var itemwidths = 0;
//    var i = 0;
//    $('ul.mainmenu > li.activate > a').each(function () {
//        if (i < 4) {
//            itemwidths += $(this).width();
//        }
//        i++;
//    });

//    $('ul.mainmenu li.lastitem a').width((948 - itemwidths));
//    $('ul.mainmenu li.lastitem ul li.searchli').width((948 - itemwidths));

    if (!ie6flag) {
        $("ul.mainmenu").superfish({
            disableHI: true,
            autoArrows: false,
            animation: { margin: 'show' },
            delay: 0
        });

        $('ul.mainmenu li').hover(function () {
            var oldsrc = $(this).find('img').attr('src');
            $(this).children('a').children('img').attr('src', oldsrc.replace('off_', 'on_'));
            $('#ctl00_MainMenu_searchTB').focus();
            $(this).children('a').addClass('menuhover');
        },
        function () {
            var oldsrc = $(this).find('img').attr('src');
            var thislink = $(this).children('a');
            $(thislink).children('img').attr('src', oldsrc.replace('on_', 'off_'));
            $(this).children('a').removeClass('menuhover');
        });
        if ($.browser.safari) {
            $('ul.mainmenu li ul li ul').css('top', '-32px');
        }
    }

    /*RIGHT IMAGE HOVER*/
    /*Set original height*/
    if ($('div#rightSlider1').height() > 16) {
        var rSliderHeight1 = $('div#rightSlider1').height() + 45;
        if (rSliderHeight1 > 425)
            rSliderHeight1 = 425;
        //set to standard height    
        $('div#rightSlider1 div').css('display', 'none');
        var orgRightSlider1 = '45';
        if ($('div#rightSlider2').length !== 0) {
            rSliderHeight1 = rSliderHeight1 + 45; //move topslider more when two sliders exist
            $('div#rightSlider1').css('height', '110px');
            orgRightSlider1 = '110';
        }
        else {
            $('div#rightSlider1').css('height', '45px');
        }
    }
    else {
        //hide if no content in div
        $('div#rightSlider1').css('display', 'none');
    }
    if ($('div#rightSlider2').height() > 16) {
        if (rSliderHeight2 > 425)
            rSliderHeight2 = 425;
        var rSliderHeight2 = $('div#rightSlider2').height() + 20;
        if (rSliderHeight2 > 425)
            rSliderHeight2 = 425;
        //set to standard height    
        $('div#rightSlider2 div').css('display', 'none');
        $('div#rightSlider2').css('height', '50px');
    }
    else {
        //hide if no content in div
        $('div#rightSlider2').css('display', 'none');
    }
    /*expand on hover*/
    $('div#rightSlider1').hover(
	    function () {
	        $(this).children('div').slideDown();
	        $(this).stop().animate({ bottom: '0px', height: rSliderHeight1 + 'px' }, "200");
	    },
	    function () {
	        $(this).stop().animate({ bottom: '0px', height: orgRightSlider1 + 'px' }, "200");
	        $(this).children('div').slideUp();

	    });

    $('div#rightSlider2').hover(
	    function () {
	        $('div#rightSlider1').stop();
	        $(this).children('div').slideDown();
	        $(this).stop().animate({ bottom: '0px', height: rSliderHeight2 + 'px' }, "200");
	        $('div#rightSlider1').animate({ height: (rSliderHeight2 + 64) + 'px' }, "200");
	    },
	    function () {
	        $(this).stop().animate({ bottom: '0px', height: '50px' }, "200");
	        $(this).children('div').slideUp();
	        $('div#rightSlider1').animate({ height: orgRightSlider1 + 'px' }, "200");
	    });


    /*SEARCH RESULT SLIDERS*/
    $("#slider").easySlider({
        auto: false,
        controlsShow: false,
        speed: 600,
        prevId: 'prodPrev',
        nextId: 'prodNext',
        controlsFade: false
    });
    $("#slider2").easySlider({
        auto: false,
        controlsShow: false,
        speed: 600,
        prevId: 'pagePrev',
        nextId: 'pageNext',
        controlsFade: false

    });
    $('span#prodNext a').click(function () {
        var oldtext = parseInt($('#prodCurPage').html());
        if (oldtext < parseInt($('#totProds').html())) {
            $('#prodCurPage').text(oldtext + 1);
            $('span#prodPrev a').css('color', '#000');
        }
        if (oldtext === (parseInt($('#totProds').html()) - 1))
            $('span#prodNext a').css('color', '#b4b4b4');
    });
    $('span#prodPrev a').click(function () {
        var oldtext = parseInt($('#prodCurPage').html());
        if (oldtext > 1) {
            $('#prodCurPage').text(oldtext - 1);
            $('span#prodNext a').css('color', '#000');
        }
        if (oldtext === 2)
            $('span#prodPrev a').css('color', '#b4b4b4');
    });

    $('span#pageNext a').click(function () {
        var oldtext = parseInt($('#pageCurPage').html());
        if (oldtext < parseInt($('#totPages').html())) {
            $('#pageCurPage').text(oldtext + 1);
            $('span#pagePrev a').css('color', '#000');
        }
        if (oldtext === (parseInt($('#totPages').html()) - 1))
            $('span#pageNext a').css('color', '#b4b4b4');
    });
    $('span#pagePrev a').click(function () {
        var oldtext = parseInt($('#pageCurPage').html());
        if (oldtext > 1) {
            $('#pageCurPage').text(oldtext - 1);
            $('span#pageNext a').css('color', '#000');
        }
        if (oldtext === 2)
            $('span#pagePrev a').css('color', '#b4b4b4');
    });

    //FORM SLIDER
    $("#formslider").easySlider({
        auto: false,
        controlsShow: false,
        speed: 600,
        prevId: 'formPrev',
        nextId: 'formNext',
        controlsFade: false

    });
    $('span#formNext a').click(function (e) {
        if ($('.rbl1 input:checked').length < 1) {
            $('.validator1').show();
            e.preventDefault();
        };
        if ($('.rbl2 input:checked').length < 1) {
            $('.validator2').show();
            e.preventDefault();
        };
        if ($('.rbl3 input:checked').length < 1) {
            $('.validator3').show();
            e.preventDefault();
        };

    });
    $('a#policy').click(function (event) {
        $('#popupcontainer').load('/privacypolicy.html', function () {
            $('#popupdiv').overlay({
                top: 50,
                expose: {
                    color: '#fff',
                    loadSpeed: 100,
                    opacity: 0.6
                },
                closeOnClick: false,
                api: true
            }).load();
        });
    });
});




