/*************************** Display Content ***************************/

jQuery(document).ready(function(){	
	jQuery("#accordion-switcher, .slider-wrapper, .slider").addClass("display");
});


/*************************** List Styling ***************************/

jQuery(document).ready(function(){	
	jQuery("ul li:first-child").addClass("li-first");
	jQuery("ul li:last-child").addClass("li-last");			
});


/*************************** Navigation Menus ***************************/

jQuery(document).ready(function(){	

	var nav = jQuery("#nav");

	nav.find("li").each(function() {
		if (jQuery(this).find("ul").length > 0) {
		
			jQuery("<span/>").html("&#9660;").appendTo(jQuery(this).children(":first"));
			
		}
	});

});


/*************************** Navigation Menu Positioning ***************************/

jQuery(document).ready(function(){
	jQuery("#nav>ul>li").each(function() {
		pos = jQuery(this).offset();
		if(pos.left + 100 > jQuery(window).width()+document.body.scrollLeft-jQuery(this).width()) {
		jQuery(this).addClass("nav-shift");}
	});
});


/*************************** Accordion Slider ***************************/

// Accordion Slider Captions
jQuery(document).ready(function(){	
	
	jQuery(".accordion-slider .panel").hover(
	function() {
		jQuery(this).find(".caption").stop().fadeTo(500, 0.95);
	},
	function() {
		jQuery(this).find(".caption").stop().fadeTo(500, 0);
	});
	
});


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

jQuery(document).ready(function(){

	jQuery("div.gallery-item .gallery-icon a").prepend('<span class="hover-image"></span>');
	jQuery("div.gallery-item .gallery-icon a").attr("rel", "prettyPhoto[gallery]");
	var galleryimgWidth = jQuery("div.gallery-item .gallery-icon img").width();
	var galleryimgHeight = jQuery("div.gallery-item .gallery-icon img").height();
	jQuery("div.gallery-item .gallery-icon .hover-image").css({"width": galleryimgWidth, "height": galleryimgHeight});
	jQuery("div.gallery-item .gallery-icon a").css({"width": galleryimgWidth});

	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'pp_default',
		social_tools: false
	});

});

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

jQuery(document).ready(function(){

	jQuery('.hover-image, .hover-video').css({'opacity':'0'});
	jQuery('.sc-image, .post-thumbnail, .portfolio-thumbnail, .slide, .accordion-slider .panel, div.gallery-item .gallery-icon').hover(
		function() {
			jQuery(this).find('.hover-image, .hover-video').stop().fadeTo(750, 1);
			jQuery(this).find("a[rel^='prettyPhoto'] .image, a[rel^='prettyPhoto'] .slider-image, a[rel^='prettyPhoto'] .accordion-image, a[rel^='prettyPhoto'] .attachment-thumbnail").stop().fadeTo(750, 0.5);
		},
		function() {
			jQuery(this).find('.hover-image, .hover-video').stop().fadeTo(750, 0);
			jQuery(this).find("a[rel^='prettyPhoto'] .image, a[rel^='prettyPhoto'] .slider-image, a[rel^='prettyPhoto'] .accordion-image, a[rel^='prettyPhoto'] .attachment-thumbnail").stop().fadeTo(750, 1);
		})
		
});


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

jQuery(function () {
	jQuery('.preload').hide();//hide all the images on the page
});

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

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


/*************************** Accordion ***************************/

jQuery(document).ready(function(){
	jQuery(".accordion").accordion({ header: "h3.accordion-title", autoHeight: false });
	jQuery("h3.accordion-title").toggle(function(){
		jQuery(this).addClass("active");
		}, function () {
		jQuery(this).removeClass("active");
	});	
});


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

jQuery(document).ready(function(){
	jQuery(".sc-tabs").tabs({
		fx: {
			height:'toggle',
			duration:'fast'
		}
	});	
});


/*************************** Toggle Content ***************************/

jQuery(document).ready(function(){
	jQuery(".toggle-box").hide(); 
	
	jQuery(".toggle").toggle(function(){
		jQuery(this).addClass("toggle-active");
		}, function () {
		jQuery(this).removeClass("toggle-active");
	});
	
	jQuery(".toggle").click(function(){
		jQuery(this).next(".toggle-box").slideToggle();
	});
});


/*************************** Review Panel Width ***************************/

(function(jQuery){
 jQuery.fn.extend({
 
 	customStyle : function(options) {
	  if(!jQuery.browser.msie || (jQuery.browser.msie&&jQuery.browser.version>6)){
	  return this.each(function() {
	  
			var currentSelected = jQuery(this).find(':selected');
			jQuery(this).after('<span class="select-menu"><span class="select-menu-inner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:jQuery(this).next().css('font-size')});
			var selectBoxSpan = jQuery(this).next();
			var selectBoxWidth = parseInt(jQuery(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
			var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			selectBoxSpan.css({display:'inline-block'});
			selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			jQuery(this).height(selectBoxHeight).change(function(){
				// selectBoxSpanInner.text(jQuery(this).val()).parent().addClass('changed');   This was not ideal
			selectBoxSpanInner.text(jQuery(this).find(':selected').text()).parent().addClass('changed');
				// Thanks to Juarez Filho & PaddyMurphy
			});
			
	  });
	  }
	}
 });
})(jQuery);

jQuery(document).ready(function(){
	jQuery('.selection').customStyle();
});


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

});
