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

jQuery(document).ready(function(){
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		theme: "facebook"
	});
});


//***************************** 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();
});


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

jQuery(document).ready(function(){
	// We can use this object to reference the panels container
	var panelContainer = jQuery('div#panels');
	// Create a DIV for the tabs and insert it before the panel container
	jQuery('<div id="tabs"></div>').insertBefore(panelContainer);
	
	// Find panel names and create nav
	// -- Loop through each panel
	panelContainer.find('div.panel').each(function(n){
		// For each panel, create a tab
		jQuery('div#tabs').append('<a class="tab" href="#' + (n+1) + '">' + jQuery(this).attr('title') + '</a>');
	});
	
	// Determine which tab should show first based on the URL hash
	var panelLocation = location.hash.slice(1);
	if(panelLocation){
		var panelNum = panelLocation;
	}else{
		var panelNum = '1';
	}
	// Hide all panels
	panelContainer.find('div.panel').hide();
	// Display the initial panel
	panelContainer.find('div.panel:nth-child(' + panelNum + ')').fadeIn('slow');
	// Change the class of the current tab
	jQuery('div#tabs').find('a.tab:nth-child(' + panelNum + ')').removeClass().addClass('tab-active');
	
	// What happens when a tab is clicked
	// -- Loop through each tab
	jQuery('div#tabs').find('a').each(function(n){
		// For each tab, add a 'click' action
		jQuery(this).click(function(){
			// Hide all panels
			panelContainer.find('div.panel').hide();
			// Find the required panel and display it
			panelContainer.find('div.panel:nth-child(' + (n+1) + ')').fadeIn('slow');
			// Give all tabs the 'tab' class
			jQuery(this).parent().find('a').removeClass().addClass('tab');
			// Give the clicked tab the 'tab-active' class
			jQuery(this).removeClass().addClass('tab-active');
		});
	});
});



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

jQuery(function() {
	jQuery("#scrollslider").smoothDivScroll({
	scrollingSpeed: 16,
	mouseDownSpeedBooster: 1,
	autoScroll: "",
	autoScrollDirection: "endlessloop",
	autoScrollSpeed: 2,
	visibleHotSpots: "always",
	startAtElementId: "startslider1"
	});
	jQuery("#scrollportfolio").smoothDivScroll({
	scrollingSpeed: 16,
	mouseDownSpeedBooster: 1,
	autoScroll: "",
	autoScrollDirection: "endlessloop",
	autoScrollSpeed: 2,
	visibleHotSpots: "always",
	startAtElementId: "startportfolio1"
	});		
});


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


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


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

jQuery(document).ready(function(){

	jQuery(function() {
		jQuery("#slider-container-large, #slider-container-medium, #slider-container-small").hover(function(){			jQuery(this).find(".pop_box_lower").animate({top:"-150px"},{queue:false,duration:500});},
			function(){ jQuery(".pop_box_lower").animate({top:"0px"},{queue:false,duration:500});
		});
		
	});

	jQuery(function() {
	
		jQuery("#slider-container-large").hover(function(){
			jQuery(this).find(".pop_box_upper_large").animate({top:"-525px"},{queue:false,duration:500});},
			function(){ jQuery(".pop_box_upper_large").animate({top:"-650px"},{queue:false,duration:500});
		});
		
		jQuery("#slider-container-medium").hover(function(){
			jQuery(this).find(".pop_box_upper_medium").animate({top:"-350px"},{queue:false,duration:500});},
			function(){ jQuery(".pop_box_upper_medium").animate({top:"-475px"},{queue:false,duration:500});
		});
		
		jQuery("#slider-container-small").hover(function(){
			jQuery(this).find(".pop_box_upper_small").animate({top:"-418px"},{queue:false,duration:500});},
			function(){ jQuery(".pop_box_upper_small").animate({top:"-553px"},{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('#contactform').submit(function(){
	
		var action = jQuery(this).attr('action');
		
		jQuery("#message").slideUp(750,function() {
		jQuery('#message').hide();
		
 		jQuery('#submit')
			.after('<div class="loader"> </div>')
			.attr('disabled','disabled');
		
		jQuery.post(action, { 
			name: jQuery('#name').val(),
			email: jQuery('#email').val(),
			subject: jQuery('#subject').val(),
			comment_box: jQuery('#comment_box').val(),
			verify: jQuery('#verify').val()
		},
			function(data){
				document.getElementById('message').innerHTML = data;
				jQuery('#message').slideDown('slow');
				jQuery('#contactform div.loader').fadeOut('slow',function(){jQuery(this).remove()});
				jQuery('#contactform #submit').attr('disabled',''); 
				if(data.match('success') != null) jQuery('#contactform').slideUp('slow');
				
			}
		);
		
		});
		
		return false; 
	
	});
	
});
