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(){
		location = 'http://hotels.webjet.co.nz/webjethotels/nz/';
		
		return;            
            
		$( '#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=Car';
		
		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'});
	});
	
	

		$('#intl-australia').each(function(){
			intl_spec_move("#intl-australia", "right");
			intl_spec_move("#intl-nz", "right");
		});

	}
	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();
	
}


