function bindOpenLink() 
{
	$('#openLinkWindow').bind('click', function() {
		$('#linkDiv').toggle();
		$('#linkToGet').select();
	});						
	
}


function showTooltip(){
	$('.cutted').tooltip({
	    track: true, 
	    delay: 0, 
	    showURL: false, 
	    showBody: " - ", 
	    fade: 250 
	});
}

$(document).ready(function() {	
	
	$('.buy').bind('click', function() {				
		$("#contentLoading").show();
		
		
		$iId = $(this).attr('id');
		
		$iCount = $("#quantity_" + $iId).attr('value');				
		
		 $.ajax({
		   type: "GET",
		   url: "/fast-shop/buy/id/"+$iId + "/count/" + $iCount,
		   success: function($data){
			 	$("#contentLoading").hide();  
	   			trush();
	   			count();
	   			reloadCart();
	   			
		   }
		 });
		}); 	
	
	bindOpenLink();
	
	$('.showProduct').bind('click', function() {
		$id = $(this).attr('id');
		$actionedUrl = "/product/wizard-product/id/" + $id;
		$("#contentLoading").show();  
		 $.ajax({
		   type: "GET",
		   url: $actionedUrl,
		   success: function($data) {
			 $("#contentLoading").hide();  

			 $("#content_offers").fadeOut(function() {
				 document.getElementById('content_offers').innerHTML=$data;
				 $("#content_offers").fadeIn();
				 showTooltip();				
				 bindOpenLink();				 
			$(".quantityInput").keyup(function() {
				if (parseInt($(this).val()) >= 100)
					$(this).val(99);
				if (parseInt($(this).val()) == 0)
					$(this).val(1);
				if (!parseInt($(this).val()) && $(this).val() != ""){				
					$(this).val(1);
				}
			});									 
				 
			$('.buy').bind('click', function() {				
				$("#contentLoading").show();
				
				
				$iId = $(this).attr('id');
				
				$iCount = $("#quantity_" + $iId).attr('value');				
				
				 $.ajax({
				   type: "GET",
				   url: "/fast-shop/buy/id/"+$iId + "/count/" + $iCount,
				   success: function($data){
					 	$("#contentLoading").hide();  
			   			trush();
			   			count();
			   			reloadCart();
			   			
				   }
				 });
				}); 					 
				 
			 });
			 
		   }
		 });
		return false; 
	});
	
	$('ul a').collapsor();
	$('dl strong').collapsor({sublevelElement:'dl', speed: 1000});
	$('.showProduct').bind('click', function() {
		$('.showProduct').attr('class', 'showProduct');
		$('ul li ul').css('display', 'none');
		$(this).parent().parent().attr('style', 'display:block');
		$(this).parent().parent().parent().children('a').attr('class', 'open');
		$(this).attr('class', 'showProduct open');
	});
});
