function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
	}
	function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
	}
 
function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	 return pattern.test(emailAddress);
	};

	$(document).ready(function() {
		$(function() {
        $(this).bind("contextmenu", function(e) {
            e.preventDefault();
        });
    }); 
		var jRun = 0;
		function itemLoadCallbackFunction(carousel, state)
		{
//		    for (var i = carousel.first; i <= carousel.last; i++) {
//		        // Check if the item already exists
//		        if (!carousel.has(i)) {
//		            // Add the item
//		            carousel.add(i, "I'm item #" + i);
//		        }
//		    }
			var size = carousel.options.size;
			var current = carousel.first;
			
//			console.log(carousel.first);
			
		jRun++;
			
		$('#gallery-dots a.active').removeClass('active');
		$('#gallery-dots a[rel='+(jRun)+']').addClass('active');
		
		
			
			if (jRun % 3 == 0)
			{
				jRun = 0;
//				current = current-size;
//				console.log('------ GOT TO THE FIRST FUCKING DOT...........--------------');
			}
			
			
//			console.log(jRun)
		};

		
		function mycarousel_initCallback(carousel)
		{
			var dotsLength = carousel.options.size / carousel.options.scroll;
			
			for (i = 1;i <= dotsLength;i++)
			{
				var li = $('<li><a href="#">•</a></li>');
				var a = li.find('a');
				
				a.attr('rel',i);
				
				
				a.click(function(e){
					e.preventDefault();
					var gotoRun = $(this).attr('rel') ;
					var start = 1;
					if (gotoRun > 1)
					{
						
						start = (gotoRun * carousel.options.scroll) - carousel.options.scroll +1;// - carousel.options.scroll -1
						if (start > carousel.options.size)
						{
							start =1;
						}
					}
					jRun = gotoRun-1;
	//console.log('going to row : '+start)
					carousel.scroll(start)
					
				})
				
				
				
				if (i == 0)
				{
					a.addClass('active');
				}
//				console.log($('#gallery-dots').length);
				$('#gallery-dots').append(li);
			}
			
			
			
//			console.log(Math.floor(carousel.options.size / carousel.options.scroll)
		}
		
		
		$("#clearnace_gallery").jcarousel({
			auto: 8 // delay - seconds
			,initCallback: mycarousel_initCallback
			,itemLoadCallback: itemLoadCallbackFunction

			,wrap: "circular"
				,animation : 1000
					,rtl: false
					,easing: "easeInOutQuad"
	                                ,scroll:3 // items per scroll
		});
		
		
		
		
	$('#ship_select').change(function(){
		var price = $('#tot_price').val();
		var ship = $(this).val();
		var set = parseFloat(price) + parseFloat(ship);
		set.toFixed(2);
		$('#set_total').html(set);
		
		
		
	});
	$('a.product_view').fancybox(
			{
	        		'autoDimensions'	: true,
				'width'         		: 934,
				'height'        		: 423,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'padding'       :0,
				 
				'showCloseButton' :true,
				onComplete : function(){ $('img.product_small_img').click(function(){

				    var Src = $(this).attr('src');
				    $('#product_big_image').attr('src', Src);
				});
				}
				 
			}
		);
	
	
	$('a.edit-product').fancybox(
			{
        		'autoDimensions'	: true,
			'width'         		: 934,
			'height'        		: 423,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'padding'       :0,
			 
			'showCloseButton' :true,
			onComplete : function(){$('img.product_small_img').click(function(){

			    var Src = $(this).attr('src');
			    $('#product_big_image').attr('src', Src);
			});
			}
			 
		}
	);
	
	
	$('.select-size').live('change',function(){
		var id = $(this).val();
		var ajaxUrl = WWW_ROOT + 'catalog/prices/' + id;
		$.post(ajaxUrl,{'id': id},function(data){
			
			data = $.trim(data);
			 var currentPrice = parseFloat(data,10).toFixed(2);
			 $('.price-value').html('₪'+currentPrice);
			 $('.hidPrice').val(currentPrice);
			
		});
		
	});
	$('.paypal').click(function(e){
	
	if(!$('#terms').attr('checked'))
	{
		alert("יש לאשר את קריאת התקנון");
		e.preventDefault();
		
	}
	
});
	
	
	$('.dtl_btn').live('click',function(e){
		
		e.preventDefault();
		$('.product-img').hide();
		$('.tumb').hide();
		$('.dtl_form').show();
		
	});
	$('#contact-form').live('submit',function(){
		var actionUrl = $(this).attr('action');
		$.ajax({
			type		: "POST",
			cache	: false,
			url		: actionUrl,
			data		: $(this).serializeArray(),
			success: function(data) {
				
				if (data == 'ok')
				{
					
					$('.contact-form').hide();
					$('.v-tk').show();
					
				}	
				else
				{
					$.fancybox(data);
					$('.product-img').hide();
					$('.dtl_form').show();
				}
			}
		});
		return false;
		
		
		
	});
$('.cart_form').live('submit',function(){
		
		var actionUrl = $(this).attr('action');
		
		$.fancybox.showActivity();
		

		$.ajax({
			type		: "POST",
			cache	: false,
			url		: actionUrl,
			data		: $(this).serializeArray(),
			success: function(data) {
				
				if (data == 'ok')
				{
					
					window.location.href=WWW_ROOT+'pages/index?add=true';
					
				}	
				else
				{
					$.fancybox(data);
				}
			}
		});
		return false;

	});
	
	
$('.send_news').click(function(e){
		
		e.preventDefault();
		
		var ajaxUrl = $(this).closest('form').attr('action');
		
		var newsletter = $('#news').val();
		$.post(ajaxUrl,{'newsletter': newsletter},function(data){
			
			data = $.trim(data);
			
			if (data == 'ok')
			{
				$('#newslatter').hide();
				$('#thanks').show();
				
			}
			
		});
		
	});
	



	$('.open').click(function( ){
	 
	 var className = $('#footer').attr('class');
	 if(className=='closed')
	{
	 $("#footer").animate({"height": "167px"}, "slow");
	 $("#footer").removeClass().addClass('big');
	 var color = $('.open').css("background-position", "bottom");

	}
	 if(className=='big')
	{
		 $("#footer").animate({"height": "42px"}, "slow");
		 $("#footer").removeClass().addClass('closed');
		 var color = $('.open').css("background-position", "top");
	}
	 
	
	});

	$('a#login-link').fancybox(
			{
	        		'autoDimensions'	: false,
				'width'         		: 250,
				'height'        		: 'auto',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			}
		);
	$('#submit-login').live('click',function(){
		$('#quick-login-form').submit();
	});
	$('#quick-login-form').live('submit',function(){
		
		var actionUrl = $(this).attr('action');
		$.fancybox.showActivity();
		

		$.ajax({
			type		: "POST",
			cache	: false,
			url		: actionUrl,
			data		: $(this).serializeArray(),
			success: function(data) {
				
				if (data == 'ok')
				{
					window.location.reload();
				}	
				else
				{
					$.fancybox(data);
				}
			}
		});
		return false;

	});
	
	
	 
	
	
	

	
	
	
	
});
