$(function() {
	$('a[rel*=facebox]').facebox(); 

	/*$("#slide-nav").css('width','883px;');
	if ($.browser.msie) {
		$("#slideshow img").attr('width','81');
	}*/

    $("#divarea1").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev"
    });

    $("#divarea2").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		visible: 5.0,
		start: 0,
		scroll: 5
    });

    $("#divarea3").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		visible: 5.0,
		start: 0,
		scroll: 5
    });

    $("#slide-images").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		visible: 3.0,
		start: 0,
		scroll: 1
    }).css('width','933px');
	
    $("#slideshow").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		visible: 9.0,
		start: -3,
		scroll: 1
    });
	
	// Lazyload the villa images (this is not the lazyload plugin..) woooo
	(function($) {
	  $.fn.lazyload = function(func) {
		var nodes = [] ;
		this.each(function() { nodes.push($(this)) } ) ;
		var scrollFunc = function() {
		  var topOffset = $(window).scrollTop() ;
		  var bottomOffset = topOffset + $(window).height() ;
		  for(var n in nodes) {
			var node = nodes[n] ;
			if(!node[0]._lazyloaded) {
			  var nodeTop = node.offset().top ;
			  if((nodeTop < bottomOffset) && (nodeTop + node.height() > topOffset)) {
				node[0]._lazyloaded = true ;
				func(nodes[n]) ;
			  }
			}
		  }
		} ;
		if(nodes.length > 0) {
		  $(window).scroll(scrollFunc) ;
		  scrollFunc() ;
		}
	  } ;
	})(jQuery) ;

	setTimeout(function() {
		$("img[lazysrc]").lazyload(function(e) { e.attr("src",e.attr("lazysrc")) ; });
	}, 2500);
	// End lazyload script

	$('#infobox').accordion({ autoheight: false });
	$('#faq').accordion({ autoheight: false, header: '.head' });
		
	$("div.title").each(function(index) {
		link = link.add($(this).click(function() {	accordion("activate", index + ($(this).is(".next") ? 1 : -1))}));});
	});
		
	$("div.title").each(function(index) {
		link = link.add($(this)
		.click(function() {
			accordion("activate", index + ($(this).is(".next") ? 1 : -1))
	}));
});

function myfunction() {
	$.facebox('<iframe src=/popups/world-map.php width=900 height=550 scrolling=no frameborder=0></iframe>');
}
    
function setVal($id, $val, $hide){
	$("input[name="+$id+"]").val($val);
	$("#"+$hide).slideUp(50);
}

function setHtml($id, $val){
	$("#"+$id).html($val);
}

function setLink($id, $val, $hide){
	$("#"+$id).attr('href', $val)
	$("#"+$hide).slideUp(50);
}

function toggle(menuId) {
 var ele = document.getElementById(menuId);
 if(ele.style.display == "block") {
      ele.style.display = "none";
   }
 else {
  ele.style.display = "block";
 }
}

function updateAreas($id){
	$loc=$("#areasSelector");
	$wait=$("#dropdown-menu2");
	$wait.html('updating');
	$.ajax({
	  url: "/includes/reloadAreas.php?id="+$id,
	  cache: false,
	  success: function(html){
		$loc.html(html);
		$wait.html('Choose A Location...');
	  }
	});
}

function filter(id){
	$('#dropdown-items5').slideUp('fast');
	$('#divarea1').hide();
	$('#divarea2').hide();
	$('#divarea3').hide();
	$('#divarea4').fadeIn('fast');
	
	$('#t2link').attr("href", '/top20/'+id+'/');
	$('#slink').attr("href", '/specials/'+id+'/');
	$('#splink').attr("href", '/staffpicks/'+id+'/');
	
	$.ajax({
	   type: "POST",
	   url: "includes/homepageFilter.php?id="+id,
	   success: function(data){
			$('#category-content').html(data);
	   }
	});			
}
