// created by khalilyabi.com
$(function(){
	// logo hover 
	$("#logo").hover(function(){
		$(this).attr("src","images/logo_ticor.png");
	},function(){
		$(this).attr("src","images/logo_ticor_off.png");
	});
	
	// start sub menu
	$("#product_menu li ").hover(
	  function(){
		$(this).find("a").css('background-color',"#141212");
		var widthSubMenu=0;
		$(this).find(".sub_menu_container li .box").each(function(i, e){	
		widthSubMenu+=$(e).outerWidth(true);
		});
		
		$(this).find(".sub_menu_container ul").css('width',widthSubMenu);
		widthSubMenu=0;	
		
		$(this).find(".sub_menu_container").css('visibility','visible');
		
	  },
	  function(){
		$(this).find("a").css('background-color',"transparent");
		$(this).find(".sub_menu_container").css( 'visibility','hidden');
	  }
	);
	//end sub menu 
	
	//slideshow
	
	if($('#banner').find("#slideshow").length>0){
		$("#slideshow").cycle({
					fx: 'fade',
					timeout: 4500,
					cleartype:1,
					pager:'#nav_slider',
					pagerEvent: 'click',
					pauseOnPagerHover: false,
					pagerAnchorBuilder: function(index, el) {
						return "<a href=''><img src='images/vslider_img_small_"+(index+1)+".jpg' width='86' height='68' border='0' /></a>";
					} 
				  });
	}
	//end slideshow
	
	// validation contact form
 if($('#contact_form').length!=0){
	$.validator.addMethod("phoneUS",
            function(phone_number, element)
            {
                phone_number = phone_number.replace(/\s+/g, ""); 
                return this.optional(element) || phone_number.length > 9 &&
                    phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
            },
            "Please specify a valid phone number");
	
	$("#contact_form").validate({
		rules: {
			contact: { required: true ,minlength: 2 },
			email: { required:true,email:true},
			message:{required:true,minlength: 30},
			phone:{ required:true,phoneUS: true }
    	},
    	messages: {
			contact:{ required:"<small style='color:red'>Name (required)</small>",
				   	  minlength :"<small style='color:red'>Your name is not long enough.</small>" 
				    },
			email:{ required:"<small style='color:red'>Mail (required)</small>",
					email:"<small style='color:red'>Please enter a correct email</small>"
				  },
			phone:{	required:"<small style='color:red'>Phone Number (required)</small>",
					phoneUS:"<small style='color:red'>Please enter a correct format (US Format)</small>"
				  },
			message:{ required:"<small style='color:red'>Comment (required)</small>",
					  minlength :"<small style='color:red'>Your message is not long enough.</small>"
					}
    	} 
		
	});	
	$("#contact_form").submit(function (){
		if($("#contact_form").valid()){
		var	contact=$('#contact').attr('value');
		var	company=$('#company').attr('value');
		var email=$('#email').attr('value');
		var phone=$('#phone').attr('value');
		var model_num=$('#model_num').attr('value');
		var message=$('#message').attr('value');
			$.ajax({  
				type: "POST",  
				 url: "php/sendmail.php",  
				data: "contact="+contact+"&company="+company+"&email="+email+"&phone="+phone+"&model_num="+model_num+"&message="+message,  
				 success: function(){ 
				 	 $('#contact_form').hide('slow').after('<p>Message has been sent.</br></br></br><a href="contact.html" style="color:green">Send an other message</a></p>'); 
					   
				 }  
			 });  
		}								
		
		return false;
	});
	
	

 }
});
