﻿/// <reference path='../jquery-1.2.6.js' />
$(document).ready(function() {
    $('#ctl00_ctl00_MainPlaceHolder_MainContentPlaceHolder_AddToCartLink').click(addToCart);
    $('#ctl00_ctl00_MainPlaceHolder_MainContentPlaceHolder_AddToFairCartLink').click(addToCart);
	$('#ctl00_ctl00_MainPlaceHolder_MainContentPlaceHolder_ToCartLink').click(toCart);
    
    $('div.productInfoViewer').hide();
});

function addToCart() {
    var button = $(this);
    $(button).css('cursor', 'wait');
    $('table input[type=text]').each(function(i) {
        if (this.value != '') {
            $.ajax({
                async: 'false',
                type: 'GET',
                url: ["http://",location.host,'/Templates/Public/data/AddItemToCart.aspx'].join(''),
                data: 'ProductId=' + this.id.split('_')[1] + '&Count=' + this.value + '&CartName=' + $(button).attr("value")
            });
            this.value = '';
        }
    });
    $('#outerCart').load(["http://",location.host,'/Templates/Public/Data/GetCart.aspx?&epslanguage=',epslanguage,' #outerCart > *'].join(''), function() { $(button).css('cursor', 'pointer'); });
}

function toCart() {
    var button = $(this);
	var hit = false;
    $(button).css('cursor', 'wait');
    $('table input[type=text]').each(function(i) {
        if (this.value != '') {
			hit = true;
            $.ajax({
                async: 'false',
                type: 'GET',
                url: ["http://",location.host,'/Templates/Public/data/ToCart.aspx'].join(''),
                data: 'ProductId=' + this.id.split('_')[1] + '&Count=' + this.value,
				success: function(data) { eval(data);$('#CartDiv').load(["http://",location.host,'/Templates/Public/Data/GetCart.aspx?&epslanguage=',epslanguage,' #CartDiv > *'].join(''), function() { $(button).css('cursor', 'pointer'); }); }
            });
            this.value = '';
			$("html").animate({ scrollTop: 0 }, "slow");
        }
    });
	if(!hit) {
		$(button).css('cursor', 'pointer');
		$w.box({mod:true,width:338,msg:$w.l("forgotQyt")});
	}
	//javascript:$w.box({mod:true,width:291,head:"Meddelande",msg:"En produkt har lagts till i varukorgen, vad vill du göra?<a onclick=\"$w.box({close:true});return false;\" class=\"btn\"><span>Fortsätt handla</span></a><a style=\"float: right;\" class=\"btn_ico\" href=\"/Butiken/Varukorg/\"><img alt=\"\" src=\"http://images.watski.com/icons/cart_add.png\"><span>Gå till varukorgen</span></a><br /><br /><br />"});
}


function ViewInfo(id) {
    $('#productInfoViewer').load(["http://",location.host,'/Templates/Public/Data/ProductInfo.aspx?epslanguage=',epslanguage,'&EnovaId=',id,' #PageData'].join(''), function() {
        $('#productInfoViewer').css('top', ($('#infoLink_' + id).position().top - $('#productInfoViewer').height() + 15) + 'px');
        $('#productInfoViewer').css('left', ($('#infoLink_' + id).position().left) - 30 + 'px');
        $('#productInfoViewer').show();
        $('div.productInfo div.productInfoMiddle').height($('div.productInfo div.productInfoMiddle table').height()+50);
        InitAjax();
    });
    return false;
}

function openImage(file) {
    $('#ImageViewer').show();
    $('#ImageOuterHolder').css('display', 'block');
    $('#ImageHolder').html('<img src="' + file.replace('ConversionFormat_4', 'ConversionFormat_28') + '">');

    $('#ImageHolder').click(function() {
        HideLargeImage();
    }
    )
    
    $('#ImageClose').click(function() {
        HideLargeImage();
    }
    )
    
    }

    function HideLargeImage() {
        $('#ImageViewer').hide();
        $('#ImageOuterHolder').hide();
    }
