jQuery(document).ready(function(){ 

	//var newObject = Cruise({url:"dddd.php"});
/**
*/	
 jQuery("#orange").tooltip({position:"center right", events: {
   def:     "click,mouseout"
}

});
/**
Form Loader when ajax is called for populating any fields
*/
 jQuery('#fadeOutFormOverlay').ajaxStart(function() {
 
					if ($.browser.msie) {
					    jQuery('#overlayForm').bgiframe({top:0, left:0});					
				     }
					  jQuery('#overlayForm').addClass('overlayForm').fadeTo('fast', 0.5).css('display', 'block').css('height', jQuery(this).height()+"px").css('width', jQuery(this).width()+"px");
						 jQuery('#loadingCalenderOverlay').removeClass('loadingCalenderHide').addClass('loadingCalender');
});	

		 		 jQuery('#fadeOutFormOverlay').ajaxStop(function() {				    
					jQuery('#overlayForm').css('height', 0+"px").css('width', 0+"px").removeClass('overlayForm').fadeTo('fast', 0.5).css('display', 'none');
				      jQuery('#loadingCalenderOverlay').removeClass('loadingCalender').addClass('loadingCalenderHide'); 
				    //  jQuery('#fadeOutCalenderOverlay').unbind('ajaxStart');			
 });
				
//End of loader functionality

	jQuery("#selectdestination").change(function(){
	 var destination = $(this).attr("value");
    /*$.AjaxWrapper.url="";
	$.AjaxWrapper.data="text";
	$.AjaxWrapper.requestType="get";
	$.AjaxWrapper.data="action=retrieveLiners";
	$.AjaxWrapper.ajaxRequest();*/
	jQuery.ajax({

		   type: "get",
		   url:  HOSTURL+"cruise/index.php",
		   data: "action=retrieveLiners&destination="+destination,
		   success: function(msg){
		   //jQuery("#linersSelection").html(msg);
		    jQuery("#selectcruiseliner").html("");
		   jQuery("#selectcruiseliner").append(msg);

		   }
		 });
		jQuery.ajax({
		   type: "get",
		   url:  HOSTURL+"cruise/index.php",
		   data: "action=retrieveDepartingDates&destination="+destination,
		   success: function(msg){	
		    // jQuery("#selectDepartingDates").html("");		
		
		    jQuery("#selectdepdate").html("");
				jQuery("#selectdepdate").append(msg);
            jQuery("#selectcruiseliner").change();

		   }
		 });
		 	 

	});
  /**
	*Functionality for populating ports thorugh Ajax.
	*
	*/

		jQuery("#selectcruiseliner").change(function(){
 	    var destination = $("#selectdestination").attr("value");
	     var liner = $(this).attr("value");
	 
	     jQuery.ajax({
		   type: "get",
		   url:  HOSTURL+"cruise/index.php",
		   data: "action=retrievePorts&destination="+destination+"&liner="+liner,
		   success: function(msg){
		 //  jQuery("#portsSelection").html(msg); 
		   jQuery("#selectdepartfrom").html("");
		   jQuery("#selectdepartfrom").append(msg);
		   }
		 });	 
	 });
	/**
	*Functionality for displaying no of cabins details on change of no of cabin's value.
	*
	*/
	jQuery("#cabins").change(function(){
	    var valueOfCabins = jQuery(this).attr("value");
		if(valueOfCabins == "2"){
		      jQuery("#cabin_2").show();
		}else{
		      jQuery("#cabin_2").hide();
		}
	});
	
	/**
	*Functionality for displaying child age option box for selected number of child.
	*
	*/
	jQuery("#childs_1").change(function(){
	    var valueOfCabins = jQuery(this).attr("value");
		var totalCountOfCabin = 3;
		if( parseInt(valueOfCabins) == 0){
			jQuery("#child_agetext_1").css("visibility", "hidden");
			jQuery("#choose_child1_1").addClass("display_block").css("visibility", "hidden");
		//jQuery("#choose_child1_1").addClass("display_block").show();
		for ( var i=2; i <= totalCountOfCabin; i++ ) {
			    jQuery("#choose_child1_"+i).addClass("display_block").addClass("display_none").hide();
			  }
		}else{
				    jQuery("#child_agetext_1").css("visibility", "visible");
					jQuery("#choose_child1_1").addClass("display_block").css("visibility", "visible");
					for ( var i=1; i <= totalCountOfCabin; i++ ) {
						  if( i <= parseInt(valueOfCabins) ) {
							jQuery("#choose_child1_"+i).addClass("display_block").show();
						  }else{
							jQuery("#choose_child1_"+i).removeClass("display_block").addClass("display_none").hide();
						  }
				  }    
		}
	});


	jQuery("#childs_2").change(function(){
	    var valueOfCabins = jQuery(this).attr("value");
		var totalCountOfCabin = 3;
		if( parseInt(valueOfCabins) == 0){
			jQuery("#child_agetext_2").css("visibility", "hidden");
			jQuery("#choose_child2_1").addClass("display_block").css("visibility", "hidden");
		for ( var i=2; i <= totalCountOfCabin; i++ ) {
			    jQuery("#choose_child2_"+i).addClass("display_block").addClass("display_none").hide();
			  }
		}else{
				jQuery("#child_agetext_2").css("visibility", "visible");
				jQuery("#choose_child2_1").addClass("display_block").css("visibility", "visible");
				for ( var i=1; i <= totalCountOfCabin; i++ ) {
		      if( i <= parseInt(valueOfCabins) ) {
			    jQuery("#choose_child2_"+i).addClass("display_block").show();
			  }else{
			    jQuery("#choose_child2_"+i).removeClass("display_block").addClass("display_none").hide();
			  }
           }    
		}
	});
		/**
	*Functionality for validation of the search form.
	*
	*/
	// adds an effect called "wall" to the validator
	var errorMessages = new Array();
	errorMessages ["selectdestination"] = "Please select destination.";
	errorMessages ["selectdepdate"] = "Please select departing date.";
	// initialize validator with the new effect
	$("#main_form_area").validator({
		errorInputEvent: null   
	}).bind("onFail", function(e, els ) {
		var errorMessagesString = "";
		$.each(els, function(index, els) {
		//alert(els.input.attr("value"));
		 errorMessagesString += "<li>" +errorMessages[els.input.attr("name")]+ "</li>";			
		});

		jQuery.facebox('<div style="width:400px;"><div class="floatr" style="margin:5px 5px 0 0; width:100px; "><a href="javascript:;" class="colorgrey bold text11 closeicon" style="text-decoration:none;float:right;" onclick="$(document).trigger(\'close.facebox\');" ></a>&nbsp;</div><div class="clear"><div class="error-page-alert"><span class="ezee">ezee</span><span class="alert">alert</span><br/><div class="alertimg padl20">&nbsp;</div></div><div class="error-page-main_content"><div class="error_content"><ul class="error_content">'+errorMessagesString+'</ul></div></div><div class="clear">&nbsp;</div></div></div>');
	
}).submit(function(e)  { 
			// when data is valid 
		if (!e.isDefaultPrevented()) {
			jQuery("#main_form_area").append(jQuery("#productForm").html());
			// tell user that everything is OK
			//  $("#errors").html("<h2>All good</h2>");
			// prevent the form data being submitted to the server
			//e.preventDefault();
		} 
});

	jQuery("#cruiseSearchFormSubmit").click(function(){ 
$("#main_form_area").trigger("submit");
	});
	
	

	$("#accordion").accordion({
		autoHeight: false,
		event: "mouseover"
	});
	// select #flowplanes and make it scrollable. use circular and navigator plugins
	$("#flowpanes").scrollable({ circular: true }).navigator({
		// select #flowtabs to be used as navigator
		navi: "#flowtabs",
		// select A tags inside the navigator to work as items (not direct children)
		naviItem: 'a',
		// assign "current" class name for the active A tag inside navigator
		activeClass: 'current',
		// make browser's back button work
		history: true
	}).autoscroll({ interval: 5000 });
	/**
	*Functionality for displaying child age option box for selected number of child.
	*
	*/
	//$("#location-city").bind();
	$("#location-city,ul.destinationTabs").tabs("div.destinationDealsContainer > div", {event:'mouseover'});

	//$("ul.destinationTabs").tabs("div.destinationDealsContainer > div", {event:'mouseover'});
	

});
function goToLinks(url,width)
{
	window.open(url,'','scrollbars=yes,width='+width+',height=620'); 
	return false;
	}
