// JavaScript Document
$(document).ready(function() {
	
	var winWidth = document.body.clientWidth;
	
	if(winWidth < 1100) {
		$('#leftFlourish').hide();
		$('#rightFlourish').hide();
	}
	
	$('.buy').click(function() {
	    if($('#ctl00_ContentPlaceHolder1_ddlSize').val() != "0")
        {
		    addToCart();
		    $('img#cartImg').remove();
		    $('#cartImgWrap').prepend('<img src="gfx/cartAnim_M.gif?q=' + new Date().getMilliseconds() + '" id="cartImg" />');
		}
		else
		{
		    $('#error').dialog();		    
		}
		return false;
	});
	
	$('.cartItem a.remove').click(function(){
		var cartItem = $(this).parent().addClass('remove');	
		$(this).parent().fadeOut();
		return false;
	});

	
	$('#navWrap').corner();
	$('.addWhite').corner();
	$('#sideBar').corner();
	$('#frontInfo').corner();
	$('p.msg').corner();
	$('p.sent').corner();
	$('p.sentfail').corner();
	
	/*$('a.iframe').fancybox({'hideOnContentClick': true, 'frameWidth' : 400, 'frameHeight' : 490});
	$('a.spinme').fancybox({'hideOnContentClick': true, 'frameWidth' : 400, 'frameHeight' : 490});*/
	
});



function addToCart()
{    
    $.post('CartHandler.aspx', {action: 'add', pId: $('#hdnProdId').val(), qty: $('#amount').val(), size: $('#ctl00_ContentPlaceHolder1_ddlSize').val()},
	    function(data){
	        $('p#cartStatus').empty().append(data);    
	    });
}

function updateCities(country)
{
    $.post('ResellerHandler.aspx', {action: 'updateCities', country: country},
	    function(data){
	        $('#selectCity').empty().append(data);    
	        $('#selectCity').focus();
	    });
}

function displayResults()
{
    var cityValue = $('#selectCity').val();
    var countryValue = $('#selectCountry').val();
    var dam = $('#dam:checked').val() == undefined ? 0 : 1;
    var herr = $('#herr:checked').val() == undefined ? 0 : 1;
    var ugg = $('#ugg:checked').val() == undefined ? 0 : 1;
    $.post('ResellerHandler.aspx', {action: 'displayResults', country: countryValue, city: cityValue, dam: dam, herr: herr, ugg: ugg},
    function(data){
        $('#retailResults').empty().append(data);            
    });
}

function showSelected(retailerId)
{
    $.post('ResellerHandler.aspx', {action: 'showSelected', retailer: retailerId},
    function(data){
        $('#retailSelected').empty().append(data);            
    });
}

function getCartQuantity()
{
    $.post('CartHandler.aspx', {action: 'getQuantity'},
	    function(data){
	        $('p#cartStatus').empty().append(data);    
	    });
}

function removeFromCart(cartId)
{
    $.post('CartHandler.aspx', {action: 'remove', cartId: cartId},
    function(data){
        $('#cartSum').empty().append(data);
        getCartQuantity();
    });
}

function updateCartAmount(cartId, amount)
{    
    $.post('CartHandler.aspx', {action: 'updateAmount', qty: amount, cartId: cartId},
        function(data){
            $('#cartSum').empty().append(data);
            getCartQuantity();    
        }
    );
}

function updateSize(cartId, attributeId)
{    
    $.post('CartHandler.aspx', {action: 'updateSize', size: attributeId, cartId: cartId});
}
