/*************************** Alternative Post Styling ***************************/

jQuery(document).ready(function(){
	jQuery(".post-container:nth-child(odd)").addClass('odd');
});


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


/*************************** Post Display ***************************/

function gp_post_display() {
	
	jQuery(document).ready(function(){
	
		jQuery(".post-display-small").click(function() {
			jQuery(".post-display-small").addClass("active");
			jQuery(".post-display-large").removeClass("active");	
			jQuery(".post-container").fadeOut("fast", function() {
				jQuery(this).fadeIn("fast").addClass("post-small");
				jQuery(this).fadeIn("fast").removeClass("post-large");
				jQuery.cookie("display_cookie", "post_small");
			});
		});
	
	
		jQuery(".post-display-large").click(function() {
			jQuery(".post-display-large").addClass("active");
			jQuery(".post-display-small").removeClass("active");
			jQuery(".post-container").fadeOut("fast", function() {
				jQuery(this).fadeIn("fast").addClass("post-large");
				jQuery(this).fadeIn("fast").removeClass("post-small");
				jQuery.cookie("display_cookie", "post_large");
			});
		});
			
	});

}

gp_post_display();


/*************************** Gallery Shortcode Lightbox Support ***************************/

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});

});


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

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

gp_lightbox();


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

function gp_image_hover() {
	
	jQuery(document).ready(function(){
	
		jQuery('.overlay, div.gallery-item .gallery-icon').hover(
			function() {
				jQuery(this).find('.hover-image, .hover-video').stop().fadeTo(750, 1);
			},
			function() {
				jQuery(this).find('.hover-image, .hover-video').stop().fadeTo(750, 0);			
			}
		);
	
	});
		
}

gp_image_hover();


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

});
