/* Author:

*/


//console.log("outside jQuery");
function hideMenu()
{
	
}

function initHideMenu(delay)
{
	$.doTimeout( 'loop', delay, function(){
		$('.gallery header').addClass('hide');
    	return false;
  	});
}

			// pre-submit callback 
			function showRequest(formData, jqForm, options) { 
				//console.log(options);
			    // formData is an array; here we use $.param to convert it to a string to display it 
			    // but the form plugin does this for you automatically when it submits the data 
			    //var queryString = $.param(formData); 
			 
			    // jqForm is a jQuery object encapsulating the form element.  To access the 
			    // DOM element for the form do this: 
			    // var formElement = jqForm[0]; 
			 
			   // alert('About to submit: \n\n' + queryString); 
			 
			    // here we could return false to prevent the form from being submitted; 
			    // returning anything other than false will allow the form submit to continue 
			    //return true; 
			} 
			 
			// post-submit callback 
			function showResponse(responseText, statusText, xhr, $form)  { 
			    // for normal html responses, the first argument to the success callback 
			    // is the XMLHttpRequest object's responseText property 
			 
			    // if the ajaxForm method was passed an Options Object with the dataType 
			    // property set to 'xml' then the first argument to the success callback 
			    // is the XMLHttpRequest object's responseXML property 
			 
			    // if the ajaxForm method was passed an Options Object with the dataType 
			    // property set to 'json' then the first argument to the success callback 
			    // is the json data object returned by the server 
			 
			    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
			        '\n\nThe output div should have already been updated with the responseText.'); 
			} 

			function processJson(data,status,xhr,form) {
				if (data.error) {
					$('.alert-message p').html(data.error);
					$('.alert-message').addClass('warning');
					$('.alert-message').show();
				} else {
					$('.alert-message p').html(data.message);
					$('.alert-message').addClass('success');
					$('.alert-message').show();
					$('#contact').clearForm();
				}
			}

(function(doc) {

	var addEvent = 'addEventListener',
	    type = 'gesturestart',
	    qsa = 'querySelectorAll',
	    scales = [1, 1],
	    meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];

	function fix() {
		meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
		doc.removeEventListener(type, fix, true);
	}

	if ((meta = meta[meta.length - 1]) && addEvent in doc) {
		fix();
		scales = [.25, 1.6];
		doc[addEvent](type, fix, true);
	}

}(document));

