/*
	Author:  Bruno Lenette
	Created: 16/12/2010
*/

/*
	Function when you click on travel destinations and travel experience
*/

$(document).ready(function() {
	
	// ## HEADER jquery ->
	// Add pipes to footer nav and make all content lowercase ->
	$("#footer li").not(".firstLink").prepend("|");
	// add date
   	var dateObj = new Date();
    	var year = dateObj.getFullYear();
	$("#footer li.firstLink").prepend("<span class='textBlack'>Lic No. 9TA1389 | Copyright " + year + " |</span>");
	
	if ($("#contentTools ul").html() !== null ) {
		// Split font sizing into two li elements
		$("#contentTools ul").html( $("#contentTools ul").html().replace( /a><a/i, "a></li><li><a" ) );
		
		// Add pipes to content tools
		$("#contentTools li").not(".firstUtilLink").prepend ("<span>|</span>");
	}
	
	$("#footer").append("<a href='http://ibc.com.au'>Site by IBC Solutions</a>");
	
	// Basic Search default value
	var defaultSearchValue = "Search:";

	$("#BasicSearch input").val(defaultSearchValue);
	$("#BasicSearch input").focus(function() {
		if ($(this).val() == defaultSearchValue)
			$(this).val("");
		});
	$("#BasicSearch input").blur(function() {
		if ( $(this).val() == "" ) {
			$(this).val(defaultSearchValue);
		}

		});
	
	//jQuery(".selectContainer select").select_skin();
	
	// Travel Select Boxes
	
	
	var originalExperiences = "url(/templates/travel_experience.png)";
	var selectedExperiences = "url(/templates/travel_experience_sel.png)";
	var originalDestination = "url(/templates/travel_destination.png)";
	var selectedDestination = "url(/templates/travel_destination_sel.png)";
	var hiddenNavTracker = 0;   // 0 - both closed
								// 1 - destinations open
								// 2 - experiences open
	
	$("#travel_destination").click(function(){
		
		switch (hiddenNavTracker) {
			case 0:
				// switch content
				$("#areaNav").show();
				$("#experienceNav").hide();
				$("#hiddenNavigation").animate({height:"show",opacity:"show"},400);
				$("#travel_destination").css( "background-image", selectedDestination );
				
				
				hiddenNavTracker = 1;
			break;			
			case 1:
				$("#hiddenNavigation").animate({height:"hide",opacity:"hide"},400);
				$("#travel_destination").css( "background-image", originalDestination );
				hiddenNavTracker = 0;
			break;
			case 2:
				$("#hiddenNavigation").animate({height:"hide",opacity:"hide"},400, function() {
					$("#hiddenNavigation").animate({height:"show",opacity:"show"},400);
					// switch content
					$("#areaNav").show();
					$("#experienceNav").hide();
				} );
				$("#travel_experience").css( "background-image", originalExperiences );
				$("#travel_destination").css( "background-image", selectedDestination );
				hiddenNavTracker = 1;
			break;	
		}
	});
	
	$("#travel_experience").click(function(){
		switch (hiddenNavTracker) {
			case 0:
				// switch content
				$("#areaNav").hide();
				$("#experienceNav").show();
				$("#hiddenNavigation").animate({height:"show",opacity:"show"},400);
				$("#travel_experience").css( "background-image", selectedExperiences );
				hiddenNavTracker = 2;
			break;
			case 1:
				$("#hiddenNavigation").animate({height:"hide",opacity:"hide"}, 400, function() {
					$("#hiddenNavigation").animate({height:"show",opacity:"show"},400);
					// switch content
					$("#areaNav").hide();
					$("#experienceNav").show();
				});
				$("#travel_experience").css( "background-image", selectedExperiences );
				$("#travel_destination").css( "background-image", originalDestination );
				hiddenNavTracker = 2;
			break;
			case 2:
				$("#hiddenNavigation").animate({height:"hide",opacity:"hide"},400);
				$("#travel_experience").css( "background-image", originalExperiences );
				hiddenNavTracker = 0;
			break;	
		}
	});
	
	/*
		Function to hide and show destination
	*/
	$(".destinationBox h3").click(function()
	{
	
		$(".destinationBox h3").removeClass("arrowUpDestination");
		
		$(".destinationBox .destinationList").animate({height:"hide",opacity:"hide"},400);
	
		if ($(this).next().is(":visible") == false) {
			$(this).next().animate({height:"show",opacity:"show"},400);
			$(this).addClass("arrowUpDestination");
		}
	});	
	
	var customNavigationSwitch = 0;
	
	/*if ($("#customNavigation") !== null) {
		if ($("#customNavigation").html().indexOf("ul") > -1) {
			$("#customNavigationToggle").show();
		}
	}*/
	
	$("#customNavigationToggle").click(function() {
		switch(customNavigationSwitch) {
			case 0:
			$("#customNavigation").slideDown();
			customNavigationSwitch = 1;
			break;
			
			case 1:
			$("#customNavigation").slideUp();
			customNavigationSwitch = 0;
			break;
		}
		
	});
	
	/* IE rounded corners */ 	
	
	if($.browser.msie)
	{
		jQuery.support.borderRadius = false;
		jQuery.each(['BorderRadius','MozBorderRadius','WebkitBorderRadius','OBorderRadius','KhtmlBorderRadius'], function() {
			if(document.body.style[this] !== undefined) jQuery.support.borderRadius = true;
			return (!jQuery.support.borderRadius);
		});
		
		if( ! $.support.borderRadius)
		{
			$(".tcmFormTitleBanner, .dynamicFormTitle, .dFormHeaderText").append('<span class="tl nCorner"></span><span class="tr nCorner"></span><span class="bl nCorner"></span><span class="br nCorner"></span>');			
		}
	}
	
	// Hide empty sub title dynamic form divs
	$(".dynamicFormSubTitle").each( function () {
		if ( $(this).html().length == 0 )
		{
			$(this).hide();
		}	
	});
	
	
	/* Style file inputs if plugin is available */
	if(jQuery().filestyle) {
		$("input[type=file].filestyle").filestyle({
	        image: "/templates/browse.gif",
	        imageheight: 23,
	        imagewidth: 93,
	        width: 180,
	        paddingLeft: 5
	    });
	  
	  $(".dFormField input[type=file]").filestyle({
	        image: "/templates/browse.gif",
	        imageheight: 23,
	        imagewidth: 93,
	        width: 180,
	        paddingLeft: 5
	    }); 
	   
	}
	
	
	// Default Cycling
	$('.jCycle').cycle(); 
	
	// Some Random Element Styling + Functionality hax
	
	$(".maxFiddy").attr("maxlength", "50");
	$(".maxQuattro").attr("maxlength", "4");
	
	// travel enquiry form
	$("#defaultControl_ctl00_segment147_ctl00_place158_ctl00_travelEnquiry_firstName, #defaultControl_ctl00_segment147_ctl00_place158_ctl00_travelEnquiry_lastName, #defaultControl_ctl00_segment147_ctl00_place158_ctl00_travelEnquiry_phoneNumber, #defaultControl_ctl00_segment147_ctl00_place158_ctl00_travelEnquiry_emailAddress").attr("maxlength", "50");
	$("#defaultControl_ctl00_segment147_ctl00_place158_ctl00_travelEnquiry_agentDescription").attr("maxlength", "200");
	
	$("#defaultControl_ctl00_segment147_ctl00_place158_ctl00_travelEnquiry_postCode").attr("maxlength", "4");
	
	//$("#defaultControl_ctl00_segment147_ctl00_place159_ctl00_divInlineContentOutput").cycle(); 
	
	
	/* MEX Logged in user elements */
	
	if ($(".strLoginSummaryUserName").length > 0) {
		//add tick is now done through loginDetails module (custom)
		//$("#agentNavigation ul").prepend( '<li id="agentTick"><a href="http://headoffice.travellerschoice.com.au/" target="_blank"><img src="/templates/tick.gif" alt="Visit TC Direct" /></a></li><li class="firstAgentNav"><div id="welcomeAgent">Welcome ' + $(".strLoginSummaryUserName .strLoginSummaryUserFirstName").html() + ':</div></li>' );
		
		// move login stuff to fron of mex menu.
		
		
		
	}
	else {
		$("#agentNavigation ul").prepend( '<li class="firstAgentNav"><div id="welcomeAgent">not logged in:</div></li>');
			
		/* Hides Agent Naviagation */
		$("#agentNavigation").hide();
	}

/* Hide / Show Directory Item Terms and Conditions */
	$(".tacLink").click(function() {
		$(".directoryItemTAC").toggle(400);	
	});
	
	if ( $(".similar").length > 0 ) {
		$(".noResultsLink").hide();
	}
	
function fancyStart() {
	// reset the form	
}

	$(".fancybox").fancybox(
	{
		'autoDimensions'	: false,
		'width'         	: 680,
		'scrolling'			: 'auto',
		'height'        	: '80%',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'onStart'			: fancyStart
	});

/* Hacketty hack - Search Results sortBy */
$(".ascOrder").siblings("input").css("background-image", "url(/templates/sort-up.gif)");

/* Hacketty hack - Directory item form fancybox
	
	var postCodeFormRef;
	
	function fancyClose() {
		$(".directoryItemContentDetailed").append("<div id=contactAgent>" + postCodeFormRef + "</div>");
	}
	
	$(".directoryItemForm button").click(function() {
		
		postCodeFormRef = $('#contactAgent').html();
		
		// when the directoryItem form button is clicked move the content of the results div into a new popup.overlay
		$.fancybox(
		' ',
		{
        	'autoDimensions'	: false,
			'width'         	: 680,
			'scrolling'			: 'yes',
			'height'        	: '80%',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'onClosed'   		: fancyClose
		});
		
		if (('#fancybox-content:empty').length > 0) {
			$('#contactAgent').detach().prependTo($('#fancybox-content'));
		}
	});	*/
	
});
