	
$(document).ready(function(){

	
	//VARIABLES -------------------------------------------------------------------------/
	
	var navTarget = "ul#nav li a"  																				//menu link to target
	var contentHolder = "#content-wrapper"																		//specify gobal content holder
	var sideBarTarget ="#sideBar"																				//specify sidebar
	var sbToggleAmount 																							//create varible to hold sidebar toggle amount
	var sb = 0																									//submenu open/closed status
	var sb_id																									//id reference variable for submenu	
	var iconWidth = 115																							//image hover icon width
	var targetHover																								//image/videos- stores hover target ref.
	var widthRef																								//image/videos- stores img/video width ref.
	var postStatus = 0																							//blog - stores post open/closed status
	var rdId																									//blog - read more id
	var postNo																									//blog - post number to call

	//CUFON CALLS -----------------------------------------------------------------------/
	
	
	Cufon.replace('h1,h2,h3,h4,h5,h6,.name,.comment_name',{fontFamily: 'Ubuntu'}); 								//set all font
	Cufon.replace('h1.pageHeading,#slidecaption-grande,.comment div', { fontFamily: 'Bebas Neue' });			//set primary font
	
	
	//INIT -SET -------------------------------------------------------------------------/
	
	//html/wrapper
	$('#wrapper').css({overflow:'hidden'});																		//hide overflow
	$('html').css({overflow:'hidden'});																			//ie7 fix
	$('#launch-but #label').html(launchButTitle);																//toggle but initial title
	//$(contentHolder).css({display:'block'});																	//bring content to visibility if set to display:none in css
	
	/*for ie - headings*/
	$('h1,h2').css({opacity:0});																	//set main headings to opacity 	0, for ie7/8						 
	
	//pattern overlay - check if raster is on/of
	if(ss_raster==0){
		$('#wrapper').addClass('raster');																		//add raster if 0, else remove
	}else{
		//nothing
	}
	
	
	//sidebar on load
	$(window).load(function () {	
			
			sideBarHeight();										 											//set toggle amount based on sidebar height
			
			if (appearOnLoad ==0){
				
				$(sideBarTarget).css({marginTop: -sbToggleAmount});												//position sidebar
				$('#launch-but').fadeIn();																		//fade in the content launch button
			}
			
			$(sideBarTarget).show();																			//make side bar visible
			
	});
	
	
	//FUNCTIONS-------------------------------------------------------------------------/
	
	
	//scroll to top function - call as necessary
	var toTop = function(){
		
		//scrollToTop 
		if(scrollToTop = 1)$('#wrapper').animate({scrollTop:0},scrollSpeed);
				
	}
	
	//sidebar reclaculate height - call as necessary
	var sideBarHeight = function() {
		
		sbToggleAmount = $('#sideBar').height();																
	
	}
	

	//SUPERSIZED CUSTOM NAVIGATION ----------------------------------------------------/
	
	
	//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
		
	}
	
	//TWITTER -------------------------------------------------------------------------/
	
	//twitter adjustment
	var twitterH= 97*TweetsDisp																					//set the correct height of the twitter box depending on no of tweets to display where 97 is the 	                         																						  height of one tweet. If changed in the css, change it here as well.
	
	if(noTweets>1 || noTweets <=3){																				// if greater than 1 but less than 3 adjust the height accordingly
		$('#tweet-container').css({height:twitterH+'px'});														//set the correct height
	}else{
		$('#tweet-container').css({height:'288px'});															//if above 3, set it to a fixed height of 288px
	}
	
	
	
	
	//PAGINATION ----------------------------------------------------------------------/
	
	//init pajinate containers - add containers as necessary
	$('#folioContainer4').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 blog items
	
	
	
	//TOGGLE CONTENT ------------------------------------------------------------------/
	
	//launch but special effect
	  $('#launch-but').hover(
            function(){
                $('#circle').stop().animate({width : '92px', height : '92px', 'margin-top' : '-46px', 'margin-left' : '-46px'  }, 200);
				$('#circle-overlay').stop().delay(100).animate({width : '95px', height : '95px', 'margin-top' : '-47.5px', 'margin-left' : '-47.5px'  }, 200);
            },
            function(){
                $('#circle').stop().delay(200).animate({width : '80px', height : '80px', 'margin-top' : '-40px', 'margin-left' : '-40px'  }, 200);
			    $('#circle-overlay').stop().animate({width : '0px', height : '0px', 'margin-top' : '0px', 'margin-left' : '0px'    }, 200);
            }
        );
	
	//launch but actions
	$('#launch-but').click(function(){
								 
			$(sideBarTarget).animate({marginTop:0},sideBarToggleSpeed, menuEase);								//toggle sidebar
			$(contentHolder).show().animate({top:'0px', opacity:1}, contentToggleSpeed,pageEase);				//toggle content
			$('h1,h2').stop().animate({opacity:1},contentToggleSpeed);											//fade out h tags for ie 7/8
			$('#close-but div').html(closeButTitle);															//set toggle but title
			$('#controls-wrapper').fadeOut();																	//fade out gallery nav
			$('#slidecaption-grande').fadeOut();																//*ie 7/8 fix- fade out slide caption
			$('#wrapper').css({overflow:'auto'});																//make scroll bar reappear
			$('html').css({overflow:'auto'});																	//*ie 7	overflow fix						 
			var pos = $(contentHolder).offset().top
			$(this).fadeOut();
			if(ss_pauseContentOpen==1) api.playToggle();														// Pause slideshow when content opens
			return false;	
		 
	});
	
	//close but actions
	$('#close-but').click(function() {
		 	$(sideBarTarget).animate({marginTop:-sbToggleAmount},sideBarToggleSpeed, menuEase);
			$(contentHolder).animate({top:'300px',opacity:0}, contentToggleSpeed,pageEase, function(){			//hide content once animation is done, deactivate scrollbar
						$(contentHolder).hide();
			});										
			$('#controls-wrapper').delay(400).fadeIn();									
			$('#slidecaption-grande').delay(400).fadeIn();	
			$('h1,h2').stop().animate({opacity:0},contentToggleSpeed);	
			$('#launch-but,#navArrows,#slide-info').delay(sideBarToggleSpeed).fadeIn('normal',menuEase); 
			if(ss_pauseContentOpen==1) api.playToggle();														// resume slideshow when content closes
			return false;		   	 	
	});
	
	
	
	
	
	//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');
	

	//MENU CLICK FUNCTIONS
	 $(navTarget).click(function() {

			
			//ensure link isnt clickable when active
			if ($(this).hasClass('active')) return false;
			
			//set previous and next link & page ids
			var PrevLink = $(navTarget+'.active')
			$(PrevLink).removeClass('active');
			var PrevId = $(PrevLink).attr('id');
			var NextLink = $(this).addClass('active');
			var NextId = $(this).attr('id');
			
			
			//SUB MENU FUNCTIONS
			
			//CASE 1: submenu parent clicked, submenu present, none open
			if ($(this).hasClass('mainmenu') && $(this).parent().children('ul.submenu').length > 0  && sb ==0 ){
				
				//indicate that a submenu is open
				sb = 1
				
				//set submenu reference
				sb_id = $(this).attr('id');
				
				//animate submenu
				$(this).parent().children('ul.submenu').slideDown('normal', function(){
																								
					//calculate new sidebar height
					sideBarHeight();
					
				});

				
				//calculate new sidebar height
				sideBarHeight();
				
				
			//CASE 2: submenu parent clicked of open submenu clicked
			}else if($(this).hasClass('mainmenu') && $(this).parent().children('ul.submenu').length > 0 && $(this).parent().children('ul.submenu').css("display") != "none"){
			
			//nothing just load the main page

			
			//CASE 3: new submenu parent clicked, submenu present, a submenu is already open
			}else if($(this).hasClass('mainmenu') && $(this).parent().children('ul.submenu').length > 0  && sb ==1 ){

				//hide previous submenu
				$('a#'+sb_id).parent().children('ul.submenu').slideUp();
				
				//animate current  submenu
				$(this).parent().children('ul.submenu').delay(500).slideDown('normal', function(){
																								
					//calculate new sidebar height
					sideBarHeight();
					
				});

				//set new submenu id reference
				sb_id = $(this).attr('id');
				
				
				
			//CASE 4: main menu item clicked, no submenu present, hide all submenus
			}else if ($(this).hasClass('mainmenu')  &&  $(this).parent().children('ul.submenu').length == 0){
				
				//in the even a main menu w/ no submenu is clicked, hide any open submenu
				$('ul.submenu').slideUp('normal', function(){
																								
					//calculate new sidebar height
					sideBarHeight();
					
				});
				
				//all submenus now closed
				sb = 0
				
			}
			
		
			//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,h2,h3,h4,h5,h6').stop().animate({opacity:0},pageFadeSpeed);													
			 })
			
			//fade out previous + call things once done
			$(prevPage).stop().animate({opacity:0},pageFadeSpeed, function(){
				
				//scroll to top
				toTop();
				//animation done, hide previous page												   
				$(this).hide();
				//show the next page
				$(nextPage).show();
				//fade it in
				$(nextPage).animate({opacity:1},pageFadeSpeed);
				//run ie fix for animating cufon text -
				$(nextPage).children().each(function(){	
					//$('h1,h2,h3,h4,h5,h6').stop().animate({opacity:1},pageFadeSpeed);				
				
				 })
			})
			
			
			
	});	
	
	//IMGES& VIDEO -------------------------------------------------------------------------------/
	
	
	//init fancybox - image handling
	$("a._imageThumb").fancybox({
				'transitionIn'		: lightboxTransition,
				'transitionOut'		: lightboxTransition,
				'titlePosition' 	: 'over',
				'padding'			: '0',																		
				'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>';
				}
	});
	
	//init fancybox - video handling
	$("a._videoThumb").fancybox({
                  'transitionIn'        : lightboxTransition,
                  'transitionOut'       : lightboxTransition,
				  'padding'			    : '0',																	
				  'width'			    : videoWidth,
				  'height'				: videoHeight,
				  'overlayOpacity'      : overlayOpacity,
				  'overlayColor'        : overlayColor,
                  'autoscale'           : 'true',
                   'type'               : 'swf',
				  'swf'           		: {
				  'wmode'             	: 'transparent',
				  'allowfullscreen'  	: 'true'
										   }

        }); 
	
	
	
	//set rollover initial opacity
	$("._rollover").animate({ "opacity": "0" });
	$("._thumb-ind").animate({ "opacity": "0" });
	
	
	 //iterrate over all image frames - set hover w/h, shadow w/h
	 $(".image_frame").each(function(){
		
		
		var mediaWidth = $(this).children('img').width();		
		var mediaHeight = $(this).children('img').height();	
		//set w/h of hover effects based on image w/h
		$(this).children('a').css({width:mediaWidth,height:mediaHeight});			
   		$(this).children('._rollover').css({width:mediaWidth,height:mediaHeight});	
		
		//resize drop shadow if in use
		if($(this).parent().children().hasClass('drop_shadow')){
			
			//set image aspect ratio - change as necessary
			var aspectRatio = 600/40
			var shadowHeight = mediaWidth/aspectRatio
			
			$(this).parent().children('.drop_shadow').css({width:mediaWidth, height:shadowHeight});
		}
	 });
	 
	 
	 //iterrate over all image frames - shadow w/h
	 $(".video_frame").each(function(){
		
		var mediaWidth = $(this).children('iframe').width();		
		var mediaHeight = $(this).children('iframe').height();	
		
		//resize drop shadow if in use
		if($(this).parent().children().hasClass('drop_shadow')){
			
			//set image aspect ratio - change as necessary
			var aspectRatio = 600/40
			var shadowHeight = mediaWidth/aspectRatio
			
			$(this).parent().children('.drop_shadow').css({width:mediaWidth, height:shadowHeight});
		}
	 });
	 
	
	
	/*image hovers - add addtional hover icon classes here*/
	$("._imageThumb,._blogThumb,._videoThumb").hover(

			function() {
				
				targetHover = $(this).parent().children('._rollover')
				$(targetHover).animate({"opacity": "0.9"}, hoverFadeSpeed);
				
				//video icon
				if($(this).hasClass('_videoThumb')) $(this).parent().children('._thumb-ind').animate({ "opacity": "1" }, hoverFadeSpeed);
				
				//get reference width of image used
				widthRef = $(this).parent().children('._original').width();
				
				if($(this).parent('.image_frame')){
					
					//hide the icon of the viewport
					$(this).css({backgroundPosition:-widthRef});
					
					//position hover icon based on image width
					var iconPos = widthRef/2 -iconWidth/2
					
					//animate the icon to the position
					$(this).stop().animate({backgroundPosition:iconPos}, 200);
																																   
				}
				
		},
			function() {
				
				targetHover = $(this).parent().children('._rollover')
				$(targetHover).animate({"opacity": "0"}, hoverFadeSpeed);
				
				//video icon
				if($(this).hasClass('_videoThumb')) $(this).parent().children('._thumb-ind').animate({ "opacity": "0" }, hoverFadeSpeed);
				
				if($(this).parent('.image_frame')){
					
					$(this).stop().animate({backgroundPosition:widthRef}, 200);
					
				}
				
		});

	
		//SOCIAL ------------------------------------------------------------------------------/
		
		$("._rollover-social").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)
		
		
		//BLOG -------------------------------------------------------------------------------/

		
		//read more click functions
		 $('.r-more').click(function() {
				
				//get id of read more link
				rdId = $(this).attr('id');
				
				//get the number from the id
				postNo = rdId.substr(rdId.length - 2);
				
				//check that post is closed
				if (postStatus ==0){		
					
					//slide and hide the blog container 
					$('#blogContainer').animate({marginLeft:'-500px', opacity:0}, function(){
							
							//enter the pose close button
							$('.post_close').show();
							$('.post_close').stop().animate({backgroundPosition:'-17px'}, 200);
							
							//hide the blog container as its not in use
							$('#blogContainer').hide();
							
							//swtich post status
							postStatus=1;	
							
							//call our post content associated with the read more that was clicked
							$(this).parent().children('#post'+postNo).show().animate({marginLeft:'0px', opacity:1});
																						
					});
					
					
				
				}
					
		});
		 
		 
		 //post close button functions
		 $('.post_close').click(function() { 
				
				//only in use if a post is open
				if (postStatus ==1){
		 
		 			//get the post thats open, slide it and hide it
					$('#post'+postNo).animate({marginLeft:'-500px', opacity:1}, function(){
																						 
								//hide the close button														 
								$('.post_close').stop().animate({backgroundPosition:'-33px'}, 200, function(){
								
									$('.post_close').hide();
								
								});
								
								//re-enter the blog container
								$('#blogContainer').show().animate({marginLeft:'0px', opacity:1});
								
								//scroll to top
								toTop();
								
								//swtich post status
								postStatus=0;		
								
								//hide the post that was previously open
								$('#post'+postNo).hide();
								
							
					});
							
				}
		
		});
		 
		 //post_close:hover
		$('.post_close').mouseover(function() {
											
			$(this).css({backgroundPosition:'0px'});
			
		  }).mouseout(function(){
			  
			$(this).css({backgroundPosition:'-17px'});
			
		  });
		
		 
		
		//FORMS ------------------------------------------------------------------------------/
		/*- original code by Farid Hadi -http://www.faridhadi.com*/
		
		// hide form reload button
		$('#reload').hide();
		
		//field values on focus,on focus out
		$('#contactForm #name,#contactForm #email,#contactForm #subject,#contactForm #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 );
		});
		
		//submit click function
		$('#contactForm #submit').click(function() {
												 
			// Fade in the prloader
			$('#contactForm #formProgress').hide();
			$('#contactForm #formProgress').html('Sending&hellip;');
			$('#contactForm #formProgress').fadeIn();
			
			// Disable the submit button
			$('#contactForm #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 #name').val();
			var email=$('#contactForm #email').val();
			var subject=$('#contactForm #subject').val();
			var message=$('#contactForm #message').val();
			
			
			//check if form element have verify class, if so remove and recheck
			if ($('#contactForm #name').hasClass('formVerify')){
				$('#contactForm #name').removeClass('formVerify');
			}
			if ($('#contactForm #email').hasClass('formVerify')){
				$('#contactForm #email').removeClass('formVerify');
			}
			if ($('#contactForm #message').hasClass('formVerify')){
				$('#contactForm #message').removeClass('formVerify');
			}
			
			//Make sure bkgs are set to original
			$('#contactForm #name').addClass('formReset');
			$('#contactForm #email').addClass('formReset');
			$('#contactForm #message').addClass('formReset');
			
			// Validate the data
			if(name=='Name*' || name=='' ) {
				$('#contactForm #name').addClass('formVerify');
				$('#contactForm #name').focus();
				isFocus=1;
				isError=1;
			}
			if(email=='E-mail*' || email=='' ) {
				$('#contactForm #email').addClass('formVerify');
				if(isFocus==0) {
					$('#contactForm #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 #email').addClass('formVerify');
	
					if(isFocus==0) {
						$('#contactForm #email').focus();
						isFocus=1;
					}
					isError=1;
					
				}
			}
			if(message=='Message*' || message=='' ) {
				$('#contactForm #message').addClass('formVerify');
				if(isFocus==0) {
					$('#contactForm #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 #submit').attr("disabled", "");
				
				return false;
			}
			
			$.ajaxSetup ({
				cache: false
			});
			
			var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&message=' + message;  
			$.ajax({
				type: "POST",
				url: "php/submit-form-ajax.php",
				data: dataString,
				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 #name').val('Name*');
						$('#contactForm #email').val('E-mail*');
						$('#contactForm #subject').val('Subject');
						$('#contactForm #message').val('Message*');
						
						// 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 #submit').attr("disabled", "");
				},
				error: function(ob,errStr) {
					$('#contactForm #formProgress').html(formError);
					
					// Activate the submit button
					$('#contactForm #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');
		
		//Ensure new title is cufoned
		Cufon.replace('h1#sentConfirmTitle');
		
	});			
		
		
		
		
});

