/*
 *  Javascripts  
 *
 *	carreonphotography.com
 *
 *  Ed Carreon - Los Angeles Photographer
 *
 *  Written by Ronan Donniou for carreonphotography.com
 *  copyright (c) Ed Carreon 2011
 *
 *  Written for Jquery 1.7+
 *
 *  Requires plugins : 
 *		Galleria-1.2.5+  => http://galleria.aino.se/
 *		jquery.scrollTo-1.3.3.js, jquery.serialScroll-1.2.1.js, jquery.localscroll-1.2.5.js => http://flesler.blogspot.com
 *		Qtip 2+ => http://craigsworks.com/projects/qtip2/
 *		bxslider => http://bxslider.com/ 
 *		coda-slider => ?
 */


$(document).ready(function () {

/* MENU */
    $("#mainmenu li").hover(function(){
        $(this).addClass("hover");
        $('ul:first',this).stop(true,true).slideDown('fast');
    }, function(){
       $(this).removeClass("hover");
        $('ul:first',this).stop(true,true).slideUp('fast');
    });


/* GALLERIES */
	if( $('body').hasClass('gall') )// only for pages with gallery
	{
		// Load the theme
		Galleria.loadTheme('./scripts/galleria.classic.js');
	
		// Initialize Galleria
		$('#galleria').galleria({
						'carousel':false,
						'thumbnails' : 'empty',
						'thumbCrop': true,
						'showCounter':true,
						'idleMode':false,
						'thumbQuality':false,
						'clicknext':false,
						'autoplay': 10000
						});
		// not using default behabvior => no scroll
		// All thumbs to be visible, we need to resize all wrappers	
		Galleria.ready( function(){
				nbr_img = $('#galleria').find('img').size();
//				nbr_line = Math.floor(nbr_img/28); /* 28 imagse per row */
//				y = $('.galleria-thumbnails').find('.active').height();
//				y = (nbr_line+1) * 37; /* 30 (img) + 1+1 (borders) + 5 (margin-top) */
//				$('.galleria-thumbnails').css({'height':y+'px','overflow-y':'visible'});
				z = $('#galleria').height();
				t = z+30; //+y+37
				// wrappers
				$('.galleria-container').height(t);
				$('#galleria').height(t);
				$('#galleria-wrp').height(t); /* prevents bottom content to slide up. Has min-height */
				g_name = $('#gal_title').text();
				$newdiv1 = $('<span class="galleria-ttl"/>').html(g_name+"&nbsp;");
				$newdiv2 = $('<span style="last-sep"/>').html("&nbsp;");
				$('.galleria-counter').prepend($newdiv1).append($newdiv2);
				ww = $('.galleria-counter').outerWidth();
				$('.galleria-thumbnails-container').css({'left':ww+'px'});
			});
	} // only gallery




/* HOME SLIDER */
	if( $('body').hasClass('home') )
	{
		// Image fade slider on Home
        $('#PhotoSlide').bxSlider({
			mode:'fade',
			controls : false,
			speed:1000,
			pause:3000,
			auto:true,
			autoHover:true
		});
	}


/* RESOURCES */
	if( $('body').hasClass('resource') )
	{
		$('h4 a').click(function(event){
				event.preventDefault();
				if( !( $(this).hasClass('active') ) )
				{
					$("a.active").removeClass('active').parents('h4').next('ul').slideUp('fast');
					$(this).parents('h4').next('ul').slideDown('fast');
					$(this).addClass('active');
				}
			});
	}
	
	
/* CLIENTS */
	if( $('body').hasClass('clientsp') )
	{
		$('.client-list a').each(function() {

				$(this).click(function(event){event.preventDefault();return false;});

				var src = $(this).attr('href');
				$(this).qtip({
					  content: {
						text: 'loading',
						ajax:{
						  url: './photos/client_pictures/qtp.html',
						  data: { pic: src },
						  method: 'get',
						  dataType: 'json',
						  success: function(data, status){
							 ipath = '<img src="photos/client_pictures/'+data.image.fname+'" alt=""/>';
							 this.set('content.text', ipath );
							 this.set('style.width', data.image.fw+'px');
							}
						  }
					   },
					   
					  show: 'mouseover',
					  hide: 'mouseout',
					  position: {
						  viewport: $(window),
						   effect: false
					   }
				});
		});
	}
	
	
	
/* CONTACT */
	if( $('body').attr('id') == 'page_contact'  )
	{
		$('#submit').click(function(event){
				//	event.preventDefault();
					$('#ContactFormItm').find('.error').fadeOut();
					var e=0;
					if(	$.trim( $('#Fname').attr("value") )	==""	){e=1;$('#Fname').parents('p').find('.error').fadeIn();	}
					if(	$.trim( $('#Namec').attr("value") )	==""	){e=1;$('#Namec').parents('p').find('.error').fadeIn();	}
					if(	$.trim( $('#Message').attr("value") )	==""	){e=1;$('#Message').parents('p').find('.error').fadeIn();	}
					if($('#Email').attr("value")==""){e=1; $('#Email').parents('p').find('.error').fadeIn(); 
					}else{
							TheEmail=$('#Email').attr("value");
							var EmailRE=/^[a-z0-9._-]+@+[a-z0-9._-]+\.+[a-z]{2,4}$/i;
							if(!EmailRE.test(TheEmail)){e=1; $('#Email').parents('p').find('.error').fadeIn();}
					}
					if ( e == 1 ){ return false; }else{$('#ContactFormItm').submit();}
		 });
	}

	
});