jQuery(function($){
	
	//$(window).unload( function () { alert("Bye now!"); } );
	//console.log("inside jQuery");

	$('#supersized').load(function() {
		//console.log("Supersized load");
	});

	$(window).load(function() {
		//console.log("Window load");
	});
		
	$(document).ready(function() {

		//console.log("Document ready");
		//$('body').css('display', 'none');
		//$('body').fadeIn(6000);
		//console.log('transition',$.support);
		if ($.support.transition)
    		$.fn.animate = $.fn.transition;// = $.fn.animate;

		var html = $('html').addClass('ready');
		//html;
		/*imageFiles = $('#supersized > li > a > img');
		pictures = $('#gallery > img ');
		console.log(pictures);
		console.log(photos);
		console.log('start----------------------');*/
/*		$.doTimeout( 'loop', 5000, function(){
			console.log("hide menu");
			$('nav').addClass('hide');
    		return false;
  		});*/
//  		console.log(location.hash.slice(1));
		initHideMenu(5000);

		//var t = setTimeout(hideMenu,4000);

		var submenu = $(".submenu > div");
		var margin = -(submenu.width()/2);
		submenu.css('margin-left',-(submenu.width()/2));
		
		/*
		 * add animation fade out on click event
		 */
		/*$("a.fade").click(function(event){
	        event.preventDefault();
	        linkLocation = this.href;
	        $('#supersized').fadeOut(700);
	        $("body").fadeOut(700, 'easeOutQuart', function() {
			    window.location = linkLocation;
			});
	    });*/

/*
	 * fade in
	 */
	/*$('body').fadeIn(500,'easeInQuart', function() {
		
	        // Animation complete
	});*/


		$(".gallery header").hover(
  			function () {
  				$('.gallery header').removeClass('hide');
  				$.doTimeout( 'loop', true );
  			},
  			function () {
  				$.doTimeout( 'loop', true );
  				initHideMenu(1000);
  			}
		);

		


		/*$.delay(5000, function(){
			console.log('test');
			$('nav').addClass('hide');
			//Do anything after 1 second
		});*/
		
		/*$('.link').click(function() {
			event.preventDefault();
			newLocation = this.href;
			$('body').fadeOut(1000, newpage);
		});
		function newpage() {
			window.location = newLocation;
		}

		function redirectPage() {
 			window.location = linkLocation;
		} 

   		$('a').click( function( event ){
        	if( this.href == "" || this.href == null ) { event.preventDefault(); return; }
        	if( (this.href.indexOf("#") == -1) && (this.href.indexOf("mailto:") == -1) && (this.href.indexOf("javascript:") == -1) && (this.target != "_blank")) {
            	event.preventDefault();
            	linkLocation = this.href;
            	$("body").fadeOut(600, redirectPage);
        	}
    	}); 
    
    
    	$('.top').click(function(){
        	$('html, body').animate({scrollTop:0}, 'slow');
        	return false;
    	});

		// add animation fade out on click event
	 	
		$("a.transition").click(function(event){
	        event.preventDefault();
	        linkLocation = this.href;
	        $("body").fadeOut(700, 'easeOutQuart', function() {
			    window.location = linkLocation;
			});
	    });
	    */

	    if ($('form').length) {
	    	// prepare the form when the DOM is ready 
		
			    var options = { 
			       /* target:        '#msg',*/   // target element(s) to be updated with server response 
			        beforeSubmit:  showRequest,  // pre-submit callback 
			        success:       processJson,  // post-submit callback 
			 		dataType:      'json'
			        // other available options: 
			        //url:       url         // override for form's 'action' attribute 
			        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
			        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
			        //clearForm: true        // clear all form fields after successful submit 
			        //resetForm: true        // reset the form after successful submit 
			 
			        // $.ajax options can be used here too, for example: 
			        //timeout:   3000 
			    }; 
			 
			    // bind form using 'ajaxForm' 
			    $('#contact').ajaxForm(options); 
			
	    };

	    var startSlide = location.hash.slice(1);

		 if ($('.gallery').length) { // implies *not* zero
    

			$.supersized({
			
				// Functionality
				slideshow               :   1,			// Slideshow on/off
				autoplay				:	1,			// Slideshow starts playing automatically
				start_slide             :   startSlide,			// Start slide (0 is random)
				stop_loop				:	0,			// Pauses slideshow on last slide
				random					: 	0,			// Randomize slide order (Ignores start slide)
				slide_interval          :   6000,		// 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		:	500,		// Speed of transition
				new_window				:	0,			// 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			:	1,			// Disables image dragging and right click with Javascript
														   
				// Size & Position						   
				min_width		        :   0,			// Min width allowed (in pixels)
				min_height		        :   0,			// Min height allowed (in pixels)
				vertical_center         :   1,			// Vertically center background
				horizontal_center       :   1,			// Horizontally center background
				fit_always				:	0,			// Image will never exceed browser width or height (Ignores min. dimensions)
				fit_portrait         	:   1,			// Portrait images will not exceed browser height
				fit_landscape			:   0,			// Landscape images will not exceed browser width
														   
				// Components							
				slide_links				:	'blank',	// Individual links for each slide (Options: false, 'number', 'name', 'blank')
				thumb_links				:	0,			// Individual thumb links for each slide
				thumbnail_navigation    :   0,			// Thumbnail navigation
								

				progress_bar			:	0,			// Timer for each slide							
				mouse_scrub				:	0,
																			   
				// Components							
				slides 					:  	photos
			});	

  		} else {
		    $.supersized({
				slides  :  	[ {image : '/img/bg.jpg', title : ''} ]
			});
   
		}

	});

});
