/*
	Easy plugin to get element index position
	Author: Peerapong Pulpipatnan
	http://themeforest.net/user/peerapong
*/

$.fn.getIndex = function(){
	var $p=$(this).parent().children();
    return $p.index(this);
}

$.fn.setNav = function(){
	jQuery('#main_menu li ul').css({display: 'none'});

	$('#main_menu li:not(.current_page_item) a').not( 'ul li ul li a' ).each(function()
	{	
		$(this).hover(function()
		{	
			$(this).addClass('hover');
			$(this).animate({left: 5}, 200);
		},
		function()
		{	
			$(this).removeClass('hover');
			$(this).animate({left: 0}, 200);
		});	
		
	});
	
	$('#main_menu li ul li:not(.current-menu-item)').each(function()
	{	
		
		$(this).hover(function()
		{	
			$(this).find('a:first').addClass('hover');
			$(this).find('a:first').animate({left: 5}, 200);
		},
		function()
		{	
			$(this).find('a:first').removeClass('hover');
			$(this).find('a:first').animate({left: 0}, 200);
		});
		
	});
	
	$( 'ul#main_menu > li:has( ul li.current-menu-item )' ).each(function()
	{	
     	$(this).find('ul.sub-menu').css({overflow:'visible', height:'auto', display: 'block'});
	});
	
	$('ul#main_menu > li:has( ul.sub-menu )').click(function()
	{
		var $sublist = jQuery(this).find('ul:first');
		$sublist.slideToggle('fast');
		
		return false;
	});
	
	$('ul#main_menu > li > ul.sub-menu li ').click(function()
	{
		var subURL = $(this).find('a:first').attr('href');
		location.href=subURL;
		return true;
	});
}

$(document).ready(function() {
	$(document).setNav();
	
	Cufon.replace('h1.cufon');
	Cufon.replace('h2.cufon');
	Cufon.replace('h2.quote');
	Cufon.replace('h2.widgettitle');
	Cufon.replace('h3.cufon');
	Cufon.replace('h4.cufon');
	Cufon.replace('h5.cufon');
	Cufon.replace('.dropcap1');
	Cufon.replace('#menu_wrapper .menu-main-menu-container .nav li a');
	Cufon.replace('#menu_wrapper .nav ul li a');
})

jQuery(function () {

    	jQuery('.slideshow').anythingSlider({
    	        easing: "easeInOutExpo",
    	        autoPlay: false,
    	        startStopped: false,
    	        animationTime: 600,
    	        hashTags: true,
    	        buildNavigation: true,
    	        buildArrows: false,
    			pauseOnHover: true,
    			startText: "Go",
    	        stopText: "Stop"
    	    });
    	    
    });

$(document).ready(function(){ 
	
	$('.img_frame').fancybox({ 
		padding: 10,
		overlayColor: '#000',
		overlayOpacity: .8
	});
	
	$('.pp_gallery a').fancybox({ 
		padding: 0,
		overlayColor: '#000', 
		overlayOpacity: .8
	});
	
	$.validator.setDefaults({
		submitHandler: function() { 
		    var actionUrl = $('#contact_form').attr('action');
		    
		    $.ajax({
  		    	type: 'POST',
  		    	url: actionUrl,
  		    	data: $('#contact_form').serialize(),
  		    	success: function(msg){
  		    		$('#contact_form').hide();
  		    		$('#reponse_msg').html(msg);
  		    	}
		    });
		    
		    return false;
		}
	});
		    
		
	$('#contact_form').validate({
		rules: {
		    your_name: "required",
		    email: {
		    	required: true,
		    	email: true
		    },
		    message: "required"
		},
		messages: {
		    your_name: "Please enter your name",
		    email: "Please enter a valid email address",
		    agree: "Please enter some message"
		}
	});	
	
	if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 8)
	{
		var zIndexNumber = 1000;
		$('div').each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});

		$('#thumbNav').css('zIndex', 1000);
		$('#thumbLeftNav').css('zIndex', 1000);
		$('#thumbRightNav').css('zIndex', 1000);
		$('#fancybox-wrap').css('zIndex', 1001);
		$('#fancybox-overlay').css('zIndex', 1000);
	}
	
	$('#nivo_slider').nivoSlider({ pauseTime: parseInt($('#slider_timer').val() * 1000), pauseOnHover: true, effect: 'fade', controlNav: true, captionOpacity: 1, directionNavHide: false });
	
  	jQuery('#nivo_slider').hover(function()
	{	
	    $(this).find('.nivo-controlNav').fadeIn();
	},
	function()
	{	
	    $(this).find('.nivo-controlNav').fadeOut();
	});

});
