//Cufon font replacement
Cufon.replace('.sans', { fontFamily: 'TheSans' });
Cufon.replace('.sans-light', { fontFamily: 'TheSansLight' });
Cufon.replace('.serif', { fontFamily: 'TheSerif' });
Cufon.replace('.serif-light', { fontFamily: 'TheSerifLight' });

jQuery.Format = function() {   
  var str = arguments[0]; 
  for (var i = 0; i < arguments.length - 1; i++) {        
    var reg = new RegExp("\\{" + i + "\\}", "gm");              
    str = str.replace(reg, arguments[i + 1]); 
  } 
  return str; 
};
function Capitalize(obj)
{
	val = obj.replace(/-/g,' ');
    newVal = '';
    val = val.split(' ');
    for(var c=0; c < val.length; c++) {
      newVal += val[c].substring(0,1).toUpperCase() + val[c].substring(1,val[c].length) + ' ';
    }
    return newVal;
};
function BuildDestinationDDL(data)
{
  var list = $("#destination_list").append('<ul style="list-style-type:none;font-size:10px;"></ul>').find('ul'); 
list.append("<li><a href='#'>All Destinations</a></li>");
  var ddl = [];
  $(data).find("destination").each(function()
  {
      var dest = $(this).text().split('.')[0]; 
	  if (dest.length != 0 && dest.indexOf('default') == -1)
      {	  
	     ddl[dest] = dest;  
	  }
  }); 
  var idx = 0;
  for (ll in SortKeys(ddl))
  {
	 list.append("<li><a href='#" + idx + "'>" + Capitalize(ll) + "</a></li>");
	 idx++;
  } 
  
  $('#destination_list li a').each(function(i){$(this).css("cursor","pointer");$(this).click(function(){$('#destination_filter span').text($(this).text());setFilterBy = $(this).text().toLowerCase();$("#destination_list").hide();displayData();});});		 				
  
  	//destination select on item scroller
	$("#destination_select_wrapper").hover(function() {
		$("#destination_list").show();
		$("#destination_select").css({"background-position": "0 -27px"});
	}, function() {
		$("#destination_list").hide();
		$("#destination_select").css({"background-position": "0 0"});
	});
		
	//destination filter (/accommodations/)
	$("#destination_filter_wrapper").hover(function() {
		$("#destination_list").show();
		$("#destination_filter").css({"background-position": "-148px -27px"});
	}, function() {
		$("#destination_list").hide();
		$("#destination_filter").css({"background-position": "-148px 0"});
	});
		

	//width adjustment for destination filter dropdown
	var width = $("#destination_list").width();
	var destinations = $("#destination_list li a");
	$.each(destinations, function() {
		$(this).width(width-25);
	});  
};
function SortKeys(arr){
	var sortedKeys = new Array();
	var sortedObj = {};
	for (var i in arr){
		sortedKeys.push(i);
	}
	sortedKeys.sort();
	for (var i in sortedKeys){
		sortedObj[sortedKeys[i]] = arr[sortedKeys[i]];
	}
	return sortedObj;
};
$(document).ready(function(){
	//homepage feature rollover
	$("#feature .image a").hover(function(){
			var text = $(this).parent().parent().find(".text").find("a");
			text.css({'color': '#00467f'});
		}, function() {
			var text = $(this).parent().parent().find(".text").find("a");
			text.css({'color': ''});
	});
	
	//homepage subfeature rollover
	$(".sub_feature_image").hover(function(){
			var text = $(this).next().find("a");
			text.css({'color': '#00467f'});
		}, function() {
			var text = $(this).next().find("a");
			text.css({'color': ''});
	});
	
	//packages rollover
	$(".package a img").hover(function(){
			var text = $(this).parent().parent().find(".text").find("a");
			text.css({'color': '#00467f'});
		}, function() {
			var text = $(this).parent().parent().find(".text").find("a");
			text.css({'color': ''});
	});
	
	//item scroller functionality
	$("#scroller div.scrollable").scrollable({size: 6}).circular();
	$("#scroller .browse").hover(function() {
		$(this).css({'background-position':'0px -23px'});
	}, function() {
		$(this).css({'background-position':'0px 0px'});
	});
	
	//destination select on item scroller
	$("#destination_select_wrapper").hover(function() {
		$("#destination_list").show();
		$("#destination_select").css({"background-position": "0 -27px"});
	}, function() {
		$("#destination_list").hide();
		$("#destination_select").css({"background-position": "0 0"});
	});
	
	//image viewer functionality
	$("#image_viewer div.scrollable").scrollable({size: 1}).circular().navigator();
	$("#image_viewer .left").hover(function() {
		$(this).css({'background-position':'0px 0px'});
	}, function() {
		$(this).css({'background-position':'0px -30px'});
	});
	$("#image_viewer .right").hover(function() {
		$(this).css({'background-position':'-30px 0px'});
	}, function() {
		$(this).css({'background-position':'-30px -30px'});
	});
	
	//destination filter (packages.html)
	$("#destination_filter_wrapper").hover(function() {
		$("#destination_list").show();
		$("#destination_filter").css({"background-position": "-148px -27px"});
	}, function() {
		$("#destination_list").hide();
		$("#destination_filter").css({"background-position": "-148px 0"});
	});


	//destination filter (/activities/)
	$("#destination_filter_wrapper2").hover(function() {
		$("#destination_list").show();
		$("#destination_filter2").css({"background-position": "-188px -27px"});
	}, function() {
		$("#destination_list").hide();
		$("#destination_filter2").css({"background-position": "-188px 0"});
	});
		
	//width adjustment for destination filter dropdown
	var width = $("#destination_list").width();
	var destinations = $("#destination_list li a");
	$.each(destinations, function() {
		$(this).width(width-25);
	});
	
	//height adjustment for detail pages
	$('#details').height($('#item_details').height()-35);
});

function changeMenu(item){
document.getElementById('packages').className="menu";

if(item=="Accommodation"){
document.getElementById('accommodations').className="menucurrent";
}

else{
document.getElementById('activites').className="menucurrent";
}


}
