var start = "1"; 
$(document).ready(function(){
    var IE = /*@cc_on!@*/false;
    /************* START ONLINEAGENCY ***********
    $("a[href^=http://content.onlineagency.com/]").click( function() {
        var address = $(this).attr("href");
        address = address.slice(address.indexOf(".com/")+5); 
        var newAddress = window.location.toString();
        newAddress = newAddress.substr(0,newAddress.indexOf("ext")+4) + address;
        $(this).attr("href",newAddress);
    });
    /************* END ONLINGEAGENCY ************/
    /************* START SORT        ************/
    $("#nextSort").click( function() {
        start = parseInt($("#start").val())+1;
        $("#sortSubmit").click();        
    });
    $("#prevSort").click( function() {
        start = parseInt($("#start").val())-1;
        $("#sortSubmit").click();        
    });
    $("#sortSubmit").click( function() {
        var type             = $("#sortType").val();
        var order            = $("#sortOrder").val();
        var direction        = $("#sortDirection").val();
        var sortCruiseline   = $("#sortCruiseline").val();
        var sortDestination  = $("#sortDestination").val();
        var sortNumberOfDays = $("#sortNumberOfDays").val();
        var sortMonth        = $("#sortMonth").val();
        $("#deals").fadeOut("fast", function() {
            var height = $(this).height();
            $(this).css({'height':height});
            $(this).animate({'height':'40'});
            $(this).html("<p>Loading results...</p>").fadeIn("fast").css({'height':'auto'});    
        });
        var requestString = "&mode=sort&start="+start+"&type="+type+"&order="+order+"&direction="+direction+"&cruiseline="+sortCruiseline+"&destination="+sortDestination+"&numberOfDays="+sortNumberOfDays+"&month="+sortMonth;
        $.ajax({  
            type: "POST",  
            url: "sort.php",  
            data: requestString, 
            success: function(text) {
                $("#deals").replaceWith(text).stop().fadeTo("fast",1);
            },
            error: function() {
                $("#deals").replaceWith("<p>An error has occurred.  Please try again in a few moments.</p>").stop().fadeTo("fast",1); 
            }  
        }); 
    });
    /************* END SORT          ************/
    /************* START NAVIGATION *************/
    $("div[id^=nav-hover-]").hide();
    $("a[id^=nav-control-]").mouseenter( function() {
        var id = $(this).attr('id');
        id = id.substr(12);
        if (IE) {
            $("#nav-hover-"+id).stop(true).show(1); 
        } else {
            $("#nav-hover-"+id).stop(true).fadeTo(200,1);     
        }
    });
    $("a[id^=nav-control-]").mouseleave( function() {
        var id = $(this).attr('id');
        id = id.substr(12);
        if (IE) {
            $("#nav-hover-"+id).delay(2).hide(1);    
        } else {
            $("#nav-hover-"+id).fadeTo(200,0).delay(200).hide(1); 
        }
    });
    $("div[id^=nav-hover-]").mouseenter( function() {
        if (IE) {
            $(this).stop(true).show(1);     
        } else {
            $(this).stop(true).fadeTo(100,1).show(1); 
        }
        var id = $(this).attr('id');
        id = id.substr(10);
        $("#nav-control-"+id).addClass('active');
    })
     $("div[id^=nav-hover-]").mouseleave( function() {
        if (IE) {
            $(this).delay(2).hide(1);    
        } else {
            $(this).fadeTo(200,0).delay(200).hide(1);       
        }
        var id = $(this).attr('id');
        id = id.substr(10);
        $("#nav-control-"+id).removeClass('active');
    })  
    /************* END NAVIGATION *************/
    /************* START CSS FIXES ************/
    $('.sidebar-email input:text').each( function() {
        if (!IE) { $(this).css({'width':'160px'}); }
    });
    $('#ajaxSearch_form input:text').each( function() {
        if (!IE) { $(this).css({'width':'123px'}); }    
    });
    $('input:text').click( function() {
        if ($(this).val() == $(this).attr('defaultValue') ) {
            $(this).val("");
        }
    });
    $('input:text').blur( function() {
        if ($(this).val() == "" ) {
            $(this).val($(this).attr('defaultValue'));
        }        
    });
    $("#sidebar .sidebar-email a").click( function() {
        $("#addEmail").submit();
    });
    // Provided by CruisePlus
    /*$('h3.question').click( function() {
        $(this).next().slideToggle();
    }).next().hide(); */
    $('#about .question h3').click( function() {
        $(this).parent().children(".answer").slideToggle("fast");
    });
    /*$("#about h2").click( function() {
        $(this).parent().children(".question").slideToggle("fast");   
    });*/
    $("#about .question .answer").hide();
    /************* END CSS FIXES  *************/
	
		    /************* START tab *************/
$(document).ready(function() {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

});
	
/************* END TAB         ************/	
	
	
    /************* START GALLERY **************/
	var totWidth=0;
	var positions = new Array();
	
	$('#slides .slide').each(function(i){
		positions[i]= totWidth;
		totWidth += $(this).width();
		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
	});
	
	$('#slides').width(totWidth);
	/* Change the cotnainer div's width to the exact width of all the slides combined */
	$('#menu ul li a').click(function(e,keepScroll){
			$('li.menuItem').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');
			var pos = $(this).parent().prevAll('.menuItem').length;
			$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
			/* Start the sliding animation */
			e.preventDefault();
			/* Prevent the default action of the link */
			// Stopping the auto-advance if an icon has been clicked:
			if(!keepScroll) clearInterval(itvl);
	});
	
	$('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */
	/*****
	 *
	 *	Enabling auto-advance.
	 *
	 ****/
	var current=1;
	function autoAdvance()
	{
		if(current==-1) return false;
		$('#menu ul li a').eq(current%$('#menu ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
		current++;
	}

	// The number of seconds that the slider will auto-advance in:
	var changeEvery = 10;
	var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);
	/* End of customizations */
    /************* END GALLERY *************/
});


$(document).ready(	
			function() {
				$(".container").wtRotator({
					width:640,
					height:300,
					button_width:24,
					button_height:24,
					button_margin:5,
					auto_start:true,
					delay:5000,
					transition:"random",
					transition_speed:800,
					cpanel_position:"inside",
					cpanel_align:"BR",
					timer_align:"top",
					display_thumbs:true,
					display_dbuttons:true,
					display_playbutton:true,
					display_numbers:true,
					display_timer:true,
					mouseover_pause:false,
					cpanel_mouseover:false,
					text_mouseover:false,
					text_effect:"fade",
					text_sync:true,
					tooltip_type:"image",
					shuffle:false,
					block_size:75,
					vert_size:55,
					horz_size:50,
					block_delay:25,
					vstripe_delay:75,
					hstripe_delay:180					
				});
			}
		);



   /************* START TRACKING **************/
   


  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-17290448-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();




       /************* END TRACKING *************/

