
/*
	Easy plugin to get element index position
	Author: Peerapong Pulpipatnan
	http://themeforest.net/user/peerapong
*/

var $j = jQuery.noConflict();

$j.fn.getIndex = function(){
	var $jp=$j(this).parent().children();
    return $jp.index(this);
}

$j.fn.setNav = function(){
	jQuery('.nav li ul').css({display: 'none'});

	jQuery('.nav li').each(function()
	{	
		
		var $jsublist = jQuery(this).find('ul:first');
		
		jQuery(this).hover(function()
		{	
			$jsublist.stop().css({overflow:'hidden', height:'auto', display:'none'}).slideDown(200, function()
			{
				jQuery(this).css({overflow:'visible', height:'auto', display: 'block'});
			});	
		},
		function()
		{	
			$jsublist.stop().slideUp(200, function()
			{	
				jQuery(this).css({overflow:'hidden', display:'none'});
			});
		});	
		
	});
	
	jQuery('.nav li').each(function()
	{
		
		jQuery(this).hover(function()
		{	
			jQuery(this).find('a:first').addClass('hover');
		},
		function()
		{	
			jQuery(this).find('a:first').removeClass('hover');
		});	
		
	});
	
	jQuery('.main_nav li ul').css({display: 'none'});

	jQuery('.main_nav li').each(function()
	{	
		
		var $jsublist = jQuery(this).find('ul:first');
		
		jQuery(this).hover(function()
		{	
			$jsublist.stop().css({overflow:'hidden', height:'auto', display:'none'}).slideDown(200, function()
			{
				jQuery(this).css({overflow:'visible', height:'auto', display: 'block'});
			});	
		},
		function()
		{	
			$jsublist.stop().slideUp(200, function()
			{	
				jQuery(this).css({overflow:'hidden', display:'none'});
			});
		});	
		
	});
	
	jQuery('.main_nav li').each(function()
	{
		
		jQuery(this).hover(function()
		{	
			jQuery(this).find('a:first').addClass('hover');
		},
		function()
		{	
			jQuery(this).find('a:first').removeClass('hover');
		});	
		
	});
	
}

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"
    	    });
    	    
    });

$j(document).ready(function(){ 

	$j(document).setNav();
	
	$j('.img_frame').fancybox({ 
		padding: 10,
		overlayColor: '#000',
		transitionIn: 'elastic',
		transitionOut: 'elastic',
		overlayOpacity: .8
	});
	
	
	
	$j.validator.setDefaults({
		submitHandler: function() { 
		    var actionUrl = $j('#contact_form').attr('action');
		    $j.ajax({
  		    	type: 'POST',
  		    	url: actionUrl,
  		    	data: $j('#contact_form').serialize(),
  		    	success: function(msg){
					$j('#contact_form').hide();
  		    		$j('#reponse_msg').html(msg);
  		    	}
		    });
		    
		    return false;
		}
	});
		    
		
	$j('#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;
		$j('div').each(function() {
			$j(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});

		$j('#thumbNav').css('zIndex', 1000);
		$j('#thumbLeftNav').css('zIndex', 1000);
		$j('#thumbRightNav').css('zIndex', 1000);
		$j('#fancybox-wrap').css('zIndex', 1001);
		$j('#fancybox-overlay').css('zIndex', 1000);
	}
	
	$j(".accordion").accordion({ collapsible: true });
	
	$j(".accordion_close").find('.ui-accordion-header a').click();
	
	$j(".tabs").tabs();
	
	$j('.thumb li a').tipsy();
	
	$j('.social_media li a').tipsy();
	
	$j('#nivo_slider').nivoSlider({ pauseTime: parseInt($j('#slider_timer').val() * 1000), pauseOnHover: true, effect: $j('#pp_homepage_slider_trans').val(), controlNav: true, captionOpacity: 1, directionNavHide: false, controlNavThumbs:true, controlNavThumbsFromRel:true });
	
	jQuery('#nivo_slider').hover(function()
	{	
	    $j(this).find('.nivo-controlNav').fadeIn();
	},
	function()
	{	
	    $j(this).find('.nivo-controlNav').fadeOut();
	});
	
	var footerLi = 0;
	jQuery('#footer .sidebar_widget li.widget').each(function()
	{
		footerLi++;
		
		if(footerLi%4 == 0)
		{ 
			$j(this).addClass('widget-four');
		}
	});
	
	$j('input[title!=""]').hint();
	
	$j('textarea[title!=""]').hint();
	
	$j('#main_menu.main_nav').append('<li><a>&nbsp;</a></li>');
	
	$j('#content_wrapper > .widgettitle').each(function()
	{	
		var titleText = $j(this).html();
		$j(this).html('<span>'+titleText+'</span>');
	});
	
	$j('.sidebar_wrapper > .sidebar > .content > .sidebar_widget > li > .widgettitle').each(function()
	{	
		var titleText = $j(this).html();
		$j(this).html('<span>'+titleText+'</span>');
	});
	
	$j('h1').each(function()
	{	
		var titleText = $j(this).html();
		$j(this).html('<span>'+titleText+'</span>');
	});
	
	$j('h5').each(function()
	{	
		var titleText = $j(this).html();
		$j(this).html('<span>'+titleText+'</span>');
	});
	
	/*VideoJS.setupAllWhenReady({
      controlsBelow: false, // Display control bar below video instead of in front of
      controlsHiding: true, // Hide controls when mouse is not over the video
      defaultVolume: 0.85, // Will be overridden by user's last volume if available
      flashVersion: 9, // Required flash version for fallback
      linksHiding: true // Hide download links when video is supported
    });*/

});
