
function runASOmniture(omnitureString){
	eval(omnitureString);
}

$(document).ready(function(){
	$.historyInit(history_callback);
	
	if(jQuery.browser.msie) {
		$("a").each(function(){
			if (typeof $(this).attr('href') == "string") {
				if ( $(this).attr('href').indexOf("layout") > 0) {
					$(this).click(function(){rebuild_poi_search_form($(this).attr('href')); return false;});
				}
			}
		});
	}
});


function shadow_open() {
	$("#sb-nav-close").html(' Close ');
}



$(function(){

	// New Pagination call for Accomodations
	$("#ajax_results").pagination();
		
	Cufon.replace('#top_nav li a', {
	hover: true
	});
	
	
	Shadowbox.setup("a.shadowlink", {
	    player: "iframe",
		width: '700px'
	});
	
	Cufon.replace('h1,h2');
	
	$('#top_nav li a, h1, h2').css("visibility", "visible")

	//tabs
//	$("#tabs li a").click(function (){
//		$("#tabs li a").removeClass("on");
//		$(this).addClass("on");
//		var tabid = $(this).parent("li").attr("id");
//		$(".wt").hide();
//		$("."+tabid).show();
//		return false;
//	});
	
	$("#gallery_tabs #season, #gallery_tabs #passion").mouseenter(function(){
		$(this).find('.sub').slideDown();
	});
	
	$("#gallery_tabs #season, #gallery_tabs #passion").mouseleave(function(){
		$(this).find('.sub').slideUp();
	});
	
	$("#gallery_tabs li .sub").each(function(){
		$(this).slideUp();
	});
	
	//sfhover
		$(".search_btn, .sign_btn, .modify_s").hover( 
		function() {$(this).addClass("sfhover")},
		function() {$(this).removeClass("sfhover")}
		);
	
	// events expand/collapse
	$('.ec_module .b_more').click(function(){
			var ecmod = $(this).parents('.ec_module');
			var wasdown = ecmod.find('.collapsed').length;
			$('.ec_content .expanded').slideUp().addClass('collapsed').removeClass('expanded').parent().find('a.b_more').html('More &raquo;');

			if (wasdown == 1){
				ecmod.find('.collapsed').slideDown().addClass('expanded').removeClass('collapsed');
				ecmod.find('a.b_more').html('&laquo; Close');
			}

			return false;		

	});

// horizontal image gallery --------------------------------------

	$("#gallery_thumbs ul").css("left", "0px");
	var num_of_images = $("#gallery_thumbs ul > li").length;
	//var image_width = $("#photo_frame ul li:first").width();
	var image_width = 118;
	var list_width = num_of_images * image_width;
	$("#gallery_thumbs ul").css("width", list_width);//!!!!!!
	var left = 0;
	var margin = 4;
	$(".right_b").click(function(){
		//fast scroll to the first image
		if (Math.abs(left) == (list_width-image_width)) {
			$("#gallery_thumbs ul").animate({"left": "-="+margin+"px"}, 200, function(){
				left = 0;
				$("#gallery_thumbs ul").animate({"left": "0px"}, 800);
			});
		}
		//next image
		if (Math.abs(left) < (list_width-image_width)) {
			left -= image_width;
			$("#gallery_thumbs ul").animate({"left": "-="+image_width+"px"}, 400);
		}	
	});
	$(".left_b").click(function(){
		//fast scroll to the last image
		if (left == 0) {
			$("#gallery_thumbs ul").animate({"left": "+="+margin+"px"}, 200, function(){
				left -= list_width-image_width;
				$("#gallery_thumbs ul").animate({"left": "-="+(list_width-image_width+margin)+"px"}, 800);
			});
		}
		//previous image
		if (left < 0) {
			left += image_width;
			$("#gallery_thumbs ul").animate({"left": "+="+image_width+"px"}, 400);
		}
	});





});


function reset_poi_search() {
	if (arguments[0]) { 
		$('#cat_select').setValue(arguments[0]);
	} 
	if (arguments[1]) var subselect = arguments[1];
	$("#cat_keywords").setValue(""); 
	if ($('#cat_select').getValue() != '0') {
		$('#sub_cat_select').load('/Directory/options/' + $('#cat_select').getValue(), "", function(){
			opts = $("#sub_cat_select option"); 
			if (opts.length < 2) $("#sub_cat_select, .or_label").css("display", "none");
			if (subselect) $('#sub_cat_select').setValue(subselect);
		})
	}
}

