// Default JavaScript for SydneySkydivers.com.au - Gerard Dunning (gerard@digitalskydive.com)


var mainContent;
var msgContent;


function initPage() {
  mainContent = $( "#content" );
  msgContent = $( "#msg" ); 
  
  initLinks();	 

} 

function initLinks() {
	
  //Static Pages
  $('.navGen').unbind('click');
  $(".navGen").click(function(event) {
	  event.preventDefault();
	  $(this).blur();
	  var page = $(this).attr('data');
      getContent($("#content"), "page.php", "page="+page);
  });  
  
  //Pop-Up Widgets
  $('.navBook').unbind('click');
  $(".navBook").click( function(event) {
 	event.preventDefault();
	$(this).blur();
	var id = $(this).attr('data');
    bk_win(id);
    return false;
  });
  $('.navVoucher').unbind('click');
  $(".navVoucher").click( function(event) {
	event.preventDefault();
	$(this).blur();
    gv_win();
    return false;
  });  
  
  //Dynamic Pages
  $('.navLocation').unbind('click');
  $(".navLocation").click( function(event) {
 	event.preventDefault();
	$(this).blur();
	var id = $(this).attr('data');
	var params = "loc="+id;
    getContent($("#content"), "location.php", params);
  }); 
  
  $('h2 a').smoothScroll();
  
  $('.info').mouseenter(
    function () {
	 $("#prodList").find(".desc").fadeOut(250); 	
      var id = $(this).attr('data');
	  $("#p_"+id).fadeIn(300);
    } 
  );
  
  $(document).pngFix(); 	 	
}

function getContent(obj, source, params, callback) { 
   $.ajax({
  	  url: source,
	  data: params,
	  cache: "true",
	  dataType: "html",
	  error: function(){
		showMessage("Service Currently Unavailable");
		setStatus("Error: "+source,false);
	  },
	  beforeSend: function(){
		 setStatus("Communicating...",true);
 	  },
	  complete: function(){
		 _gaq.push(['_trackPageview', '/'+source+'?'+params]); 
		 setStatus("",false);  
	  },
	  success: function( data ) {
	    obj.html(data);
		if (typeof callback == "function") callback();
		if (data.indexOf("<") > -1) { 
		  obj.find("input:text:visible:first").select().focus();
		  if (obj.find("div").length) { 
		    obj.fadeIn(300, function() {
		  	    $.smoothScroll({scrollTarget: '#top'});
			});
		  }
		  initLinks();
		} else {
		  showMessage(data);	
		}
	  }
	});
}

function showMessage(msg) {
   if (msg) {	
	 msgContent.html( msg );
	 msgContent.slideDown(300).delay(3000).fadeOut(400);
   }
}

function setStatus(msg, wait) {
   $("#status").html(msg);
   if (wait) {
	  $("#wait").fadeIn(300);
   } else {
	  $("#wait").fadeOut(700); 
   }
}

function make_YouTube(id) {
	var data = '<object><param name="movie" value="http://www.youtube.com/v/' + id + '&rel=0&hl=en_US&feature=player_embedded&version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/' + id +'&rel=0&hl=en_US&feature=player_embedded&version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="300" height="200"></embed></object>';
	$('#youtube').html(data);
}

function bk_win(loc) {
   window.open('http://bookings.sydneyskydivers.com.au/public.php?loc='+loc,'bookings', 'width=820,height=700,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=no');
}

function gv_win() {
   window.open('http://bookings.sydneyskydivers.com.au/gv.php','bookings','width=817,height=700,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=no');
}
