
/*
========================================================
============ Forms- Validator and functions ============ 
========================================================

Files Required: None
Forms should be mapped in http://admin.plasticsurgerystudios.com/

-------------------------------------------------- */

// CLEAR FORM FUNCTION

function clearText(thefield) {
if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} function replaceText(thefield) {
if (thefield.value=="") { thefield.value = thefield.defaultValue }
}

// FORM VALIDATOR

function MM_validateForm() { //v4.0
	if (document.getElementById){
		var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
		for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
			if (val) { nm=val.name; if ((val=val.value)!="") {
				if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
				} else if (test!='R') { num = parseFloat(val);
					if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
						min=test.substring(8,p); max=test.substring(p+1);
						if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
		} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
	} if (errors) alert('The following error(s) occurred:\n'+errors);
	document.MM_returnValue = (errors == '');
} }




// :::::::::::::::::::::::::::::::::::::::::::
// Tabbed Sections
// :::::::::::::::::::::::::::::::::::::::::::

(function( $ ){
		  
  $.fn.TabbedSections = function() {
  
  	ts = this;
	tsc = ts.children();
	selected = 'Selected';
	
	tsc.filter(':first').addClass(selected);
	fHref = tsc.filter('.'+selected).attr('href');
	cb = $(fHref).parent();
	
	$(fHref).addClass(selected).animate({
		 left:'0'
		 },1000);
	
	tsc.each(function(){
			$(this).click(function(e){
						e.preventDefault();
						var clicked = $(this);
						var href = clicked.attr('href');
						if($(href).siblings('.'+selected).filter(':animated')){
								$(href).siblings('.'+selected).stop();
							}
						To = setTimeout(function (){
								var w = $(href).outerWidth(true);
								var speed = 1000;
								$(href).siblings('.'+selected).animate({left:(-1*w)},speed).removeClass(selected).end().delay(speed).addClass(selected).animate({left:'0'},speed);
								clicked.siblings('.'+selected).removeClass(selected).end().addClass(selected);
							},0);//Timeout
				   });	  
		  });
	

  };// Tabbed Sections
 

 
 
  $.fn.MenuSlide = function() {
  
  	pm = this;
	pmSL = pm.children('.SectionLinks');
	pmL = pmSL.children('a');
	pmB = $('.pmBack');
	btnToCat = $('.toCat');
	btnNext = $('.nextBtn');
	btnPrev = $('.prevBtn');
	selected = 'Selected';
	CategoryBtns = $('.CategoryBtns');
	ProjectBtns = $('.ProjectsBtns');
	speed = 500;
	pmWidth = pm.outerWidth(true);
	
	pm.filter(':first').css({'right':'0'}).siblings('.ProjectMenus').css({'right':(-1*pmWidth)});
	
			
		
	// Click on Project Menu Link
	pmL.click(function(e){
		e.preventDefault();
		var clicked = $(this);
		var href = clicked.attr('href');
		msTo = setTimeout(function (){
		
			$(href).animate({right:'0'},speed).addClass('Active');
		
		},0);//Timeout
		
		if($('.ProjectMenus.Active').length == 0){
			CategoryBtns.fadeIn(speed);
		}//if
		
		if($('.ProjectMenus.Active').length == 1){
			ProjectBtns.fadeIn(speed);
			$('#flashMovie').css({'display':'none'});
		}//if
		
		if($(this).parent().parent().hasClass('Category')){
			$(this).addClass('Selected');
		}
		
		contentHref = href.replace('#','#content_');
		$(contentHref).fadeIn(speed);
			
	});//Click on Project Menu Link

	
	
	
	// Click on back Link
	pmB.click(function(e){
			e.preventDefault();
		   $(this).parent().parent('.ProjectMenus').animate({right:(-1*pmWidth)},speed).removeClass('Active');
			
			if($('.ProjectMenus.Active').length == 0){
				CategoryBtns.fadeOut(speed);
			}//if
			
			if($('.ProjectMenus.Active').length == 1){
				ProjectBtns.fadeOut(speed);
			}//if
			
			$('.Category .Selected').removeClass('Selected');
			$(contentHref).fadeOut(speed);
			$('#flashMovie').css({'display':'block'});
			
	   });//pmB click
	


	
	// Click on Button which takes you back to categories ::: CLEARS ALL OPEN SCREENS :::
	btnToCat.click(function(e){
			e.preventDefault();
			pm.filter('.Active').animate({right:(-1*pmWidth)},speed).removeClass('Active');
			$('.Category .Selected').removeClass('Selected');
			
			CategoryBtns.fadeOut(speed);
			ProjectBtns.fadeOut(speed);
			$(contentHref).fadeOut(speed);
			$('#flashMovie').css({'display':'block'});
				
	   });//pmB click
	


	
	// Click the for NEXT project
	btnNext.click(function(e){
			e.preventDefault();
			
			//If Projects Menu is open
			if(pm.filter('.Projects.Active').length > 0 && $('.Category.Active a.Selected').next().length > 0){
				var zInd = $('.Projects.Active').css('z-index');
				$('.Projects.Active').css({'z-index': '999'}).children().not(':first').fadeOut(speed,function(){
					$(this).parent().fadeOut(speed,function(){
						$(this).css({'right':(-1*pmWidth)}).show().css({'z-index': zInd }).children().show();
					});
				}).end().end().removeClass('Active');
				
				var newHref = $('.Category a.Selected').next().attr('href');
				$('.Category a.Selected').removeClass('Selected').next().addClass('Selected');
				$(newHref).css({'right': '0'}).delay(speed*2).fadeIn(speed).addClass('Active');

				$(contentHref).fadeOut(speed);

				newContentHref= $('.Projects.Active').attr('id');
				contentHref= '#content_'+newContentHref;
				$(contentHref).delay(speed).fadeIn(speed);
				
			}// if



			//If Projects Menu IS NOT open
			if(pm.filter('.Projects.Active').length == 0 && pm.filter('.Category.Active').next().length > 0){
				var zInd = $('.Category.Active').css('z-index');
				$('.Category.Active').css({'z-index': '999'}).children().not(':first').fadeOut(speed,function(){
					$(this).parent().fadeOut(speed,function(){
						$(this).css({'right':(-1*pmWidth)}).show().css({'z-index': zInd }).children().show();
					});
				}).end().end().removeClass('Active').next().css({'right': '0'}).delay(speed*2).fadeIn(speed).addClass('Active');
			}//if
	
	   });//btn NEXT click
	



	
	// Click the for PREV project
	btnPrev.click(function(e){
			e.preventDefault();

			//If Projects Menu is open
			if(pm.filter('.Projects.Active').length > 0 && $('.Category.Active a.Selected').prev().length > 0){
				var zInd = $('.Projects.Active').css('z-index');
				$('.Projects.Active').css({'z-index': '999'}).children().not(':first').fadeOut(speed,function(){
					$(this).parent().fadeOut(speed,function(){
						$(this).css({'right':(-1*pmWidth)}).show().css({'z-index': zInd }).children().show();
					});
				}).end().end().removeClass('Active');
				
				
				var newHref = $('.Category a.Selected').prev().attr('href');
				$('.Category a.Selected').removeClass('Selected').prev().addClass('Selected');
				$(newHref).css({'right': '0'}).delay(speed*2).fadeIn(speed).addClass('Active');

	
				$(contentHref).fadeOut(speed);

				newContentHref= $('.Projects.Active').attr('id');
				contentHref= '#content_'+newContentHref;
				$(contentHref).delay(speed).fadeIn(speed);
				

			}// if Project
			
	
			//If Projects Menu NOT OPEN open
			if(pm.filter('.Projects.Active').length == 0 && pm.filter('.Category.Active').prev().length > 0){
				var zInd = $('.Category.Active').css('z-index');
				$('.Category.Active').css({'z-index': '999'}).children().not(':first').fadeOut(speed,function(){
					$(this).parent().fadeOut(speed,function(){
						$(this).css({'right':(-1*pmWidth)}).show().css({'z-index': zInd }).children().show();
					});
				}).end().end().removeClass('Active').prev().css({'right': '0'}).delay(speed*2).fadeIn(speed).addClass('Active');
			}// if Project
			
	
	   });//btn PREVIOUS click


  };// MenuSlide
 
 
  
 
 
 
 
$.fn.PhotoGal = function() {
	$(this).each(function(){
		var pgCont = $(this);
		var pgChildren = pgCont.children();
		var speed = 500;
		var active = 'Active';
		
		pgCont.append('<div class="PhotoGalleryLinks" />');
		
		var thisPGLinks = pgCont.children('.PhotoGalleryLinks');
		
		pgChildren.appendTo(thisPGLinks);
		
		thisPGLinks.append('<div class="Overlay" />');
		pgChildren.each(function(){
			imgHref = $(this).attr('href');
			thisPGLinks.before('<img src="'+imgHref+'" />');
		});
		var pgChildrenImg = pgCont.children('img');
		pgChildrenImg.hide().css({'position':'absolute','left':'0','right':'0'});
		pgChildrenImg.first().show().addClass(active);
	  	pgChildren.first().addClass(active);
		
		pgChildren.click(function(e){
			e.preventDefault();
			if($(this).hasClass(active)){return false;}
			
			var thisHref = $(this).attr('href');
			pgChildrenImg.each(function(){
				if($(this).attr('src') == thisHref){
					thisImg = $(this);
					return false;
				}
			});//pgChildrenImg.each
			
			pgChildrenImg.filter('.'+active).fadeOut(speed,function(){
				$(this).removeClass(active);
				
			 });
			
			thisImg.addClass(active).fadeIn(speed);
			
			pgChildren.filter('.'+active).removeClass(active);
			$(this).addClass(active);
									
		});//pgChildren.click
	  
	});// $(this).each
};// PhotoGal


 
})( jQuery );











