$(function() {
    // ANIMATION - BRANDS
    $('#brand-nav ul li').hover(function() {
        $(this).stop().animate({ marginLeft: -30 }, { duration: 500, easing: 'easeOutBounce' });
        // $(this).children().stop().animate( { opacity: 0.3 }, { duration: 300 });
    }, function() {
        $(this).stop().animate({ marginLeft: 0 }, { duration: 500, easing: 'easeOutBounce' });
        // $(this).children().stop().animate( { opacity: 1 }, { duration: 300 });
    });
    // ANIMATION - BRANDS

    

    // TECH SPECS PANEL
    $('#techspecs-open').click(function() {
        $('#techspecs-panel').slideToggle('normal');
        return false;
    });
    // TECH SPECS PANEL

    // HOME PAGE SLIDER
    var sliderControlAnimate = $(this).parent('.promo-slider-control').siblings('.promo-content').children('a').stop().animate;
    $('div.promo-slider-control a.link-one').click(function() {
        $(this).parent('.promo-slider-control').siblings('.promo-content').children('a').stop().animate({ marginTop: 0 }, { duration: 750, easing: 'easeOutBack' });
        return false;
    });
    $('div.promo-slider-control a.link-two').click(function() {
        $(this).parent('.promo-slider-control').siblings('.promo-content').children('a').stop().animate({ marginTop: -207 }, { duration: 750, easing: 'easeOutBack' });
        return false;
    });
    $('#lower-promo-area ul li').hover(function() {
        $(this).children().stop().animate({ opacity: 0.3 }, { duration: 300 });
    }, function() {
        $(this).children().stop().animate({ opacity: 1 }, { duration: 300 });
    });
    // HOME PAGE SLIDER

    //Compare
    var valueField = $("#hdnSelectedIdDiv input");
    if (valueField.length > 0) {
        var currentValue = valueField.val();
        

        
        if (currentValue.length == 0) {

            //valueField.val(currentValue + ',');
//            $("#number-selected").html(1);
        }
        else {
            currentValue = valueField.val();
            var countValue = currentValue.substr(0, currentValue.length - 1);
            var prods = countValue.split(",");
            //var pageCount = $("#productList input:checked").size();
            var selectedCount = prods.length;



            //if ($("#view-comparison").exists()) {
            var compareSection = $("#view-comparison");
            //var compareFinsTip = $(".compareButton div");

            // Add active class to button if more than 2 fins are checked
            if ((selectedCount + 1) > 1) {
                //                if (compareFinsButton.hasClass("active") == false) {
                compareSection.fadeIn("slow");
                //              }
            }
            // Remove active class if there aren't enough fins selected to compare
            else {
                compareSection.fadeOut("slow");
            }
            $("#number-selected").html(selectedCount);
        }
    }
    //Compare



    // NAV DROPPER
    $("li.parent").hover(function() {
        $(this).children("ul.dropper").stop().animate({ height: 400 }, { duration: 0, easing: 'easeOutSine' });
    }, function() {
        $(this).children("ul.dropper").stop().animate({ height: 0 }, { duration: 0, easing: 'easeOutSine' }).hide();
    });
    $("li.sub").hover(function() {
        $(this).children("ul.sub-dropper").stop().animate({ height: 400 }, { duration: 0, easing: 'easeOutSine' });
        $(this).addClass("selected");
    }, function() {
        $(this).children("ul.sub-dropper").stop().animate({ height: 0 }, { duration: 0, easing: 'easeOutSine' }).hide();
        $(this).removeClass("selected");
    });
    $("li.sub").children("a").addClass("sub-selected");
    // NAV DROPPER
	
	
	// 3rd level DROPPER
    $("li.parenttwo").hover(function() {
        $(this).children("ul.sub-sub-dropper").stop().animate({ height: 400 }, { duration: 0, easing: 'easeOutSine' });
        $(this).addClass("selected");
    }, function() {
        $(this).children("ul.sub-sub-dropper").stop().animate({ height: 0 }, { duration: 0, easing: 'easeOutSine' }).hide();
        $(this).removeClass("selected");
    });
    $("li.sub2").children("a").addClass("sub-selected");
    // 3rd level DROPPER
	
	

    // JQTRANSFORM
    $("#contact-form, #modify").jqTransform();
    // JQTRANSFORM

    // TABLE COLOURS
    $("tr:even").css("background-color", "#0069aa");
    $("tr:odd").css("background-color", "#999999");
    // TABLE COLOURS
    
    
});

