$(document).ready(function() {
 
	sfHover();
	
	doscrollpane();
	
	$('#gallery-images').cycle({ 
		fx:      'scrollDown', 
		pager: '#gallery-nav',
		timeout:  0,
		pagerAnchorBuilder: function(idx, slide) { 
			// return selector string for existing anchor 
			return '#gallery-nav li:eq(' + idx + ') a'; 
		} 
	});
	    
     
    $('#direct').click(function() { 
        $('#gallery-nav li:eq(2) a').trigger('click'); 
        return false; 
    }); 
	
	$('#gallery-nav li a').click(function() {
		
		$('#header').slideUp('slow');
		
		$('a.full-image-link').hide();
		
		$('a.show-menu').show();
	
	});
	//hide all things to be revealed
	 $('a.open-info').hide();
	 
	 $('a.show-menu').hide();
	
	$('a.revealer').click(function(e) {
	
		e.preventDefault();
		
		$(this.hash).show("slow");
		
		$(this).hide('slow');
		
		return false;
		
	 });
	 
	 $('#top-menu li:not(.current)').hover(function() {
		
		$('#top-menu li.current ul').hide();
		
	 });
	 
	 $('#top-menu li:not(.current)').mouseout(function() {
		
		$('#top-menu li.current ul').show();
		
	 });
	 
	$('a.show-menu').click(function(e) {
	 
		e.preventDefault();
		
		$('#header').slideDown('slow');
		
		$('.note').remove();
		$('.notep').remove();
		
		$('a.full-image-link').show();
		
		$('a.open-info').show();
		
		$(this).hide();
		
		return false;
		
	 });
 
 
	$('#cancelnote').click(function(){
	
		$('#featureimage').imgAreaSelect({ hide: true, disable:true });
		
			$('#noteform').hide();
				
		});
 
		$('#addnotelink').click(function(){
		
			$('#featureimage').imgAreaSelect({ enable:true, onSelectChange: showaddnote, x1: 120, y1: 90, x2: 280, y2: 210 });
				
			return false;
				
		});
	 
	 $('a.close-this').click(function(e) {
	 
		e.preventDefault();
				
		$('#col1-info').jScrollPaneRemove();
		
		$(this).parent().hide();
		
		$('a.open-info').show();
 
		
		return false;
		
	 });
	 
	 $('a.open-info').click(function(e) {
	 
		e.preventDefault();
		
		$('.page-info').show('fast',doscrollpane);
		
		$(this).hide();
		
		return false;
		
	 });
	 
	  $('a.full-image-link').click(function(e) {
	 
		e.preventDefault();
		
		$('#col1-info').jScrollPaneRemove();
		
		$('.page-info').hide('fast');
		
		$('#header').slideUp('slow');
		
		$('a.open-info').hide();
		
		$('a.show-menu').show();
		
		$('#featureimage').imgNotes(hotspots);
		
		$('.note').show();
		
		$(this).hide();
		
		return false;
		
	 });
	 
	Date.format = 'yyyy/mm/dd';
 
	$('.datepicker').datePicker({clickInput:true,startDate:'1996/01/01'})
	
	$("#text-list").sortable({
      handle : '.handle',
      update : function () {
		var order = $('#text-list').sortable('serialize');
		$("#info").load("process-sortable.php?"+order);
      }
    });
	$(".handle").mouseup(function(){
      $("#info").show('slow');
    }).mousedown(function(){
       $("#info").hide();
    });
	
	/* old colorbox implementation
	$("a.book-now").colorbox({iframe:true, innerWidth:1000, innerHeight:450});
	*/
	
	$('a.book-now').click(function(){
        window.open(this.href);
        return false;
    });
 
});
 
function doscrollpane(){
 
	$('#col1-info').jScrollPane();
	
}
var addthis_config = {
		ui_cobrand: "the green house"
	}
 
function initReveals(speed){
 
	$('.hidden').hide(speed);
	
	$('.revealer').show();
	
}
 
function showaddnote (img, area) {
		imgOffset = $(img).offset();
		form_left  = parseInt(imgOffset.left) + parseInt(area.x1);
		form_top   = parseInt(imgOffset.top) + parseInt(area.y1) + parseInt(area.height)+5;
 
		$('#noteform').css({ left: form_left + 'px', top: form_top + 'px'});
 
		$('#noteform').show();
 
		$('#noteform').css("z-index", 10000);
		$('#NoteX1').val(area.x1);
		$('#NoteY1').val(area.y1);
		$('#NoteHeight').val(area.height);
		$('#NoteWidth').val(area.width);
 
	}
	
function stripslashes(str){
 
	return str.replace(/\\/g, '');
	
}
 
sfHover = function() {
	var sfEls = document.getElementById("top-menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
