	$(document).ready(function() {
		$("a[rel=lightbox]").fancybox({
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
		});

		$(".vidbox").click(function() {
			$.fancybox({
					'padding'					: 0,
					'autoScale'				: false,
					'transitionIn'		: 'elastic',
					'transitionOut'		: 'elastic',
					'title'						: this.title,
					'width'						: 480,
					'height'					: 270,
					'href'						: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/')+'&amp;rel=0',
					'type'						: 'swf',
					'swf'							: {
					'wmode'						: 'transparent',
					'allowfullscreen'	: 'true'
					}
				});

			return false;
		});	
		
		$(".popupContact").fancybox({
				'width'					: 440,
				'height'				: 325,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
		});
			
		// Search multiselect with images and checkbox
		$(".multiselect").multiSelect({ 
			selectAll: false,
			noneSelected: 'התאמה לאוכל' 
		});
		$(".openPop").fancybox({
				'width'					: 440,
				'height'				: 325,
				'autoScale'				: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
		});
			
		$("#linkAddMsg").fancybox({
				'width'					: 440,
				'height'				: 325,
				'autoScale'				: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
		});
			
		$("#termsPage").fancybox({
				'width'					: 800,
				'height'				: 325,
				'autoScale'				: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
		});
			
		$("#CVVmsg").fancybox({
				'width'					: 440,
				'height'				: 325,
				'autoScale'				: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
		});
			
		// Cupon
		$('#checkCupon').click(function () {
			var cupon = $('#cupon').val();
			var xmlHttp;
			// Firefox, Opera 8.0+, Safari    
			try {xmlHttp=new XMLHttpRequest();}
			catch (e)  {
				// Internet Explorer        
				try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
			  catch (e) {      
			    try {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			    catch (e) {alert("Your browser does not support AJAX!");return false;}      
				}    
			}
			xmlHttp.onreadystatechange=function() {
				if(xmlHttp.readyState==4) {
					res = xmlHttp.responseText;
//				alert(res);
					if (res > 0){
						$('.popupCuponText').html("הקופון עודכן בהצלחה, הוא מעניק לך הנחה של "+res+" אחוז " );
						$('.popupCuponFrm').html('<input type="button" name="closeCupon" class="cartBtnLink" value="המשך" onclick="$.fancybox.close()" />');
						var discount = parseFloat($('#amount').val()) * parseFloat(res) / 100;
						discount = Math.round(discount);
						var totalWidthDiscount = parseFloat($('#sum').val())-discount;
						$('#cartCuponPrice').html(discount);
						$('#cartTotalPriceDiscount').html(totalWidthDiscount);
						$('#sum').val(totalWidthDiscount);
					}
					else{
						$('.popupCuponText').html('<span class="error">הקופון שהנזת אינו תקין אנא נסה שנית</span>');
//						$('.popupCuponText').html(url);
					}
				}
			}			url = "checkcupon.asp?c="+cupon;			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);  

			return false;
		});
		
		
		// Add to cart
		$('.addToCart').click(function () {
			var itemQuantity = 1;
			var itemID 	  = $(this).attr('id').replace('item_','');
			if ($(this).attr('class') == 'addToCart page')
				itemQuantity = getElement("itemQuantity").value;
			
			var xmlHttp;
			// Firefox, Opera 8.0+, Safari    
			try {xmlHttp=new XMLHttpRequest();}
			catch (e)  {
				// Internet Explorer        
				try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
			  catch (e) {      
			    try {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			    catch (e) {alert("Your browser does not support AJAX!");return false;}      
				}    
			}
			xmlHttp.onreadystatechange=function() {
				if(xmlHttp.readyState==4) {
					res = xmlHttp.responseText;
//				alert(res);
					tmpArr = res.split("&");
					if (tmpArr.length == 2){
						cartPrice = tmpArr[0];
						cartQuantity = tmpArr[1];

						document.getElementById("cartItemsNum").innerHTML = cartQuantity;
						document.getElementById("cartAmount").innerHTML = cartPrice;
						if (isProductPage == 1){
							document.getElementById("cartItemsNumP").innerHTML = cartQuantity;
							document.getElementById("cartAmountP").innerHTML = cartPrice;
						}						
						lsMsg = '<img src="images/accept.png" alt="" />&nbsp;&nbsp;הפריט התווסף לסל בהצלחה!';
					}
					else{
						cartErr = tmpArr[0];
						lsMsg = '<img src="images/cancel.png" alt="" />&nbsp;&nbsp;ארעה שגיאה בהוספת המוצר לסל! אנא נסה/י שנית.';
//						lsMsg = url;
					}
					$('#popupAddToCartMsg h3').html(lsMsg);
					$('#linkAddMsg').trigger('click');
				}
			}			url = "insertToCart.asp?itemID="+itemID+"&itemQuantity="+itemQuantity;			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);  

			return false;
		});
			
	});
	

