$(document).ready(function(){
	
	//VARIABLES FOR QUICK MODS
	var navTargetA = "ul#nav li a"; 																			//menu link to target
	var navTargetB = "ul#botNav li a"; 																			//menu link to target
	var navTarget;																								//hold current nav menu with active link
	var contentHolder = "#content-wrapper";																		//specify gobal content holder
	var sideBarTarget = "#sideBar";																				//specify sidebar
	var sbToggleAmount; 																						//create varible to hold sidebar toggle amount		
	var PrevLink;																								//holds previous page link	
	var currentPage = "_" + startPage;
	
	//CUFON
	Cufon.replace('h1,#slidecaption-grande,.comment div', { fontFamily: 'Bebas Neue' });						//set primary font
	Cufon.replace('h2,h3,h4,h5,h6,.name',{fontFamily: 'Ubuntu'}); 												//set secondary font
	
	
	//check if raster is on/of
	if(ss_raster==0){
		$('#wrapper').addClass('raster');																		//add raster if 0, else remove
	}else{
		//nothing
	}
	
	
	//supersized control navigation
	if(ss_transitionType==0 || ss_transitionType==1 || ss_transitionType==3 || ss_transitionType==5 || ss_transitionType==6 || ss_transitionType==7){
		
		//use original horizontal
		
	} else if(ss_transitionType == 2 || ss_transitionType == 4) {
		
		//use vertical
		$('#prevslide').css({backgroundPosition: '0px -300px'});
		$('#nextslide').css({backgroundPosition: '0px -200px'});
		
		$('#prevslide').hover(function(){							   
			$(this).css({backgroundPosition: '0px -350px'})                     
			},
			function(){
			$(this).css({backgroundPosition: '0px -300px'})                     
		});
 
			
		$('#nextslide').hover(function(){							   
			$(this).css({backgroundPosition: '0px -250px'})                     
			},
			function(){
			$(this).css({backgroundPosition: '0px -200px'})                     
		});
	
	} else {
		
		//nothing
		
	}
	

// new load code borrowed - DTJ 12/15/11

	$(window).bind('load', function () {				 
		setupPage();
	});
	
	function setupPage() {
		setTimeout( function() {
				var h = $(window).height();

/*
				var h = h - $('#navContainer').innerHeight();
				var cH = h - 50;

				var cHm = $('.current-page').innerHeight();

				var barH = cHm;
			
				if (barH > cH) {
					
					dH = barH - cH;
					
					if ( $.browser.msie ) {
						dH = dH + 20;
					}
					
					if(dH < 46) {
						dH = dH;
					} else {
						dH = 46;
					}
					
					cH = barH;
					
					if ( $.browser.msie ) {
						dH = dH + 30;
					}
					$("#content-wrapper").css({ 'padding-bottom': dH });
					$(".current-page").css({ 'padding-bottom': 30 });
				} else { 
					$("#content-wrapper").css({ 'padding-bottom': 0 });
					$(".current-page").css({ 'padding-bottom': 0 });
				}
				
				$("#content-wrapper").animate({ minHeight : h });
				$(".current-page").animate({ height : cH });
*/

				var cHm = $('.current-page').innerHeight() + 116;
//				if (cHm < h) {
//					$("#content-wrapper").animate({ minHeight : h });
//				} else {
					$("#content-wrapper").animate({ minHeight : cHm });
//				}

		}, 1000);
	};

/*
	$.event.add(window, "scroll", resizeFrame);
	$.event.add(window, "resize", resizeFrame);
	
	function resizeFrame() {
		var h = $(window).height();
		var h = h - $('#navContainer').innerHeight();
		var cH = h - 50;

		var cHm = $(".current-page").children(".main-content").innerHeight();

		var barH = cHm;

		if (barH > cH) {

			dH = barH - cH;


			if(dH < 46) {
				dH = dH;
			} else {
				dH = 46;
			}

			cH = barH;

			if ( $.browser.msie ) {
				dH = dH + 30;
			}

			$("#content-wrapper").css({ 'padding-bottom': dH });
			$(".current-page").css({ 'padding-bottom': 30 });
		} else {
			$("#content-wrapper").css({ 'padding-bottom': 0 });
			$(".current-page").css({ 'padding-bottom': 0 });
		}

		$("#content-wrapper").css({ minHeight : h });
		$(".current-page").css({ height : cH });
		
	}
*/
// end borrowed code	
	
	/*init team div*/
	$('ul.listStyle li:last').css('border', 'none'); 															//make sure the last team has no border
	$('ul.listStyle li:last').css({margin :'0px',padding:'0px'});
	
	/*init blog div*/
	$('#blogContainer ul li div.post:last').css('border', 'none'); 												//make sure the last team has no border
	$('#blogContainer ul li div.post:last').css({margin :'0px'});
	
	//init pajinate containers
	$('#folioContainer').pajinate({start_page : folio_start_page, items_per_page : folio_items_per_page	});     //initialize pagination of folio items
	$('#blogContainer').pajinate({start_page : 0,items_per_page : blog_items_per_page	});     				//initialize pagination of folio items
	
	//init fancybox
	$("a[rel=folioGroup]").fancybox({
				'transitionIn'		: lightboxTransition,
				'transitionOut'		: lightboxTransition,
				'titlePosition' 	: 'over',
				'padding'			: '0',																		//remove to display border
				'overlayOpacity'    : overlayOpacity,
				'overlayColor'      : overlayColor,
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
	});
	
	$("a._videoThumb").fancybox({
                  'transitionIn'        : lightboxTransition,
                  'transitionOut'       : lightboxTransition,
				  'padding'			    : '0',																	//remove to display border
				  'width'			    : videoWidth,
				  'height'				: videoHeight,
				  'overlayOpacity'      : overlayOpacity,
				  'overlayColor'        : overlayColor,
                  'autoscale'           : 'false',
                   'type'               : 'swf',
				  'swf'           		: {
				  'wmode'             	: 'transparent',
				  'allowfullscreen'  	: 'true'
										   }

    }); 
	
	
	
	//MAIN MENU - PAGE SWITCH

	 //add ids to the menu links
/*
	 $(navTarget).each(function(i){
		i++						
   		this.id = this.id + "_" + i;
	 });
*/	 
	 //add ids to the pages
/*	 
	 $(contentHolder).children('.content').each(function(i){
		i++													 
   		this.id = this.id + "page" + "_" + i;
	 });
*/
	 
	 //hide all, then set the first
	 $(contentHolder).children('.content').hide();
	 $(contentHolder).children("#page_" + startPage).show();
	 $('#_' + startPage).addClass('active');

	 PrevLink = $('#_' + startPage);

	 if ($(navTargetA).hasClass('active')) { navTarget = navTargetA; }
	 if ($(navTargetB).hasClass('active')) { navTarget = navTargetB; }
	
	 $(navTargetA).click(function() {

			//ensure link isnt clickable when active
			if ($(this).hasClass('active')) return;

			//ensure link id has been assigned
			if ($(this).attr('id') == '') return;
			
			PrevLink = $(navTarget + '.active');
			$(PrevLink).removeClass('active');
			
			var PrevId = $(PrevLink).attr('id');
			var NextLink = $(this).addClass('active');
			var NextId = $(this).attr('id');

			navTarget = navTargetA;
			currentPage = NextId;
						
			//set markers
			var prevPage = $("#content-wrapper").children("#page"+PrevId);
			var nextPage = $("#content-wrapper").children("#page"+NextId);	
			
			$(prevPage).css({opacity:1});
			$(nextPage).css({opacity:0});
			
			//run ie fix for animating cufon text
			$(prevPage).children().each(function(){
				$('h1').stop().animate({opacity:0},pageFadeSpeed)									 
				$('h2').stop().animate({opacity:0},pageFadeSpeed)														
			 })
			
			//fade out previous + call things once done
			$(prevPage).stop().animate({opacity:0},pageFadeSpeed, function(){
				$(this).removeClass('current-page');
				
				//animation done, hide previous page												   
				$(this).hide();
				
				//show the next page
				$(nextPage).show();
				$(nextPage).addClass('current-page');
				
				//fade it in
				$(nextPage).animate({opacity:1},pageFadeSpeed, function() {
//					resizeFrame();
					setupPage();
				});

				//run ie fix for animating cufon text
				$(nextPage).children().each(function(){	
					$('h1').stop().animate({opacity:1},pageFadeSpeed)									 
					$('h2').stop().animate({opacity:1},pageFadeSpeed)					
				});
				
			})
			
			if ($(this).attr('rel') == 'flashbg') {
//				$('#flashbg').show();
//				$('#flashbg').animate({opacity:1},pageFadeSpeed);	
				$('#supersized').animate({opacity:0},pageFadeSpeed, function() {
					$(this).hide();
				});	
			} else {
//				$('#flashbg').animate({opacity:0},pageFadeSpeed, function() {
//					$(this).hide();
//				});	
				$('#supersized').show();
				$('#supersized').animate({opacity:1},pageFadeSpeed);
			}
			
	});	

	 $(navTargetB).click(function() {

			//ensure link isnt clickable when active
			if ($(this).hasClass('active')) return;

			//ensure link id has been assigned
			if ($(this).attr('id') == '') return;
	
			PrevLink = $(navTarget + '.active');
			$(PrevLink).removeClass('active');

			var PrevId = $(PrevLink).attr('id');
			var NextLink = $(this).addClass('active');
			var NextId = $(this).attr('id');

			navTarget = navTargetB;
			currentPage = NextId;
		
			//set markers
			var prevPage = $("#content-wrapper").children("#page"+PrevId);
			var nextPage = $("#content-wrapper").children("#page"+NextId);	
			
			$(prevPage).css({opacity:1});
			$(nextPage).css({opacity:0});
			
			//run ie fix for animating cufon text
			$(prevPage).children().each(function(){
				$('h1').stop().animate({opacity:0},pageFadeSpeed)									 
				$('h2').stop().animate({opacity:0},pageFadeSpeed)														
			 })
			
			//fade out previous + call things once done
			$(prevPage).stop().animate({opacity:0},pageFadeSpeed, function(){
				$(this).removeClass('current-page');

				//animation done, hide previous page												   
				$(this).hide();

				//show the next page
				$(nextPage).show();
				$(nextPage).addClass('current-page');
	
				//fade it in
				$(nextPage).animate({opacity:1},pageFadeSpeed, function() {
//					resizeFrame();
					setupPage();
				});
				
				//run ie fix for animating cufon text
				$(nextPage).children().each(function(){	
					$('h1').stop().animate({opacity:1},pageFadeSpeed)									 
					$('h2').stop().animate({opacity:1},pageFadeSpeed)					
				 });
			})

			if ($(this).attr('rel') == 'flashbg') {
//				$('#flashbg').show();
//				$('#flashbg').animate({opacity:1},pageFadeSpeed);	
				$('#supersized').animate({opacity:0},pageFadeSpeed, function() {
					$(this).hide();
				})
			} else {
//				$('#flashbg').animate({opacity:0},pageFadeSpeed, function() {
//					$(this).hide();
//				});	
				$('#supersized').show();
				$('#supersized').animate({opacity:1},pageFadeSpeed);	
			}
	});	


	//HOVERS
	$("._rollover").animate({ "opacity": "0" });
	$("._thumb-ind").animate({ "opacity": "0" });
	
	var targetHover
	
	/*folio hovers*/
	$("._logoThumb").hover(

			function() {
				targetHover = $(this).parent().children('._rollover')
				$(targetHover).animate({"opacity": "0.9"}, hoverFadeSpeed);
				
				if($(this).parent('.thumb_holder')){
					$(this).css({backgroundPosition:'-160px'});
					$(this).stop().animate({backgroundPosition:'0px'}, 200);
																																   
				}
				
			},
			function() {
				targetHover = $(this).parent().children('._rollover')
				$(targetHover).animate({"opacity": "0"}, hoverFadeSpeed);
				
				if($(this).parent('.thumb_holder')){
					
					$(this).stop().animate({backgroundPosition:'160px'}, 200);
					
				}
				
			}
	);
	
	
	/*folio video hover*/
	$("._videoThumb").hover(
	
				function() {
					targetHover = $(this).parent().children('._rollover')
					$(targetHover).animate({"opacity": "0.9"}, hoverFadeSpeed);
					$(this).parent().children('._thumb-ind').animate({ "opacity": "1" }, hoverFadeSpeed);
					if($(this).parent('.thumb_holder')){
						$(this).css({backgroundPosition:'-160px'});
						$(this).stop().animate({backgroundPosition:'0px'}, 200);
																																	   
					}
					
				},
				function() {
					targetHover = $(this).parent().children('._rollover')
					$(targetHover).animate({"opacity": "0"}, hoverFadeSpeed);
					$(this).parent().children('._thumb-ind').animate({ "opacity": "0" }, hoverFadeSpeed);
					if($(this).parent('.thumb_holder')){
						
						$(this).stop().animate({backgroundPosition:'160px'}, 200);
						
					}
					
				}
	);
	
	
		
		/*blog hovers*/
		$("._logoBlog").hover(

			function() {
				targetHover = $(this).parent().children('._rollover')
				$(targetHover).animate({"opacity": "0.9"}, hoverFadeSpeed);
				
				if($(this).parent('.blogImg_holder')){
					$(this).css({backgroundPosition:'-500px'});
					$(this).stop().animate({backgroundPosition:'0px'}, 300);
																																   
				}
				
		},
			function() {
				targetHover = $(this).parent().children('._rollover')
				$(targetHover).animate({"opacity": "0"}, hoverFadeSpeed);
				
				if($(this).parent('.blogImg_holder')){
					
					$(this).stop().animate({backgroundPosition:'500px'}, 300);
					
				}
				
		});
	
	
		/*icon hovers*/
		$("._rollover").hover(
			function() {
				$(this).animate({"opacity": "1"}, hoverFadeSpeed);
		},
			function() {
				$(this).animate({"opacity": "0"}, hoverFadeSpeed
								);
		});
		
		//SET SOCIAL URLS
		$("a#fb").attr("href", "http://www.facebook.com/pages/"+facebookPageID)
		$("a#twr").attr("href", "http://www.twitter.com/"+twitterID)
		$("a#msp").attr("href", "http://www.myspace.com/"+myspaceID)
		$("a#fkr").attr("href", "http://www.flickr.com/photos/"+flickrID)
		$("a#yt").attr("href", "http://www.youtube.com/user/"+youtubeID)
		
		
		//CONTACT FORM - original code by Farid Hadi -http://www.faridhadi.com
		
		$('#reload').hide();// hide form reload button
		
		//field values on focus,on focus out
//		$('#contactForm #name,#contactForm #email,#contactForm #subject,#contactForm #message' ).focus(function(){
		$('#contactForm form #name, #contactForm form  #email, #contactForm form  #message' ).focus(function(){
			var initVal = $(this).val();
			$(this).val( initVal === this.defaultValue ? '' : initVal );
		}).blur(function(){
			var initVal = $(this).val();
			$(this).val( initVal.match(/^\s+$|^$/) ? this.defaultValue : initVal );
		});

		// enable the form submit button
//		$('#contactForm form #submit').attr("disabled", "");
		
		$('#contactForm form #submit').click(function() {
			
//			alert('Thanks!');
												 
			// Fade in the prloader
			$('#contactForm #formProgress').hide();
			$('#contactForm #formProgress').html('Sending&hellip;');
			$('#contactForm #formProgress').fadeIn();
			
			// Disable the submit button
			$('#contactForm form  #submit').attr("disabled", "disabled");
			
			// Set temporary variables for the script
			var isFocus=0;
			var isError=0;
			
			// Get the data from the form
			var name=$('#contactForm form #name').val();
			var email=$('#contactForm form #email').val();
//			var subject=$('#contactForm #subject').val();
			var message=$('#contactForm form #message').val();
			var display=$('#contactForm form #display').val();
			var notify=$('#contactForm form #notify').val();
			
			
			//check if form element have verify class, if so remove and recheck
			if ($('#contactForm form #name').hasClass('formVerify')){
				$('#contactForm form #name').removeClass('formVerify');
			}
			if ($('#contactForm form  #email').hasClass('formVerify')){
				$('#contactForm form  #email').removeClass('formVerify');
			}
			if ($('#contactForm form  #message').hasClass('formVerify')){
				$('#contactForm form  #message').removeClass('formVerify');
			}
			
			//Make sure bkgs are set to original
			$('#contactForm form  #name').addClass('formReset');
			$('#contactForm form  #email').addClass('formReset');
			$('#contactForm form  #message').addClass('formReset');
			
			// Validate the data
			if(name=='Name*' || name=='' ) {
				$('#contactForm form  #name').addClass('formVerify');
				$('#contactForm form  #name').focus();
				isFocus=1;
				isError=1;
			}
			if(email=='E-mail*' || email=='' ) {
				$('#contactForm form  #email').addClass('formVerify');
				if(isFocus==0) {
					$('#contactForm form  #email').focus();
					isFocus=1;
				}
				isError=1;
			} else {
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				if(reg.test(email)==false) {
					$('#contactForm form  #email').addClass('formVerify');
	
					if(isFocus==0) {
						$('#contactForm form  #email').focus();
						isFocus=1;
					}
					isError=1;
					
				}
			}
			if(message=='Speak Your Mind*' || message=='' ) {
				$('#contactForm form  #message').addClass('formVerify');
				if(isFocus==0) {
					$('#contactForm form  #message').focus();
					isFocus=1;
				}
				isError=1;
			}
			
			// Terminate the script if an error is found
			if(isError==1) {
				$('#contactForm #formProgress').html(formWarning);
				
				
				// Activate the submit button
				$('#contactForm form  #submit').attr("disabled", "");
				
				return false;
			}
			
			$.ajaxSetup ({
				cache: false
			});
			
//			var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&message=' + message;  
			var dataString = 'name='+ name + '&email=' + email + '&message=' + message + '&display=' + display + '&notify=' + notify;  
			$.ajax({
				type: "POST",
				url: "php/submit-form-ajax.php",
				data: dataString, // create code to determine which form info is coming from - DTJ
				success: function(msg) {
					
					/*alert(msg);*/
					
					
					// Check to see if the mail was successfully sent
					if(msg=='Mail sent') {
						
						// Update the loader to a check + message
						$('#sentConfirmMessage').html(formSuccess);
						
						//Change the main title
						$('#sentConfirmTitle').html(formSuccessTitle);
						
						//Display the info
						$('#sentConfirmMessage').fadeIn(1000);
						$('#sentConfirmTitle').fadeIn(1000);
						
						// Reinitialize the fields
						$('#contactForm form  #name').val('Name*');
						$('#contactForm form  #email').val('E-mail*');
//						$('#contactForm form  #subject').val('Subject');
						$('#contactForm form  #message').val('Speak Your Mind*');
						
						// Fade out the contact from, then toggle the height
						$("#contactForm").animate({"opacity": "0"}, 1000);	
						$('#contactForm').delay(200).slideToggle("slow");
						
						//Fade in reload link
						$('#reload').fadeIn();	
						
						
						//Ensure new title is cufoned after sending
						Cufon.replace('h1#sentConfirmTitle');
						
						
					} else {
						$('#contactForm #formProgress').html(formError);
					}
					
					// Activate the submit button
					$('#contactForm form  #submit').attr("disabled", "");
				},
				error: function(ob,errStr) {
					$('#contactForm #formProgress').html(formError);
					
					// Activate the submit button
					$('#contactForm form  #submit').attr("disabled", "");
				}
			});
			
			return false;
	});
		
	// Contact form reload but function	
	$('#reload').click(function() {
		$("#contactForm").animate({"opacity": "1"}, 1000);	
		$('#contactForm').animate({ height:'toggle' }, 1000);
		$('#sentConfirmMessage').html(formReload);
		$('#sentConfirmTitle').html(formReloadTitle);
		$('#reload').fadeOut();
		$('#contactForm #formProgress').html('*required');
		$('#contactForm form  #submit').attr("disabled", "");

		//Ensure new title is cufoned
		Cufon.replace('h1#sentConfirmTitle');
		
	});
	
	$('a[rel=prettyPhoto]').prettyPhoto();			
		
});

