$('#noscript').remove();
$('.noscript').hide();

var isIE6 = false;
if($.browser.msie && $.browser.version < 7){
	isIE6 = true;
};

$(document).ready(function(){
	$('.havescript').show();
	$('a#show-filters').click(function(event){
		event.preventDefault();
		$('div#filters').slideToggle('200');
	});

});

$(document).ready(function() {
     tooltip();
     $('.qtysub, .qtyadd').show();
     if(!$('#different_delivery_address').attr('checked')) {
    	$('.d').hide();
     };
     $('#different_delivery_address').click(function(){
     	$('.d').toggle();
     });
     $('#main .td-prodqty .qtyadd').click(function () {
     	var i = $(this).parent('td').children('input').val();
     	i++;
     	$(this).parent('td').children('input').val(i);
     	return false;
     });
     $('#main .td-prodqty .qtysub').click(function () {
     	var i = $(this).parent('td').children('input').val();
     	if (i!=0) {
	     	i--;
	     	$(this).parent('td').children('input').val(i);
     	}
     	return false;
     });
     $('#main .prodqty .qtyadd').click(function () {
     	var i = $(this).parent('li').children('input').val();
     	i++;
     	$(this).parent('li').children('input').val(i);
     	return false;
     });
     $('#main .prodqty .qtysub').click(function () {
     	var i = $(this).parent('li').children('input').val();
     	if (i!=0) {
	     	i--;
	     	$(this).parent('li').children('input').val(i);
     	}
     	return false;
     });
     $('#ac_template_61 #main .prodqty .qtyadd,#ac_template_15 #main .prodqty .qtysub').click(function () {
     	var i = $(this).parent('div').children('input.ipt-qty').val();
     	i++;
     	$(this).parent('div').children('input.ipt-qty').val(i);
     	return false;
     });
     $('#ac_template_61 #main .prodqty .qtysub,#ac_template_15 #main .prodqty .qtysub').click(function () {
     	var i = $(this).parent('div').children('input.ipt-qty').val();
     	if (i>1) {
	     	i--;
	     	$(this).parent('div').children('input.ipt-qty').val(i);
     	}
     	return false;
     });
    //if(!isIE6){
	    $('.product-list li img').hover(function(){
			$(this).attr('src',$('#image_path').val()+'/product/product_overview_hover/'+$(this).attr('rel')+'.png');
		},
		function(){
			$(this).attr('src',$('#image_path').val()+'/product/product_overview/'+$(this).attr('rel')+'.png');
		});
		$('.product-list li .accessory-img').hover(function(){
			$(this).css('background-image','url('+$('#image_path').val()+'/product/product_overview_hover/'+$(this).attr('rel')+'.png)');
		},
		function(){
			$(this).css('background-image','url('+$('#image_path').val()+'/product/product_overview/'+$(this).attr('rel')+'.png)');
		});
    //};
	$('.product-list .a-buy').click(function(){
		var rel = $(this).attr('rel');
		$('#'+rel).toggle();
		return false;
	});	
	$('.product-list .panel .close').click(function(){
		$(this).parent('.panel').hide();
	});
	$('#ac_template_61 .btn-addtobag,#ac_template_15 .btn-addtobag').click(function(){
		var id = $(this).parent('.panel').attr('id');
		id = id.substring(6);
		 $.ajax({
		   type: 'GET',
		   url: $('#web_path').val()+'scripts/ajax_basket_add.php',
		   data: ({
		   		sku_to_add: $('#panel_'+id+' .selectedcode').val()+'-'+$('#panel_'+id+' .selectedclr').val()+'-'+$('input:radio[name=selectedsize_'+id+']:checked').val(),
		   		selectedquantity: $('#panel_'+id+' .ipt-qty').val(),
		   		selectedsize: $('input:radio[name=selectedsize_'+id+']:checked').val()
		   }),
		   success: function(msg){
		     	if(msg>-1) {
		     		$('#header_bag_qty').text('('+msg+')');
		     		$.jGrowl('Item successfully added to your<br />shopping bag!');		
		     	}
		   }
		 });
		 $(this).parent('.panel').hide();
		 return false;
	});
	$('#product-image .thumbnail').click(function(){
		$('#product-image .jqzoom').attr('href',$('#image_path').val()+'product_detail_hi_res/'+$(this).attr('rel').substring(0,$(this).attr('rel').indexOf('.'))+'.jpg');
		$('#product-image .display').attr('src',$('#image_path').val()+'product_detail/'+$(this).attr('rel'));
	});
	if(isIE6) {
		$('.panel, .a-buy').remove();
	};
	$('#btn-reset').click(function(){
		$('#filters input').removeAttr('checked');
		return false;
	});
	$('#newsletter_signup').click(function () {
		$('#box_newsletter').toggle();
		$('#box_newsletter button').show();
		$('#box_newsletter input').show();
		$('#box_newsletter label').css('width','100px').html('Your email');
		return false;
	});
	$('#box_newsletter .close').click(function () {
		$('#box_newsletter').hide();
		return false;
	});
	$('#box_newsletter button').click(function () {
		$.ajax({
		   type: 'GET',
		   url: $('#web_path').val()+'scripts/ajax_store_email.php',
		   data: ({
		   		email: $('#ipt_newsletter').val()
		   }),
		   success: function(msg){
		     	$('#box_newsletter button').hide();
				$('#box_newsletter input').hide();
				$('#box_newsletter label').css('width','350px').html(msg);	
		   }
		});
	});
	if(!isIE6) {
		$('.jqzoom').hover(function(){
			$('.options-heading').animate({opacity: 1.0}, 200, "linear", function(){
				$('body').append($('<div class="window_overlay"></div>').css({'top':$('.jqZoomWindow').css('top'),'left':$('.jqZoomWindow').css('left')}));
				$('body').unbind().click(function() {
					$('.window_overlay').remove();	
				});
			});
		},function(){
			$('.window_overlay').remove();
		});
	};
}); 

// jQuery tooltip by Alen Grakalic (http://cssglobe.com)
// modified by Story Worldwide
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 0;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".jTip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$(".jTip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};
