jQuery( function( $ ){
    
    // rotate destination names in the example text underneath the destination text input
    if ( $( '#CityToExample' ).html() )
    {
        var examples = new Array('Sydney' , 'London' , 'Melbourne', 'Bangkok', 'Los Angeles', 'Brisbane', 'Auckland', 'Perth', 'Bali', 'Adelaide', 'Singapore', 'Gold Coast', 'Hong Kong', 'Canberra', 'Fiji' );
        var index = 1;
        setInterval( function(){
            if( index >= examples.length ) index = 0;
            $( '#CityToExample' ).html( 'e.g. <strong>' + examples[index].toString() + '</strong>'  );
            index++;
        }, 3000 );
    };
    
    // handle trip type selection (trip type radion button click handling)
    $( 'input[name=TripType]' ).click( function()
    {
        // one way is clicked
        if ($(this).val() == 'OneWay' )
            $( '#cal_dateback' ).css( 'visibility', 'hidden' );
        else
            $( '#cal_dateback' ).css( 'visibility', 'visible' );
        
        // multicity or round australis is clicked - send into TSA straight away
        if ($(this).val() == 'Multi City/Stopover' || $(this).val() == 'Round Australia' )
        {
            document.location.href = 'http://nz.webjet.co.nz/WebjetTSA/home.aspx?EntryPoint=Flight&RequestFrom=Outside&TripType=Multi';
        }
    });
    
    // handle the expanding and contracting side menus
    $( '#helpful-links, #my-account' )
        .find( 'ul' ).hide()
        .end()
        .find( 'h3' )
        .css( 'cursor', 'pointer' )
        .hover(
            function(){
                $( this ).addClass( 'hover' )
            },
            function(){
                $( this ).removeClass( 'hover' )
            }
        )
        .prepend( '<img src="/site/images/linkbuttons/plus.gif" style="position: relative; left: -7px;" />')
        .end()
        .find( 'h3' )
        .toggle( 
            function(){
                $( this ).find( 'img').attr( 'src', '/site/images/linkbuttons/minus.gif' )
                $( 'ul', $(this).parent() ).slideDown();
            },
            function(){
                $( this ).find( 'img').attr( 'src', '/site/images/linkbuttons/plus.gif' )
                $( 'ul', $(this).parent()  ).slideUp();
            }
        );
        
    $( 'div.online-answers-box' )
        .find( 'h3' )
        .css({
            cursor: 'pointer'
        })
        .hover(
            function(){
                $( this ).addClass( 'hover' )
            },
            function(){
                $( this ).removeClass( 'hover' )
            }
        )
        .prepend( '<img src="/site/images/linkbuttons/minus.gif" style="position: relative; left: -7px;" />')
        .end()
        .find( 'h3' )
        .toggle( 
            function(){
                $( this ).find( 'img').attr( 'src', '/site/images/linkbuttons/plus.gif' )
                $( 'form', $(this).parent()  ).slideUp();
            },
            function(){
                $( this ).find( 'img').attr( 'src', '/site/images/linkbuttons/minus.gif' )
                $( 'form', $(this).parent()  ).slideDown();
            }
        );
    
    
    	try{
    	
	
	$('#topTab1').click(function(){
		$( '#fragment-1' ).show();
		$( '#fragment-2' ).hide();
		$( '#fragment-3' ).hide();
		$('#topTab1').css({background: 'url(/site/images/homepage_tabs/tmp/tab_1_1.jpg) bottom no-repeat'});
		$('#topTab2').css({background: 'url(/site/images/homepage_tabs/tmp/tab_2_1.jpg) bottom no-repeat'});
		$('#topTab3').css({background: 'url(/site/images/homepage_tabs/tmp/tab_3_1.jpg) bottom no-repeat'});

	});
	$('#topTab2').click(function(){
		$( '#fragment-1' ).hide();
		$( '#fragment-2' ).show();
		$( '#fragment-3' ).hide();
		$('#topTab1').css({background: 'url(/site/images/homepage_tabs/tmp/tab_1_2.jpg) bottom no-repeat'});
		$('#topTab2').css({background: 'url(/site/images/homepage_tabs/tmp/tab_2_2.jpg) bottom no-repeat'});
		$('#topTab3').css({background: 'url(/site/images/homepage_tabs/tmp/tab_3_2.jpg) bottom no-repeat'});

	});
	$('#topTab3').click(function(){
		
		location = 'http://nz.webjet.co.nz/webjettsa/home.aspx?EntryPoint=Hotel';
		
		return;
	
		$( '#fragment-1' ).hide();
		$( '#fragment-2' ).hide();
		$( '#fragment-3' ).show();
		$('#topTab1').css({background: 'url(/site/images/homepage_tabs/tmp/tab_1_3.jpg) bottom no-repeat'});
		$('#topTab2').css({background: 'url(/site/images/homepage_tabs/tmp/tab_2_3.jpg) bottom no-repeat'});
		$('#topTab3').css({background: 'url(/site/images/homepage_tabs/tmp/tab_3_3.jpg) bottom no-repeat'});
	});
	
	

		$('#bottomRight .mod_promobox img').each(function(){$(this).dropShadow(1,1,0)});
		$('#intl-australia').each(function(){
			intl_spec_move("#intl-australia", "right");
			intl_spec_move("#intl-nz", "right");
		});
		$('.int-special-image').each(function(){$(this).dropShadow(1,1,0)});

	}
	catch(ex)
	{
	
	}
	
	
});


