// JavaScript Document

 $(document).ready(function(){
   	var flyoutOpen = 0;
	//$.preloadCssImages();
	
	/* flyout tabs */
	$('a#flyoutTab').click(function () {
		if(flyoutOpen == 0){
			$('#flyout').animate({ left: 0}, 750);	
			flyoutOpen = 1;
		}
    }); 
	
	
	$('#flyout').bind("mouseleave",function(){
		if(flyoutOpen == 1){
			$('#flyout').animate({ left: -354}, 1000);
			flyoutOpen = 0;
		}
	});
	
	jQuery.fn.outer = function() { 
	  return $( $('<div></div>').html(this.clone()) ).html(); 
	} 

	var currLocation = document.location.href;
	var inwct = currLocation .indexOf("wct_cur");
	//if ( inwct == -1) {
	//Cufon.replace('h4');
	//Cufon.replace('h5');
	//Cufon.replace('.copperplate');
	//};
	
	//$('a.lightbox').lightBox({fixedNavigation:true});
	
	$('#homC2 > div').css("marginBottom","35px");
	$('#c1 > div').css("marginBottom","20px");
	$('#c3 > div').css({'margin-left':'auto','margin-right':'auto'});
	$('.ordinaryBoxContent > div:not(:last)').css("marginBottom","20px");
	
	//$(".thumbReflection").reflect({height:.2,opacity:.25,distance:0});
	//$(".thumbReflectionIMGBOX").reflect({height:.4,opacity:.4,distance:0});
	
	//$('.ordinaryDate:not(:first)').css('paddingTop','10px');
	
	$.easing.custom = function (x, t, b, c, d) { 
	    var s = 1.70158;  
	    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
	    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
	}
	
	$("#imageBrowserBox").scrollable({
		size: 1,
		items: 'div#imageBrowserItemContainer',
		easing: 'custom', speed: 700,
		next: '#imageBrowser a.next', 
    	prev: '#imageBrowser a.prev',
		loop: true
	});
	
	$('a#advancedSearchBtn').click( function(){
		$('#lSearchAdvanced').slideToggle("slow");
	});
	
	$('#secondaryNav ul li:not(#backTo)').click( function() {
		var selMenu = $(this).find("a").attr('childid');
		var thisHref = $(this).find("a").attr("href");
		var thisTitle = $(this).find("a").attr("title");
		if (selMenu.length) {
			$("#childOf_" + selMenu).toggle(200, function(){
				$('#secondaryNavSlideContainer').animate({
					marginLeft: "-210px"
				}, 700, 'custom', function(){
					$('#secondaryNavTitle').html(thisTitle);
					$("#secondaryNavSlideContainer").animate({height: $("#childOf_" + selMenu).height()+20},700, 'custom', function(){
						window.location = thisHref;
					});
				});
			});
		} else {
			window.location = thisHref;
		}
		return false;
	});
	
	
	/*
$('#backTo').click( function() {
		var selMenu = $(this).find("a").attr('parentid');
		var thisHref = $(this).find("a").attr("href");
		var thisTitle = $(this).find("a").attr("title");
		if (selMenu.length) {
			$("#parentOf_" + selMenu).animate({height:"100%"},700,'custom', function(){
				$('#secondaryNavSlideContainer').animate({
					marginLeft: "0px"
				}, 700, 'custom', function(){
					$('#secondaryNavTitle').html(thisTitle);
					$("#secondaryNavSlideContainer").animate({
						height: $("#parentOf_" + selMenu).height() + 20
					}, 700, 'custom', function(){
						window.location = thisHref;
					});
				});
			});
		} else {
			window.location = thisHref;
		}
		return false;
	});
*/

	
	$("#eventsBrowser").scrollable({
		size: 1,
		items: 'div#eventBrowserEvents',
		easing: 'custom',
		speed: 700,
		end: function(){
			$('#imageBrowser a.next').css("backgroundPosition","right top");
		}
	});
	
	$("a#backgroundTabHandle").click( function() {
		if($("div#backgroundTab").width() == 1){
			$("div#backgroundTab").animate({width: 62}, 300, "swing");
		} else {
			$("div#backgroundTab").animate({width: 1}, 300, "swing");
		}

		return false;
	});
	
	// vertical align trick for secondary nav title
	var marg = ($('#secondaryNavTitleHolder').height() - $('#secondaryNavTitle').height()) / 2;
	$('#secondaryNavTitle').css('margin-top', marg);
	
	$('.iconLink').hover( function() {
		$(this).css("cursor","pointer");
		$("+ div",this).toggle();
		$("+ div",this).hover( function() {
			$(this).show();
		}, function(){
			$(this).hide();
		});
	}, function(){
		$("+ div",this).toggle();
	});
	
	/* listing blue tabs */
	$('.listingTabHolder a:not(#lphotos_tab)').click(function () {
          $('.listingTabHolder a').removeClass('sel');
		$(this).addClass('sel');
		
		$('.listingTabBoxHolder').hide().filter(this.hash).fadeIn('slow');
        
        return false;
     }).filter(':first').click();
	
	$('a#lmaps_tab').click( function() {
		initDetailMap();						   
	});
	
	$('#lphotos_tab').click( function () {
		$('.listingTabHolder a').removeClass('sel');
		$('#loverview_tab').addClass('sel');
		
		$('.listingTabBoxHolder').hide().filter('#loverview_box').fadeIn('slow');
		$('a.lightbox:first').click();
		return false;
	});
	
	var numIcons = $('.iconLinkHolder').size();  // default width is 72...expand to fill parent
	if(numIcons >= 1){
		var pWidth =  $('.iconLinkHolder').parent().width();
		var newSize = Math.floor(pWidth/numIcons);
		$('.iconLinkHolder').width(newSize);
	}
	
	$('.amenListHolder').each(
		function(intIndex) {
			numChild = $(this).children().size();
			if(numChild <= 1)
				$(this).parent().hide();
		}
	);
	

	$('.minus').click(function(e) {
		var quant = $(this).prev();
		var quant = quant.prev('.numInput');
		quant.val(parseInt(quant.val(), 10) - 1);
		if (parseInt(quant.val(), 10) < 0)
		{ quant.val(0); }
	});

	$('.add').click(function(e) {
		var quant = $(this).prev('.numInput');
		quant.val(parseInt(quant.val(), 10) + 1);
	});
	
	$(".tsdiv").hover(function(){ 
			$(".tsmenu", this).css({visibility:"",top:0,left:0}).fadeIn("slow"); 
	 }, function() { 
			$(".tsmenu", this).css({visibility:"",top:0,left:0}).fadeOut("slow"); 
	 });
	
 });
 