function rebuild_poi_search_form(href) {
	var vars = href.split("?")[1].split("&"); 
	for (var i=0;i<vars.length;i++) { 
	    var pair = vars[i].split("="); 
		var thisval = pair[0];
		if (thisval == 'offset' || thisval == 'limit') thisval = "ajax_" + thisval;
		$("#"+thisval).setValue(pair[1].replace(/\+/, " "));
		if (thisval = 'target') var hitme = pair[1].replace(/\+/, " ");
	}
	if (arguments.length == 1) poi_search(hitme);
}

var reloadflag = 0;
	
function poi_search() {
	var target = 'ajax_target';
	if (arguments[0] && arguments[0] != 'firstup') target = arguments[0];
	var qstring = '?';
	$('#cat_form .sendme').each(function(){
		qstring += $(this).attr('name') + '=' + $(this).getValue().replace(/ /g, '+') + '&';
	});
	qstring += 'target=' + target;
	
	var loadme = '/layout/set/poi_search/content/view/full/2' + qstring;
	if (arguments[0] == 'firstup' && location.hash.length == 0) {
		location.replace(location.href + "#" + loadme);
		if (jQuery.browser.safari || jQuery.browser.msie) {
			history_callback(loadme)
		}
	} else {
		$.historyLoad(loadme.replace(/^.*#/, ''));
	}
	return false;
}

function paginateAlt() {
itemsPerPage = 12;
paginatorStyle = 3;
nextPageSymbol = 'Next';
previousPageSymbol = 'Prev';
separator = ' ';
$("#ajax_results").pagination();
Shadowbox.setup("a.shadowlink", {
    player: "iframe",
	width: '700px'
});
Shadowbox.setup("a.imshadowlink");
}

function history_callback(hash) {
	if (hash) {
		var target = hash.split('target=')[1]
		$("#"+target).load(hash, function(responseText, textStatus, XMLHttpRequest){if (textStatus == 'success') paginateAlt(hash);});
		reloadflag = 1;
	} else if (reloadflag) {
		location.reload(true);
	}
}

paginate = function(hash) {
	cal_func = (hash.indexOf('event_search') > 0) ? 'cal_offsetjump': 'offsetjump';
	rebuild_poi_search_form(hash, true);
	var target = hash.split('target=')[1]
	offset = parseInt($("#ajax_offset").getValue());
	limit = parseInt($('#ajax_limit').getValue());
	html = "<div class='pagwrapper'><div class='pagination'>";
	total = parseInt($('#ajax_results').attr('searchcount'));
	if (offset > 0) { 
		html += "<a class='next' href='javascript: " + cal_func + "(" + (offset - limit) + ", \"" + target + "\")'>Prev</a>"; 
	} else {
		html += "<span class='next'>Prev</span>";
	}
	var i = 0;
	var myclass = '';
	var inrange = true;
	while (i*limit < total) {
		myclass = ''
		if (i*limit == offset) myclass = " class='current'";
		if (Math.abs(i-(offset/limit)) < 6 || i==0 || (i+1)*limit > total) {
			html += "<a " + myclass + "href='javascript: " + cal_func + "(" + (i*limit) + ", \"" + target + "\")'>" + (i + 1) + "</a>"
			inrange = true;
		} else {
			if (inrange) html += "<span class='pagrange'>. . .</span>";
			inrange = false;
		}
		i++;
	}
	if (offset < (total - limit)) {
		html += "<a class='prev' href='javascript: " + cal_func + "(" + (offset + limit) + ", \"" + target + "\")'>Next</a>"; 
	} else {
		html += "<span class='prev'>Next</span>";
	}
	html += "</div</div>";
	$('#'+target).append(html);
	Shadowbox.setup("a.shadowlink", {
	    player: "iframe",
		width: '700px'
	});
	Shadowbox.setup("a.imshadowlink");
}

offsetjump = function(offset, target) {
	$("#ajax_offset").setValue(offset);
	poi_search(target);
}


var flashvars = {pathToXML:"/extension/site/design/site/flash/myXML.xml"};

var params = {
	wmode:"transparent"
};
var attributes = { 
	id:"subnav",
	name:"subnav"
};

function getSWF(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) return window[movieName];
	else return document[movieName];		
}

function getLatLng(address) {
// not finished
	// return an array[lat,lng]
	$.ajax({
		url: '/Directory/print_json/' + address,
		success: function(json) {
			return json;
		}
	});
	return false;
}