function getPorts()
{
  	 var destination = $("#selectdestination").attr("value");
	 var liner = $("#selectcruiseliner").attr("value");
	 
	  jQuery.ajax({
		   type: "get",
		   url:  HOSTURL+"cruise/index.php",
		   data: "action=retrievePorts&destination="+destination+"&liner="+liner,
		   success: function(msg){
		 //  jQuery("#portsSelection").html(msg); 
		   jQuery("#selectdepartfrom").html("");
		   jQuery("#selectdepartfrom").append(msg);
		   }
		 });
}

(function($){
  $.AjaxWrapper = {
	
	url:"",	
	requestType:"",	
	loader:"",	 
	loadingElement:"",	
	data:"",	
	dataType:"",
	successContainer:"",
	loaderShow:false,
	
	ajaxRequest:function(){
	
	this.ajaxLoaderStart();
	$.ajax({
		   type: this.requestType,
		   url:  this.url,
		   data: this.data,
		   success: function(msg){
		    $.AjaxWrapper.ajaxLoaderStop();
		     alert( "Data Saved: " + msg );
		   }
		 });	
    },

    ajaxLoaderStart:function(){
    	if(this.loaderShow = true)
    	{
           $(this.loadingElement).ajaxStart(function(){
    		   $(this).show();
    		 });
    	}
    }
	,
    ajaxLoaderStop:function(){ 
    	if(this.loaderShow = true)
    	{
            $(this.loadingElement).ajaxStop(function(){
        	   $(this).hide();
        	 });
    	}
    },
	
	test :function(){
		alert("asd");
	}
}
  
})(jQuery);