$(document).ready(function() {
	$('#flashMovie').flash({
		src: 'projects_movie.swf',
		width: 615,
		height: 555
						   })	
	/* 
	============================================================
	============ Multi-Tiered Dropdowns - Superfish ============ 
	============================================================
	
	Files Required: 
	jquery-1.3.2.min.js
	superfish.js
	
	-------------------------------------------------- */
	
	
	
					$("ul.Nav").superfish({
						delay:         1000,                // the delay in milliseconds that the mouse can remain outside a submenu without it closing 
						animation:     {opacity:'show',height:'show'},   // an object equivalent to first parameter of jQuery’s .animate() method 
						speed:         'normal',           // speed of the animation. Equivalent to second parameter of jQuery’s .animate() method 
						autoArrows:    true                // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance 
					});
	
	
	
	
	
	
	
	
	/* 
	============================================================
	=================== Light box - FancyBox ===================
	============================================================
	
	Files Required: 
	jquery-1.3.2.min.js
	jquery.fancybox-1.3.1.js
	
	Just add the class of fancybox, iframe or inline to any element.
	-------------------------------------------------- */
	
	$("a.fancybox").fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	600, 
			'speedOut'		:	200 
		});
	
	
	
	$("a.iframe").fancybox({
					'width'				: '75%',
					'height'			: '75%',
					'autoScale'			: false,
					'transitionIn'		: 'elastic',
					'transitionOut'		: 'elastic',
					'type'				: 'iframe'
				});
		
	$("a.inline").fancybox({
					'autoDimensions'    : false,
					'autoScale'			: false,
					'transitionIn'		: 'elastic',
					'transitionOut'		: 'elastic'
				});
	
	
		
	/* 
	============================================================
	============ Image Slideshow- Fading In and Out ============ 
	============================================================
	
	Files Required: 
	jquery-1.3.2.min.js
	jquery.cycle.all.js
	
	-------------------------------------------------- */
		
	$(".tom").cycle({ 
		fx: "fade",			/* controls transition effect -- see below for more effects */
		speed:  7000,		/* controls speed of transition */	
		pause: 1
	
	});
	
	$(".Shuffle").cycle({ 
		fx: "zoom",			/* controls transition effect -- see below for more effects */
		speed:  7000, 		/* controls speed of transition */	
		pause: 1
	});




//Starting Animation

if($('.LandingAnimation').length > 0){
	$('.LandingAnimation').prepend('<div class="LandingImage"/>');
	$('.LandingImage').hide().delay(500).fadeIn(1000).delay(1500).fadeOut(1000,function(){
		$('.LandingAnimation').delay(500).fadeOut(1000);
		
		$(".ImageRotator").cycle({ 
			fx: "fade",			/* controls transition effect -- see below for more effects */
			speed: 3000,		/* controls speed of transition */	
			timeout: 5000,
			pause: 1
		});
	
	});//END STARTING ANIMATION
}//if
else {
		$(".ImageRotator").cycle({ 
			fx: "fade",			/* controls transition effect -- see below for more effects */
			speed: 7000,		/* controls speed of transition */	
			pause: 1
		});
	
	}//Else





// :::::::::::::::::::::::::::::::::::::::::::
// Tabbed Sections
// :::::::::::::::::::::::::::::::::::::::::::


$('.SectionTab').TabbedSections();

$('.SidebarOverflow .ProjectMenus').MenuSlide();

$('.PhotoGalleryContainer').PhotoGal();

$('li:last').addClass('Last');










});	//END ALL


