$(document).ready(function() {

 		$.preloadCssImages({ 'imgDir': 'images' });

		$(".dropdown li").hover(function(){
			var dropDown = $(this).children("ul");
			var ulWidth = dropDown.width();
			var liWidth = $(this).width();
			var posLeft = (liWidth - ulWidth)/2 + 10;
			dropDown.css("left",posLeft);		
		});	
		
		$(".dropdown ul").parent("li").addClass("parent");
		$(".dropdown li:first-child").addClass("first");
		$(".dropdown li:last-child").addClass("last");
		$(".dropdown li:only-child").removeClass("last").addClass("only");		

		$("ul.tabs").tabs("> .tabcontent", {
			tabs: 'li', 
			effect: 'fade'
		});
		
	$(".recent_posts li:odd").addClass("odd");
	$(".popular_posts li:odd").addClass("odd");
	$(".widget-container li:even").addClass("even");

// cols
	$(".row .col:first-child").addClass("alpha");
	$(".row .col:last-child").addClass("omega"); 	

// toggle content
	$(".toggle_content").hide(); 
	
	$(".toggle").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});
	
	$(".toggle").click(function(){
		$(this).next(".toggle_content").slideToggle(300,'easeInQuad');
	});
	
	$(".table-price tr:even").addClass("even");

// gallery
	$(".gl_col_2 .gallery-item::nth-child(2n)").addClass("nomargin");
	
// pricing
	$(".table-pricing td.table-row-title:even").addClass("even");

// buttons	
	if (!$.browser.msie) {
		$(".button_styled, .button_link, .btn-submit, .button_large").hover(function(){
			$(this).stop().animate({"opacity": 0.8});
		},function(){
			$(this).stop().animate({"opacity": 1});
		});
	}	

// scroll to anchor	
	$(".topmenu a[href^='#']").click(function(event){
		event.preventDefault();
		
		var full_url = this.href;
		var parts = full_url.split("#");
		var trgt = parts[1];
		
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top - 94;
		
		$('html, body').animate({scrollTop:target_top}, 700);
	});

});

$(function () {  
     $(window).scroll(function () {  
         if ($(this).scrollTop() != 0) {  
             $('.link-top').fadeIn();  
         } else {  
             $('.link-top').fadeOut();  
         }  
     });  
     $('.link-top').click(function () {  
         $('body,html').animate({  
             scrollTop: 0  
         },  
         1500);  
     });  
	
	 // contact us form handler
	$(".btn-submit").click(function() {  
	    // validate and process form here  
		$('label#contact_error').hide();  
		//alert('OK');

	    var name = $("input#name").val();  
		if (name == "" || name == "Name" ) {  
		  $("label#contact_error").html("Please enter your name.");  
		  $('label#contact_error').show();  
		  $("input#name").focus();  
		  return false;  
		}  

	    var email = $("input#email").val();  
		if (email == "" || email == "Email" ) {  
		  $("label#contact_error").html("Please enter your email.");  
		  $('label#contact_error').show();  
		  $("input#email").focus();  
		  return false;  
		}  

	    var subject = $("input#subject").val();  

	    var message = $("textarea#message").val();  
		if (message == "" || message == "Message" ) {  
		  $("label#contact_error").html("Please enter your message.");  
		  $('label#contact_error').show();  
		  $("textarea#message").focus();  
		  return false;  
		}  

		// ajax send message
		var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&message=' + message;  
		//alert (dataString);return false;  
		
		$.ajax({  
		  type: "POST",  
		  url: "/home/contact",  
		  data: dataString,  
		  success: function() {  
			$('#contact_form').html("<div id='message'></div>");  
			$('#message').html("<h2>Thank you!</h2>")  
			.append("<br/><p>Your message has been successfully delivered. We will be in touch soon.</p>");  
		  }  
		});  
		
		return false;  

	});  

 });
 

