jQuery(function($){
	$.supersized({
	
		//Functionality
		slideshow               :   1,		//Slideshow on/off
		autoplay				:	0,		//Slideshow starts playing automatically
		start_slide             :   1,		//Start slide (0 is random)
		random					: 	0,		//Randomize slide order (Ignores start slide)
		slide_interval          :   7000,	//Length between transitions
		transition              :   1, 		//0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
		transition_speed		:	700,	//Speed of transition
		new_window				:	1,		//Image links open in new window/tab
		pause_hover             :   0,		//Pause slideshow on hover
		keyboard_nav            :   1,		//Keyboard navigation on/off
		performance				:	1,		//0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
		image_protect			:	0,		//Disables image dragging and right click with Javascript
		image_path				:	'img/background', //Default image path

		//Size & Position
		min_width		        :   0,		//Min width allowed (in pixels)
		min_height		        :   0,		//Min height allowed (in pixels)
		vertical_center         :   0,		//Vertically center background
		horizontal_center       :   1,		//Horizontally center background
		fit_portrait         	:   1,		//Portrait images will not exceed browser height
		fit_landscape			:   0,		//Landscape images will not exceed browser width
		//fit_always				:	1,
		
		//Components
		navigation              :   1,		//Slideshow controls on/off
		thumbnail_navigation    :   1,		//Thumbnail navigation
		slide_counter           :   1,		//Display slide numbers
		slide_captions          :   1,		//Slide caption (Pull from "title" in slides array)
		slides 					:  	[		//Slideshow Images
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web001.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web002.jpg', title : 'Title'},  
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web003.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web004.jpg', title : 'Title'},
											//{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web005.jpg', title : 'Title'}, 
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web006.jpg', title : 'Title'}, 
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web007.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web008.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web009.jpg', title : 'Title'},
											//{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web010.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web011.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web012.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web013.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web014.jpg', title : 'Title'},
											//{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web015.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web016.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web017.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web018.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web019.jpg', title : 'Title'},
											//{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web020.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web021.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web022.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web023.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web024.jpg', title : 'Title'},
											//{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web025.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web026.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web027.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web028.jpg', title : 'Title'},
											{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web029.jpg', title : 'Title'}
											//{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web030.jpg', title : 'Title'},
											//{image : 'http://development.makemeikonik.co.uk/nielstewartphotography/wp-content/themes/nielstewartphotography/img/background/NSP-Web001.jpg', title : 'Pickup truck by Niel Stewart', url : 'http://development.makemeikonik.co.uk/nielstewartphotography/'}  
									]
	});
});

$(document).ready(function(){

	$('a#slideshowToggle').toggle(function(){
		$(this).addClass('playing');
		$('#introPanel').fadeTo('slow', 0);
		$('#contentPanel').fadeTo('slow', 0);
		$('#hoverControl').fadeTo('slow', 0);
		$('#share').fadeTo('slow', 0);
		api.playToggle();
	}, function(){
		$(this).removeClass('playing');
		$('#introPanel').fadeTo('slow', 1);
		$('#contentPanel').fadeTo('slow', 0.95);
		$('#hoverControl').fadeTo('slow', 1);
		$('#share').fadeTo('slow', 1);
		api.playToggle();
	});
	
	//resizeDimArea();
	
	/*$(window).resize(function(){
		resizeDimArea();		  
	});*/
	
	$('.activeslide img').one('load',function() {
		setTimeout(function(){
			$('#introPanel').fadeTo('slow', 1);
			$('#contentPanel').fadeTo('slow', 0.95);
			$('#intControls').fadeTo('slow', 1);
			$('#share').fadeTo('slow', 1);
		}, 500);
	});
		
	if($('body').hasClass('single')){
		if($('#contentPanel').height() < $(window).height()){
			$('#contentPanel').css({ height: '100%' });	
		}
	}
	
	jQuery.validator.messages.required = "";
	$('#contactForm').validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = 'Please fill in all mandatory fields before continuing.';
				$("div.error p").html(message);
				$("div.error").show();
			} else {
				$("div.error").hide();
			}
		}
	});
	
	$('#hoverHotspot').hover(function(){
		$('#introPanel, #contentPanel').stop(true, false).fadeTo('slow', 0);				
	}, function(){
		$('#introPanel').fadeTo('slow', 1);
		$('#contentPanel').fadeTo('slow', 0.95);
	});

	$('#togglePanelBt').click(function(){
		if ($('#contentPanel').hasClass('panelVisible')){
			$('#contentPanel').animate({ left: '-180px' }, 700, function(){
				$(this).removeClass().addClass('panelHidden');
				$('#togglePanelBt').text('Open');
				$('#contentPanelInner').hide();
			});
		} else {
			$('#contentPanelInner').show();
			$('#contentPanel').animate({ left: '320px' }, 700, function(){
				$(this).removeClass().addClass('panelVisible');
				$('#togglePanelBt').text('Close');
			});
		}
	});
	
	
	/*$('a.showPanel').click(function(){
		var thePage = $(this).attr('href') + ' #pageContent';
		
		//$('#contentPanel').css({ height: $('#contenPanel').height() });	

		$('#pageContent').fadeOut( 500, function(){
			$(this).remove()
		});
		
		if ($('#contentPanel').hasClass('panelHidden')){
			$('#placeholder').load(thePage, function(){
				//$('#contentPanel').css({ height: $('#pageContent').outerHeight() + 45 });
				$('#contentPanelInner').show();
				$('#contentPanel').animate({ left: '320px' }, 700, function(){
					$(this).removeClass().addClass('panelVisible');
					$('#togglePanelBt').text('Close');
					$('#pageContent').fadeIn( 500 );
				});
			});
		} else {
			$('#placeholder').load(thePage, function(){
				//$('#contentPanel').animate({ height: $('#pageContent').outerHeight() + 45 }, 500, function(){
					$('#pageContent').fadeIn( 500 );
				//});
			});
		}
		
		return false;
	});*/
	
	
	/*$('#subpageNav a').click(function(){
		var pageToShow = $(this).attr('href');
		alert(pageToShow);
		$('#contentPanel .currentPage .currentSubpage').fadeOut(700, function(){
																				  
		});
	});*/
	
	
	// External links
	$('a[rel*="external"], a[rel*="pdf"]"').click(function(){
		window.open(this.href);
		return false;
	});
	$('a[rel*="external"], a[rel*="pdf"]').attr('title', 'Opens in a new browser window'); 
});

$(window).load(function(){
					
});

function resizeDimArea(){
	var dimAreaOffset = $('#introPanel').outerWidth() + $('#contentPanel').outerWidth();
	//alert(dimAreaOffset);
	var dimAreaWidth = $(window).width() - dimAreaOffset;
	//alert(dimAreaWidth);
	$('#dimArea').css({ height: $(window).height(), left: dimAreaOffset, width: dimAreaWidth });
}
