
$(document).ready(function(){
		  
		 
		  $('.contact_submit').click(function(event)
		  {

			  var contact_name_val = 	$("#" + $(this).attr("id") + "_name" ).val();
			  var contact_phone_val = 	$("#" + $(this).attr("id") + "_phone" ).val();
			  var contact_email_val = 	$("#" + $(this).attr("id") + "_email" ).val();
			  var contact_message_val = $("#" + $(this).attr("id") + "_message" ).val();
			  var csrf_token_val = 		$("#" + $(this).attr("id") + "__csrf_token").val();
			  var product_id_val = $("#" + $(this).attr("id") + "_product_id").val();
			  
			  var id = $(this).attr("id");
			  $('#' + id + '_loader').show();
			  $('.contact_submit').hide();

			  $("#msges_" + $(this).attr("id") ).load(
		        $(this).parents('form').attr('action'),
		        { "param[product_id]" : product_id_val, "param[_csrf_token]" : csrf_token_val , "param[name]" : contact_name_val, "param[phone]" : contact_phone_val, "param[email]" : contact_email_val, "param[message]" : contact_message_val },
		        function() { 
		        	$('#' + id + '_loader').hide();
		        	$('.contact_submit').show();
		        }
		      );

		      return false;
		  });
});


$(document).ready(function(){
	

	
	
	//select all the a tag with name equal to modal   
	$('[name=modal]').click(function(e) {   
	//Cancel the link behavior   
	e.preventDefault();   
	
	
	// put product message into dialog form
	$('#product_message').html( $('#prduct_message_' + $(this).attr('title') ).text() );
	$('#msges_product').text('');

	
	var id = '#dialog';

	
	$('#product_product_id').val($(this).attr('title'));
	
	//Get the screen height and width   
	var maskHeight = $(document).height();   
	var maskWidth = $(window).width();   

	//Set height and width to mask to fill up the whole screen   
	$('#mask').css({'width':maskWidth,'height':maskHeight});   
	   
	//transition effect        
	$('#mask').fadeIn(0);         

	//scrollWindow to element
	//$.scrollTo( $('#scrolltome'), 0 );
	
	
	//Get the window height and width
	
	//var height = $(window).height();
	//var scrollTop = $(window).scrollTop();	
	//var winH = height + (scrollTop * 2);
	//$(id).css('top',  winH/2-$(id).height()/2);
	var winH = $(document).height() - $(id).height() - 80;
	$(id).css( 'top',  winH );
	$.scrollTo( winH );
	
	
	
	var winW = $(window).width();
	var href = $(this).attr('href');
	
	// Arabic language need different position.
	// we are going to use a HTML elementu to make a difference, 
	// which language is currently selected
	$landEl = $('div.col');
	
	if( href == '#1' ) {
		// this is the condition
		if ($landEl.css('float') == 'right')
			$(id).css('left', winW/2-$(id).width() - 12);
		else
			$(id).css('left', winW/2 + 12);
	}else{
		// this is another condition
		if ($landEl.css('float') == 'right')
			$(id).css('left', winW/2 + 12);
		else
			$(id).css('left', winW/2-$(id).width() - 12);
	}
	
	   
	   

	//transition effect   
	$(id).fadeIn(0);    

	});   

	//if close button is clicked   
	$('.window .close').click(function (e) {   
	//Cancel the link behavior   
	e.preventDefault();   
	$('#mask, .window').hide();   
	});        

	//if mask is clicked   
	$('#mask').click(function () {   
	$(this).hide();   
	$('.window').hide();   
	});            
	
	/* Show-hide contact */
	$("#show-contact").click(function(){
	
		$("#contact-ctn").removeClass("hidden");
		$("#contact-btn").addClass("hidden");
		
	});
	
	
	$(".contact-btn").click(function(){
		
		$("#contact-ctn").removeClass("hidden");
		$("#contact-btn").addClass("hidden");
		
	});
	
	
	$("#hide-contact").click(function(){
	
		$("#contact-ctn").addClass("hidden");
		$("#contact-btn").removeClass("hidden");
		
	});
	
	/* Slider */
	
	$("#slider").easySlider({
		auto: false,
		continuous: true,
		nextId: "slider1next",
		prevId: "slider1prev"
	});
	
});