function intl_spec_move(object, position)
{
	var eleOffset = $(object).position();
	var newLeft = 0;
	var newTop = 0;
	var padding = 6;
	if(position == "bottom")
	{
		newLeft = eleOffset.left + ($(object).width() / 2) + (padding/2) - 2;
		newTop = eleOffset.top + $(object).height() + padding + 2;
	}
	else if(position == "up")
	{
		newLeft = eleOffset.left + ($(object).width() / 2) + (padding/2) - 2;
		newTop = eleOffset.top - (padding/2) - 15 + 2;
	}
	else if(position == "right")
	{
		newLeft = eleOffset.left + $(object).width() + padding + 2;
		newTop = eleOffset.top + ($(object).height() / 2) + (padding/2) - 4;
	}
	$(object + '-pointer').css({left: newLeft});
	$(object + '-pointer').css({top: newTop});
	$(object + '-pointer').show();
	
	$(object).dropShadow(2,2,2,0.5);
	$(object + '-pointer').dropShadow(2,2,2,0.8,"black");
}


/* Drop Shadow by AUTHOR: Larry Stevens, This work is in the public domain
VERSION: Drop Shadow jQuery Plugin 1.6  12-13-2007 */
(function($){

	var dropShadowZindex = 1;  //z-index counter

	$.fn.dropShadow = function(options)
	{
		// Default options
		var opt = $.extend({
			left: 4,
			top: 4,
			blur: 2,
			opacity: .5,
			color: "black",
			swap: false
			}, options);
		var jShadows = $([]);  //empty jQuery collection
		
		// Loop through original elements
		this.not(".dropShadow").each(function()
		{
			var jthis = $(this);
			var shadows = [];
			var blur = (opt.blur <= 0) ? 0 : opt.blur;
			var opacity = (blur == 0) ? opt.opacity : opt.opacity / (blur * 8);
			var zOriginal = (opt.swap) ? dropShadowZindex : dropShadowZindex + 1;
			var zShadow = (opt.swap) ? dropShadowZindex + 1 : dropShadowZindex;
			
			// Create ID for shadow
			var shadowId;
			if (this.id) {
				shadowId = this.id + "_dropShadow";
			}
			else {
				shadowId = "ds" + (1 + Math.floor(9999 * Math.random()));
			}

			// Modify original element
			$.data(this, "shadowId", shadowId); //store id in expando
			$.data(this, "shadowOptions", options); //store options in expando
			jthis
				.attr("shadowId", shadowId)
				.css("zIndex", zOriginal);
			if (jthis.css("position") != "absolute") {
				jthis.css({
					position: "relative",
					zoom: 1 //for IE layout
				});
			}

			// Create first shadow layer
			bgColor = jthis.css("backgroundColor");
			if (bgColor == "rgba(0, 0, 0, 0)") bgColor = "transparent";  //Safari
			if (bgColor != "transparent" || jthis.css("backgroundImage") != "none" 
					|| this.nodeName == "SELECT" 
					|| this.nodeName == "INPUT"
					|| this.nodeName == "TEXTAREA") {		
				shadows[0] = $("<div></div>")
					.css("background", opt.color);								
			}
			else {
				shadows[0] = jthis
					.clone()
					.removeAttr("id")
					.removeAttr("name")
					.removeAttr("shadowId")
					.css("color", opt.color);
			}
			shadows[0]
				.addClass("dropShadow")
				.css({
					height: jthis.outerHeight(),
					left: blur,
					opacity: opacity,
					position: "absolute",
					top: blur,
					width: jthis.outerWidth(),
					zIndex: zShadow
				});
				
			// Create other shadow layers
			var layers = (8 * blur) + 1;
			for (i = 1; i < layers; i++) {
				shadows[i] = shadows[0].clone();
			}

			// Position layers
			var i = 1;			
			var j = blur;
			while (j > 0) {
				shadows[i].css({left: j * 2, top: 0});           //top
				shadows[i + 1].css({left: j * 4, top: j * 2});   //right
				shadows[i + 2].css({left: j * 2, top: j * 4});   //bottom
				shadows[i + 3].css({left: 0, top: j * 2});       //left
				shadows[i + 4].css({left: j * 3, top: j});       //top-right
				shadows[i + 5].css({left: j * 3, top: j * 3});   //bottom-right
				shadows[i + 6].css({left: j, top: j * 3});       //bottom-left
				shadows[i + 7].css({left: j, top: j});           //top-left
				i += 8;
				j--;
			}

			// Create container
			var divShadow = $("<div></div>")
				.attr("id", shadowId) 
				.addClass("dropShadow")
				.css({
					left: jthis.position().left + opt.left - blur,
					marginTop: jthis.css("marginTop"),
					marginRight: jthis.css("marginRight"),
					marginBottom: jthis.css("marginBottom"),
					marginLeft: jthis.css("marginLeft"),
					position: "absolute",
					top: jthis.position().top + opt.top - blur,
					zIndex: zShadow
				});

			// Add layers to container	
			for (i = 0; i < layers; i++) {
				divShadow.append(shadows[i]);
			}
			
			// Add container to DOM
			jthis.after(divShadow);

			// Add shadow to return set
			jShadows = jShadows.add(divShadow);

			// Re-align shadow on window resize
			$(window).resize(function()
			{
				try {
					divShadow.css({
						left: jthis.position().left + opt.left - blur,
						top: jthis.position().top + opt.top - blur
					});
				}
				catch(e){}
			});
			
			// Increment z-index counter
			dropShadowZindex += 2;

		});  //end each
		
		return this.pushStack(jShadows);
	};


	$.fn.redrawShadow = function()
	{
		// Remove existing shadows
		this.removeShadow();
		
		// Draw new shadows
		return this.each(function()
		{
			var shadowOptions = $.data(this, "shadowOptions");
			$(this).dropShadow(shadowOptions);
		});
	};


	$.fn.removeShadow = function()
	{
		return this.each(function()
		{
			var shadowId = $(this).shadowId();
			$("div#" + shadowId).remove();
		});
	};


	$.fn.shadowId = function()
	{
		return $.data(this[0], "shadowId");
	};


	$(function()  
	{
		// Suppress printing of shadows
		var noPrint = "<style type='text/css' media='print'>";
		noPrint += ".dropShadow{visibility:hidden;}</style>";
		$("head").append(noPrint);
	});

})(jQuery);