//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Custom Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================



var map;
		//	Reset ap center
		function zoomto(latitude,longitude,zoom)
		{
			var centerpoint = new GLatLng( latitude, longitude );
			map.setCenter( centerpoint, zoom );
		}



//#########################################################################################################
//---------------------------------------------------------------------------------------------------------
//	jQuery functions
//---------------------------------------------------------------------------------------------------------
//#########################################################################################################
  $(document).ready(function(){

	/*	load background image	*/
	$("html").css("background-image","url(/site/images/bg_pattern.jpg)");
/*
    $("a.maptoggle").click(function () {
      $(this).next("div").slideToggle("fast");
    });    

    $("a.maptoggle").click(function () {
      $("#map-block").slideToggle("fast");
    });    

*/


/*
    $("a#map-open").click(function () {
      $("#map-block").slideToggle("fast");
      $("#map-open").slideToggle("fast");
    });    

    $("a#map-close").click(function () {
      $("#map-block").slideToggle("fast");
      $("#map-open").slideToggle("fast");
    });    

*/
//---------------------------------------------------------------------------------------------------------
//	Map Toggle
//---------------------------------------------------------------------------------------------------------
    $("a#map-open").click(function () {
      $("#map-block").css("display","none");
      $("#map-block").css("visibility","visible");
      $("#map-block").fadeIn(200);
      $("#map-open").fadeOut(200);

		//	overcome ie overlap issue - map is covered by trip search form
		if( $.browser.msie )
		{
			if( $("#main").height() < 244 )
			{
				$("#main").css("height","244px");
			}
		}
		});    

    $("a#map-close").click(function () {
      $("#map-block").fadeOut(200);
      $("#map-open").fadeIn(200);
		//	overcome ie overlap issue - map is covered by trip search form
	  if( $.browser.msie )
		{
			  $("#main").css("height","auto");
		}
    });    

    $("h2.optionsheader").click(function () {
      $(this).next("div").slideToggle("fast");
      $(this).toggleClass("expanded");
    });    



//---------------------------------------------------------------------------------------------------------
//	Expandible sections (regions/traveler reviews)
//---------------------------------------------------------------------------------------------------------
    $(".exp-header .expand").click(function () {
      $(this).parent().next(".exp-block").slideToggle("fast");
      $(this).parent().toggleClass("exp-header-active");
    });    


//---------------------------------------------------------------------------------------------------------
//	E-mail this trip to a friend
//---------------------------------------------------------------------------------------------------------
	$("a#extra-email").click(function(event){  event.preventDefault();
	});    
	$("a#extra-email").click(function () {
		$("#emailform").fadeIn("fast");
		return false;
	});    

	$("a#close-email").click(function () {
		$(this).parent().fadeOut("fast");
		return false;
	});    

/*
	$("a#extra-email").click(function () {
		$(this).next("div").fadeIn("fast");
		return false;
	});    

	$("a#close-email").click(function () {
		$(this).parent().fadeOut("fast");
		return false;
	});    
*/
/*
$("a.close").click(function(event){  event.preventDefault();
*/



    $("img#expall").click(function () {
      $(".optionsbox").show("fast");
      $("h2.optionsheader").addClass("expanded");
    });    

    $("img#clall").click(function () {
      $(".optionsbox").hide("fast");
      $("h2.optionsheader").removeClass("expanded");
    });    

	
	/*	Search	*/
	$("#searchlink").click(
		function (event) {
			event.preventDefault();
			$("#search").show();
			$("#searchtext").focus();
		}, 
		function () {
			$("#search").hide();
		}
	);
/*
	$("#search").hover(
		function () {
			$("#search").show();
		}, 
		function () {
			$("#search").hide();
		}
	);
*/	
	/*	Talk To Us menu	*/
	$("a#talkoptions").hover(
		function () {
			$("#talk-active").show();
			$("#talkoptions").hide();
		}, 
		function () {
			$("#talk-active").hide();
			$("#talkoptions").show();
		}
	);

  
	/*	Talk To Us menu	*/
	$("#talk-active").hover(
		function () {
			$("#talk-active").show();
			$("#talkoptions").hide();
		}, 
		function () {
			$("#talk-active").hide();
			$("#talkoptions").show();
		}
	);

  
  
	/*	setup menu styling	*/
	$("ul#m-tripfinder").append('<img src="/site/images/nav/bg_menu_trip_finder_bottom.png" alt="---" />');
	$("ul#m-whatwedo").append('<img src="/site/images/nav/bg_menu_what_we_do_bottom.png" alt="---" />');
	$("ul#m-whoweare").append('<img src="/site/images/nav/bg_menu_who_we_are_bottom.png" alt="---" />');
	$("ul#m-ourcustomers").append('<img src="/site/images/nav/bg_menu_our_customers_bottom.png" alt="---" />');

	//	Active menu tabs
//	$("#nav-main").find("a.active").parent().css('background-color','green' );

	$("#nav-main").find("a.active").parent().each(function () {
		var	imgname	= $("#nav-main").find("a.active").attr("id") + ".png";
//		alert( imgname );
		$(this).css('background-image','url(/site/images/nav/' + imgname + ')' );

//		$(this).css("display","noneid yellow;");
//		alert( $(this).attr("class") + ')' );
	});








	//	Menu positioning, fixes IE 2 pixel offset
	$("#nav-main a").hover( function() {
		var button_id	= $(this).attr("id");
		var	menu_id		= "#m-" + button_id.substring( 2, button_id.length );

		var p = $( this );
		var offset = p.offset();

		$( menu_id ).css( "top", ( offset.top + $( this ).height() ) );
		$( menu_id ).css( "left", offset.left );
	});


	//	Restack talk menu (after IE pngfix)
	$("a#talkoptions").hover( function() {
		$("#talkmenu").css("z-index","7100");
		$("#content").css("z-index","0");
	});


});



//-------------------------------------------------------------------------------------------------------
//	JAuery hide empty menus
//-------------------------------------------------------------------------------------------------------
$(function(){

	$(document.body).ready
	(
		function(){$(this).find('ul.m2').HideEmpty();}
	);
});

jQuery.fn.HideEmpty = function() {
  return this.each(function(){
	var itemcount	= $(this).find('li').length;
	if( !itemcount || itemcount == 0 )
	  {
		$(this).css( "visibility", "hidden" );
		$(this).css( "display", "none" );
	  }
  });
};


//-------------------------------------------------------------------------------------------------------
//	Super Simple Tabs 1.0
//		http://andreaslagerkvist.com/jquery/super-simple-tabs/
//-------------------------------------------------------------------------------------------------------
jQuery.fn.superSimpleTabs = function () {
    return this.each(function () {
        var ul = jQuery(this);

        // Go through all the in-page links in the ul
        ul.find('a[href^=#]').each(function (i) {
            var link = jQuery(this);

            // Hide all containers cept the first
            if (i) {
                jQuery(link.attr('href')).hide();
            }
            else {
                link.addClass('selected');
            }

            // When clicking link
            link.click(function () {
                // Hide selected link's containers
                jQuery(ul.find('a.selected').removeClass('selected').attr('href')).hide();

                // Show this one's
                jQuery(link.addClass('selected').attr('href')).show();

                return false;
            });
        });
    });
};