$(document).ready(function() {
    $("#toggleall").click( function() {
        $('#cart-items input:checkbox:enabled').each(function(){
            this.checked = !this.checked;
        });
        $(this).attr("checked", !$(this.attr("checked")));
        return false;
    });
	$('.intro-slider').loopedSlider({
		slidespeed: 500,
		autoStart: 5000
	});
    // initialize overlay
    initOverlay();
});
function initOverlay()
{
    // creating overlay
    $("div.BascketButton a[rel], div.SockBasketBnt a[rel]").overlay({
        api : true,
        'maskk' : 'lightgrey',

		onBeforeLoad: function() {
            $("#basket-overlay").css("display", "block");
			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".contentWrap");
			// load the page specified in the trigger
			wrap.load(this.getTrigger().attr("href"));
		}
    
    });
}
function initCart()
{
    $(".TBodyCheck input").click(function()
    {
        var checked = !$(this).parents("tr").hasClass("OpenTr");
//        console.log(checked);
        if   (checked)
        {
            $(this).parents("tr").addClass("OpenTr");
        }
        else
        {
            $(this).parents("tr").removeClass("OpenTr");
        }
    }),


    $(".CloseBTN").click(function()
    {
        $('.PopupSocks').hide();
    }),


    $(".TbodySize input").click(function()
    {
        index = $(this).parents("td").find("input").index($(this));
//        console.log(index);
        if   ($(this).attr('checked'))
        {
            $(this).parents("tr").find(".TbodyCount input:eq("+index+")").removeClass("Disabl");
            $(this).parents("tr").find(".TbodyCount input:eq("+index+")").focus();
        }
        else
        {
            $(this).parents("tr").find(".TbodyCount input:eq("+index+")").addClass("Disabl");
        }
    }),

    $(".TbodyCount input").keyup(function()
    {
        if ( ($(this).val()*1) > 0)
        {
            $(this).removeClass("Disabl");
        }
        else
        {
            $(this).addClass("Disabl");
        }
    });
}
function initAjaxForm(id)
{
    var options = {
        target : '#basket-items',
        success : showResponse,
        error : function(response) {
            console.log(response);
        }
    }
    $("#" + id).ajaxForm(options);
}
function showResponse(responseText, statusText, xhr, $form)  { 
    if(statusText == "success") {// update cart
        $("#basket-overlay").css("display", "none");
    }
} 
function popitup(url) {
	newwindow=window.open(url,'name','height=400,width=441,location=0');
	if (window.focus) {newwindow.focus()}
	return false;
}
function Init(id,code)
{
    var img = $("#sock_" + id + "_" + code);
    $("#imageHolder_" + id).attr("src", img.attr("src"));
    $("#imageHolder_" + id).attr("alt", img.attr("alt"));
    $("#imageHolder_" + id).attr("title", img.attr("title"));
}