// PRODUCT COMPARE
/* $("#product-listing a.jqTransformCheckbox").click(function() {
$("#number-selected").html(function() {
var numSelected = $("a.jqTransformChecked").length;
return (numSelected);
});
if ($("a.jqTransformChecked").size() > 1 && $("a.jqTransformChecked").size() < 4) {
$("#view-comparison").fadeIn("slow");
}
else ($("#view-comparison").fadeOut("slow"));
if ($("#product-listing a.jqTransformChecked").size() >= 4) {
$("#max-checked").fadeIn("slow");
$("#view-comparison").fadeOut("slow");
$("html, body").stop().animate({ scrollTop: 250 }, { duration: 1000, easing: 'jswing' });
return false;
}
else {
$("#max-checked").fadeOut("slow");
}
});
*/
//PRODUCT COMPARE

function CheckRemove(value, checkField) {

    var valueField = $("#hdnSelectedIdDiv input");
    var currentValue = valueField.val();

    if (valueField.val().length == 0) {
        valueField.val(value + ',');
        $("#number-selected").html(1);
    }
    else {
        currentValue = valueField.val();
        var countValue = currentValue.substr(0, currentValue.length - 1);
        var prods = countValue.split(",");
        //var pageCount = $("#productList input:checked").size();
        var selectedCount = prods.length;


        //if ($("#view-comparison").exists()) {
        var compareSection = $("#view-comparison");
        //var compareFinsTip = $(".compareButton div");

        // Add active class to button if more than 2 fins are checked
        if ((selectedCount + 1) > 1) {
            //                if (compareFinsButton.hasClass("active") == false) {
            compareSection.fadeIn("slow");
            //              }
        }
        // Remove active class if there aren't enough fins selected to compare
        else {
            compareSection.fadeOut("slow");
        }

        // Disable selection of fin, show and scroll to Compare Fins tip
        if ((selectedCount) >= 3) {

            if (currentValue.indexOf(value) >= 0) {
                var temp = currentValue.replace(value + ',', '');
                valueField.val(temp);
            }
            else {
                valueField.val(currentValue + value + ',');
            }
            currentValue = valueField.val();
            countValue = currentValue.substr(0, currentValue.length - 1);
            prods = countValue.split(",");
            //var pageCount = $("#productList input:checked").size();
            selectedCount = prods.length;

            if ((selectedCount) >= 3) {
                $("#max-checked").fadeIn("slow");
                $("#view-comparison").fadeOut("slow");
                $("html, body").stop().animate({ scrollTop: 250 }, { duration: 1000, easing: 'jswing' });
                if (currentValue.indexOf(value) >= 0) {
                    var temp = currentValue.replace(value + ',', '');
                    valueField.val(temp);
                }

                checkField.checked = false;
                return false;
            }
        }
        else {
            if (currentValue.indexOf(value) >= 0) {
                var temp = currentValue.replace(value + ',', '');
                //} else {
                //temp = currentValue.replace(value, '');
                //}
                //alert(temp)
                valueField.val(temp);
            }
            else {
                valueField.val(currentValue + value + ',');
            }
            //alert(valueField.val());
        }
        //}

        currentValue = valueField.val();
        countValue = currentValue.substr(0, currentValue.length - 1);
        prods = countValue.split(",");
        //var pageCount = $("#productList input:checked").size();
        selectedCount = prods.length;
        $("#number-selected").html(selectedCount);

    }

}