$(document).ready(function () {
    //$("a.popup").fancybox({});
    $('.comment_content').slideToggle();

    function makeSublist(parent, child, isSubselectOptional, childVal, valBefore, valAfret) {
        $("body").append("<select style='display:none' id='" + parent + child + "'></select>");
        $('#' + parent + child).html($("#" + child + " option"));

        var parentValue = $('#' + parent).attr('value');
        $('#' + child).html($("#" + parent + child + " .sub_" + parentValue).clone());

        childVal = (typeof childVal == "undefined") ? "" : childVal;
        $("#" + child).val(childVal).attr('selected', 'selected');
        $('#' + child).prepend("<option value='0' selected='selected'>" + valBefore + "</option>");
        $('#' + child).attr("disabled", "disabled");

        $('#' + parent).change(function () {
            $('#' + child).removeAttr('disabled');
            var parentValue = $('#' + parent).attr('value');
            $('#' + child).html($("#" + parent + child + " .sub_" + parentValue).clone());
            if (isSubselectOptional) $('#' + child).prepend("<option value='0'>" + valAfret + "</option>");
            $('#' + child + ' option:first').attr("selected", "selected");
            $('#' + child).trigger("change");
            $('#' + child).focus();
        });
    }

    makeSublist('ctl00_ctl00_cph1_ctrlHeader_mLongTail_ddSearch1', 'ctl00_ctl00_cph1_ctrlHeader_mLongTail_ddSearch2', true, '', 'בחר מטרה', 'הכל');



    //category tabs
    $('.product_in_category_main_item').addClass('item_dn');

    $('.product_in_category_main').each(function (index) {
        $(this).children('.product_in_category_main_item').first().addClass('active_tab');
    });
    $('.product_in_category_menu').each(function (index) {
        $(this).children('.product_in_category_menu_item').first().addClass('active');
    });



    $('.product_in_category_menu_item').hover(function () {
        
        $(this).parent().children('.product_in_category_menu_item').removeClass('active');
        $(this).addClass('active');


        var currentTabId = $(this).attr('id');
        $('.' + currentTabId).parent().children('.product_in_category_main_item').removeClass('active_tab');
        $('.' + currentTabId ).addClass('active_tab');
        return false;
    });

    $('.product_in_category_menu_item').hover(function () {

        $(this).parent().children('.product_in_category_menu_item').removeClass('active');
        $(this).addClass('active');


        var currentTabId = $(this).attr('id');
        $('.' + currentTabId).parent().children('.product_in_category_main_item').removeClass('active_tab');
        $('.' + currentTabId).addClass('active_tab');
        return false;
    });

    $("#ctl00_ctl00_cph1_ctrlContactUs1_txtFullName_txtValue").defaultValue("שם מלא");
    $("#ctl00_ctl00_cph1_ctrlContactUs1_txtPhone_txtValue").defaultValue("טלפון");

    //check form on submit
    $('.contactusbutton_small').click(function () {
        if ($("#ctl00_ctl00_cph1_ctrlContactUs1_txtFullName_txtValue").attr('value') == "שם מלא") {
            jAlert("שם מלא חובה","צלצלו אלי");
            return false;
        }
        else if ($("#ctl00_ctl00_cph1_ctrlContactUs1_txtPhone_txtValue").attr('value') == "טלפון") {
            jAlert("טלפון חובה", "צלצלו אלי");
            return false;
        }
        else jAlert("פניה נשלחה", "צלצלו אלי");
    });

    $("a.popup").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 300,
        'speedOut': 100,
        'titlePosition': 'over',
        'overlayShow': true
    });


});
