//***************************** Menu *****************************//

function mainmenu(){
	jQuery("#nav ul li a").removeAttr("title");
	jQuery("#nav ul a").removeAttr("title");
	jQuery("#nav ul ul ").css({display: "none"}); // Opera Fix
	jQuery("#nav ul li").hover(function(){
		jQuery(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		},function(){
		jQuery(this).find('ul:first').css({visibility: "hidden"});
		});
}
 
jQuery(document).ready(function(){					
	mainmenu();
});


//***************************** Lightbox *****************************//

jQuery(document).ready(function(){

	jQuery("div.gallery-item .gallery-icon a").attr("rel", "prettyPhoto[gallery]");
	
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'facebook'
	});

});


//***************************** Tabs *****************************//

jQuery(document).ready(function(){
	var panelContainer = jQuery('div#panels');
	jQuery('<div id="tabs"></div>').insertBefore(panelContainer);	
	panelContainer.find('div.panel').each(function(n){
		jQuery('div#tabs').append('<a class="tab" href="#' + (n+1) + '">' + jQuery(this).attr('title') + '</a>');
	});
	var panelLocation = location.hash.slice(1);
	if(panelLocation){
		var panelNum = panelLocation;
	}else{
		var panelNum = '1';
	}
	panelContainer.find('div.panel').hide();
	panelContainer.find('div.panel:nth-child(' + panelNum + ')').fadeIn('slow');
	jQuery('div#tabs').find('a.tab:nth-child(' + panelNum + ')').removeClass().addClass('tab-active');
	jQuery('div#tabs').find('a').each(function(n){
		jQuery(this).click(function(){
			panelContainer.find('div.panel').hide();
			panelContainer.find('div.panel:nth-child(' + (n+1) + ')').fadeIn('slow');
			jQuery(this).parent().find('a').removeClass().addClass('tab');
			jQuery(this).removeClass().addClass('tab-active');
		});
	});
});


//***************************** Scrollable Content *****************************//

jQuery(document).ready(function(){

	jQuery("#scrollslider").smoothDivScroll({
		scrollInterval: 16,
		mouseDownSpeedBooster: 1,
		autoScrollDirection: "endlessloopright",
		autoScrollSpeed: 2,
		visibleHotSpots: "always"
	});
	
	jQuery("#scrollportfolio").smoothDivScroll({
		scrollInterval: 16,
		mouseDownSpeedBooster: 1,
		autoScrollDirection: "endlessloopright",
		autoScrollSpeed: 2,
		visibleHotSpots: "always"
	});	
	
});


//***************************** Image Hover Effect *****************************//


jQuery(document).ready(function(){
    jQuery('.slider-thumbnail .meta, .portfolio-thumbnail .meta').css({'opacity':'0'});
	jQuery('.slider-thumbnail, .portfolio-thumbnail').hover(
		function() {
			jQuery(this).find('.meta').stop().fadeTo(500, 0.8);
		},
		function() {
			jQuery(this).find('.meta').stop().fadeTo(500, 0);
		}
	)
});	


//***************************** Thumbnail Slide Up Effect *****************************//

jQuery(document).ready(function(){

	// Slider Captions
	jQuery(".slider-large").hover(function(){
		jQuery(this).find(".caption").animate({top:"-525px"},{queue:false,duration:500});},
		function(){ jQuery(".caption").animate({top:"-650px"},{queue:false,duration:500});
	});
	
	jQuery(".slider-medium").hover(function(){
		jQuery(this).find(".caption").animate({top:"-350px"},{queue:false,duration:500});},
		function(){ jQuery(".caption").animate({top:"-475px"},{queue:false,duration:500});
	});
	
	jQuery(".slider-small").hover(function(){
		jQuery(this).find(".caption").animate({top:"-418px"},{queue:false,duration:500});},
		function(){ jQuery(".caption").animate({top:"-553px"},{queue:false,duration:500});
	});	

	// Slider Thumbnails
	jQuery("#slider-container").hover(function(){			jQuery(this).find("#slider-thumbnails-wrapper").animate({top:"-150px"},{queue:false,duration:500});},
		function(){ jQuery("#slider-thumbnails-wrapper").animate({top:"0px"},{queue:false,duration:500});
	});
	jQuery("#slider-container.slider-small").hover(function(){			jQuery(this).find("#slider-thumbnails-wrapper").animate({top:"-150px"},{queue:false,duration:500});},
		function(){ jQuery("#slider-thumbnails-wrapper").animate({top:"25px"},{queue:false,duration:500});
	});	
		
});


/*************************** Play/Pause Slider ***************************/


jQuery(document).ready(function(){
	
	// Toggle Slider Controls
	jQuery(".rotation").toggle(
		function(){
			jQuery('#slider').cycle('pause'); 
			jQuery(".rotation-button").replaceWith('<span class="rotation-button">&#9658;</span>');
		},
		function () {
			jQuery('#slider').cycle('resume'); 
			jQuery(".rotation-button").replaceWith('<span class="rotation-button pause-button">&#x2590;&#x2590;</span>');
		}
	);	
	
	// Pause Slider When Videos Clicked
	jQuery(".pause").click(function(){
		jQuery('#slider').cycle('pause');
	});	
	
});

/*************************** Image Preloader ***************************/

jQuery(function () {
	jQuery('.preload').hide();
});

var i = 0;
var int=0;
jQuery(window).bind("load", function() {
	var int = setInterval("doThis(i)",50);
});

function doThis() {
	var images = jQuery('.preload').length;
	if (i >= images) {
		clearInterval(int);
	}
	jQuery('.preload:hidden').eq(0).fadeIn(500);
}


/*************************** Contact Form ***************************/

jQuery(document).ready(function(){
	
	jQuery('#contact-form').submit(function() {

		jQuery('.contact-error').remove();
		var hasError = false;
		jQuery('.requiredFieldContact').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				jQuery(this).addClass('input-error');
				hasError = true;
			} else if(jQuery(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
					jQuery(this).addClass('input-error');
					hasError = true;
				}
			}
		});
	
	});
				
	jQuery('#contact-form .contact-submit').click(function() {
		jQuery('.loader').css({display:"block"});
	});	

});


/*************************** Theme Options Panel ***************************/

jQuery(document).ready(function(){
	jQuery(".trigger").click(function(){
		jQuery(".theme-box").toggle("fast");
		jQuery(this).toggleClass("active");
		return false;
	});
});
