
/* Mista.Boos Creative 2010-2011 */

/******************* LOAD WEB *******************/
function web()
{
	/* Fade Div */
	$(".one-web-preview div").stop().fadeTo(1,0);
	$(".one-web-preview div").hover(
		function()
		{
			if ( navigator.appName == "Microsoft Internet Explorer")
			{
				// IE
				$(this).stop().fadeTo(250,.87);
			}
			else
			{
				// Other browsers
				$(this).stop().fadeTo(250,1);
			}
		},
		function()
		{
			$(this).stop().fadeTo(250,0);
		});
}


/******************* LOAD PIX *******************/
function pix()
{
	// FancyBox
	$("a[rel=pix-group]").fancybox({
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'speedIn'			: 400,
		'speedOut'			: 400,
		'changeSpeed'		: 400,
		'changeFade'		: 400,
		'titleShow'	 		: false,
		'overlayColor'		: '#000',
		'overlayOpacity'	: '.70',
		'cyclic'			: true,
		'centerOnScroll'	: true,
		'padding'			: 0,
		'margin'			: 0
		/* 'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>'; 
		return '<div id="fancybox-title-over"><p id="fancybox-title-left">' + (title.length ? '' + title : '') + '</p><p id="fancybox-title-right">' + (currentIndex + 1) + ' / ' + currentArray.length + '</p></p>';
		}*/
	});
	
	// Gallery Hover Effect
	if ( navigator.appName == "Microsoft Internet Explorer")
	{
		// IE : Set background-color to div to disable the color bug
		$(".one-pic").css("background","#142b49");
	}
	$("#pix-wrapper").hover(function(){
								/*$('#pix-list').stop().fadeTo(300,0.25);*/},
						 function(){
								$(".one-pic").stop().fadeTo(300,1);});
   
	$(".one-pic").hover(function(){
								$(this).siblings().stop().fadeTo(300,0.25);
								$(this).fadeTo(150,1);},function(){$(this).stop().fadeTo(150,1);});
	
	// Masonry
	$('#pix-wrapper').masonry({ 
			columnWidth: 160, 
			itemSelector: '.one-pic',
			resizeable: false
			});
	
}


/******************* LOAD CONTACT FORM *******************/
function contact(num)
{
	// Show/Hide Contact
	if (num == null)
	{
		$("#wrap-contact").hide();
		showhide();
	}
	else
	{
		// If Send mail success : Display success message and hide wrap-contact
		showhide();
		$("#success-contact").fadeIn(
				800, 
				function(){ setTimeout(function(){$("#wrap-contact").slideUp(2000); $("#success-contact").fadeOut(500); },2500); });
	}
	
	// Check form
	$("#submit-button").click(function()
	{
		valid = true;
		fadeSpeed = 800;
		bgColorOrigin = "#1b3561";
		bgColorFade = "#a31d1d";
		
		// check name
		if ( $("#name").val() == "" || !$("#name").val().match(/[a-z]+$/i) )
		{
			$("#name").animate({backgroundColor:bgColorFade}, fadeSpeed);
			$("#error-contact").fadeIn(fadeSpeed);
			valid = false;
		}
		else
		{
			$("#name").animate({backgroundColor:bgColorOrigin}, fadeSpeed);
		}
		
		// check email
		if ( $("#email").val() == "" || !$("#email").val().match(/^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,6}$/i) )
		{
			$("#email").animate({backgroundColor:bgColorFade}, fadeSpeed);
			$("#error-contact").fadeIn(fadeSpeed);
			valid = false;
		}
		else
		{
			$("#email").animate({backgroundColor:bgColorOrigin}, fadeSpeed);
		}
		
		// check subject
		if ( $("#subject").val() == "" )
		{
			$("#subject").animate({backgroundColor:bgColorFade}, fadeSpeed);
			$("#error-contact").fadeIn(fadeSpeed);
			valid = false;
		}
		else
		{
			$("#subject").animate({backgroundColor:bgColorOrigin}, fadeSpeed);
		}
		
		// check message
		if ( $("#message").val() == "" )
		{
			$("#message").animate({backgroundColor:bgColorFade}, fadeSpeed);
			$("#error-contact").fadeIn(fadeSpeed);
			valid = false;
		}
		else
		{
			$("#message").animate({backgroundColor:bgColorOrigin}, fadeSpeed);
		}
		
		return valid;
	});	
}


/******************* LOAD SHOW/HIDE FOR CONTACT FORM *******************/
function showhide()
{
	// Show/Hide
	$("#close-contact a, .sayhello").click(function()
	{
		if ($("#wrap-contact").is(":hidden"))
		{
			$("#wrap-contact").slideDown(1000);
		}
		else
		{
			$("#wrap-contact").slideUp(1000);
		}
	});
}
