//home page slider
	$(document).ready(function(){
		$('#slider_area').cycle({ 
			fx:     'fade', 
			easing: 'backout', 
			timeout: 5110, 
			pager:  '#numbers', 
			cleartype:  1,
			pagerAnchorBuilder: function(idx) { 
				return '<li><a href="#" title="">&nbsp; s</a></li>'; 
			} 
		});
	});

//cufon fonts
	$(document).ready(function(){
		Cufon.replace('h1,h2,h3,h4,h5,h6', {hover: true});
	});

//navigation
	$(document).ready(function(){
			ddsmoothmenu.init({
				mainmenuid: "dropdown_menu", //menu DIV id
				orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
				classname: 'dropdown', //class added to menu's outer DIV
				//customtheme: ["#1c5a80", "#18374a"],
				contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
			})
 	});

//image effects 
	$(document).ready(function(){
			var image_e= $(".image.portfolio, .image.product_image");
			image_e.mouseover(function(){$(this).stop().animate({ opacity:0.6
					}, 400);
			}).mouseout(function(){
				image_e.stop().animate({ 
					opacity:1
					}, 400 );
			});
	});

//pretty photo
	$(document).ready(function(){
		$("a[rel^='prettyPhoto']").prettyPhoto();
	});

//product tabs
	$(document).ready(function(){
			var tabs= $("#tabs ul li");
			var content = $("#tabs #content");
			var kids = content.children();
			kids.attr("style","display:none;");
			$("#tabs #content div:first").attr("style","display:block;");
			tabs.click(
				function(){
						var show=$(this).attr("title");
						//change clicked tab class
						$("#tabs ul li").removeClass("active");
						$(this).addClass("active");
						//view clicked tab content
						kids.attr("style","display:none;");
						content.slideUp(100);
					$(function(){
							content.slideDown(400);
							$("#"+show+"").attr("style","display:block;");
					});
				}
			);
	});

//validate contact form
	  $(document).ready(function(){
								 
			$("#validate_form").submit(function(e){
				e.preventDefault();
				e.stopPropagation();												
			});								 
								 
		  jQuery.validator.messages.required = "";
			$("#validate_form").validate({
				 submitHandler: function(form) {
					$('#btnSubmitForm').hide();
					$('#form_processing').html('Wysyłanie wiadomości...');
					
						$.ajax({
						  url: '/?module=contact&action=submit',
						  data: $("#validate_form").serialize(),
						  type: "POST",
						  success: function(data) {
							$('#contact_form').slideUp('slow',function(){
								$('#contact_form').html('Wiadomość została wysłana.');
								$('#contact_form').slideDown('slow');		
							});
							
							
							
						  }
						});

					
				 }
										 
			});
	  });
	  
	  
	  
$.fn.delay = function( time, name ) {

    return this.queue( ( name || "fx" ), function() {
        var self = this;
        setTimeout(function() { $.dequeue(self); } , time );
    } );

};


$.metadata.setType("attr", "validate");
	  
//product page handler 
jQuery(function(){
				
	$("#quantity").numeric();		
	
	$('#quantity').focus(function(e){
		updatePrice();
	});
	
	$('#quantity').blur(function(e){
		updatePrice();
	});	
	
	$('#quantity').keyup(function(e){
		updatePrice();
	});	
				
	$('#btn_order').click(function(e){
		e.preventDefault();
		e.stopPropagation();
		if($("#order_form").validate().element("#quantity")==false){
			$('#error_messages').html('Podana wartość jest niepoprawna.').fadeIn().delay(2000).fadeOut();
		}
		$("#order_form").submit();	
	});		
	
	
	$('#btn_notify').click(function(e){
		e.preventDefault();
		e.stopPropagation();
		is_valid = true;
		if($("#notify_form").validate().element("#notify_email")==false){
			is_valid = false;
			$('#error_messages').html('Adres email jest wymagany.').fadeIn().delay(2000).fadeOut();
		}
		else if($("#notify_form").validate().element("#notify_legal")==false){
			is_valid = false;
			$('#error_messages').html('Należy wyrazić zgodę na przetwarzanie danych.').fadeIn().delay(2000).fadeOut();
		}	
		
		if(is_valid ){
			$.ajax({
			  url: '/?module=notify&action=save',
			  data: $("#notify_form").serialize(),
			  type: "POST",
			  success: function(data) {
				$('#notify_container').slideUp('slow',function(){
					$('#notify_container').html('Twoje dane zostały zapisane.');
					$('#notify_container').slideDown('slow');		
				});
			  }
			});		
		}
		
	});		
	
	
	
	/** prevent default submit **/
	/**
	$("#order_form").submit(function(e){
		e.preventDefault();
		e.stopPropagation();
		alert('a');
	});	
	**/
	
	/** handle show/hide delivery address section **/
	$("input[name='different_delivery_address']").click(function(){
		if($(this).val()==0){
			$('#deliverySection').slideDown();
			$('#deliverySection').find('input').each(function(){
				$(this).addClass('required');
			});
			
		}
		else{
			$('#deliverySection').slideUp();
			$('#deliverySection').find('input').each(function(){
				$(this).removeClass('required');
			});			
		}
	});
	
	
	$("input[name='vat_required']").click(function(){
		if($(this).val()==1){
			$('#vatSection').slideDown();
			$('#vatSection').find('input').each(function(){
				$(this).addClass('required');
			});
			
		}
		else{
			$('#vatSection').slideUp();
			$('#vatSection').find('input').each(function(){
				$(this).removeClass('required');
			});			
		}
	});	
	
				
	 jQuery.validator.messages.required = "";			
	 jQuery.validator.messages.number = "";
     jQuery.validator.messages.email = "Prosimy o podanie poprawnego adresu email.";
	 
	 
	/**
	 * If payment type is set to platnosci.pl then select correct delivery type
	 * 
	 */	
	 $("#pay_type_platnosci").click(function(){	 	
		if($(this).attr('checked')){
			$('#delivery_option_3').attr('checked','checked');
		}
	 });
	 
	 $("#pay_type_cash").click(function(){	 	
		if($(this).attr('checked')){
			$('#delivery_option_2').attr('checked','checked');
		}
	 });	 
	 
	 
	 $("#delivery_option_2").click(function(){	 	
		if($(this).attr('checked')){
			$('#pay_type_cash').attr('checked','checked');
		}
	 });	 
	 
	 $("#delivery_option_3").click(function(){	 	
		if($(this).attr('checked')){
			$('#pay_type_platnosci').attr('checked','checked');
		}
	 });	 
	 
	 $("#delivery_option_4").click(function(){	 	
		if($(this).attr('checked')){
			$('#pay_type_platnosci').attr('checked','checked');
		}
	 });	 	 
	 
	 
		
	/** enable submit button **/
	$('#btn_makeOrder').removeAttr('disabled');
	$("#validate_order_form").validate({});
	
	/** check if form is valid - if yes - then hide submit button **/
	/*	
	$("input[type='submit']").click(function(){
		if($("#validate_order_form").valid()){
			$(this).parent().html('Wysyłanie zamówienia...');
			$('#validate_order_form').submit();
		}
	});
	*/
	
	
	
	
				
});

function updatePrice(){
	if($('#quantity').val()!='' && $('#quantity').val()<1){
		$('#quantity').val('1');
	}
	var order_price = $('#product_price').val()*$('#quantity').val();
	$('#order_price').text(order_price.toFixed(2))
}


