function Interface(){

	var Interface = this;

	// global vars
	var g = {
		speed : 300
	};


//	
	
	Interface.init = function(){
		Interface.forms.init();
		Interface.lists.init();	
		Interface.toggles.init();
		Interface.rotators.init();
		Interface.readMore();		
		var IG = new Interface.gallery();
		IG.init();
	};
	
//

	Interface.lists = {
		
		init : function() {
			this.build();
		},
		
		build : function() {
			$("ul li:first-child").addClass("first");
			$("ul li:last-child").addClass("last");
		}
	
	};
	
//

	Interface.forms = {
		
		init : function() {
			this.build();
		},
		
		build : function() {

		 $("#qRRooms_select").spicyselect();			
		 $("#qRAdults_select").spicyselect();			

			$("input.date.today").datepicker({
				minDate: 0, 
				maxDate: "+1Y", 
				numberOfMonths: 1,
				showButtonPanel: true,
				closeText: 'Close',
			    
			    onSelect: function(date,thisPicker){
					date = $(this).datepicker("getDate");
					date.setDate(date.getDate()+1);
					$("form[name=omni_reservation_form] input.date.tomorrow").datepicker("setDate",date);
					$("form[name=omni_reservation_form] input.date.tomorrow").datepicker("option","minDate",date);
			    }
			});

			$("input.date.tomorrow").datepicker({
				maxDate: "+1Y", 
				numberOfMonths: 1,
				showButtonPanel: true,
				closeText: 'Close'
			});			

		}
		
	};
	
//		

	Interface.toggles = {
		
		init : function(){
			this.build();
			this.observe();
		},
		
		build : function(){
			$("#mainNavToggle").data("open",true);
		},
		
		observe : function(){
			$("#mainNavToggle").click( function(){
				if($(this).data("open")){
					Interface.toggles.close();
				}
				else {
					Interface.toggles.open();
				}				
			});
		},
		
		open : function(){
			$("#backToNav").hide(0, function(){
				$("#mainNavCollapse").show(0);
				$("#mainNavToggle").removeClass("closed").data("open",true);
			});
		},
		
		close : function(){
	
			$("#mainNavCollapse").hide(0, function(){
				$("#backToNav").show(0);		
				$("#mainNavToggle").addClass("closed").data("open",false);		
			});				
			
		}
	
	};
	
//	

	Interface.rotators = {
		
		init : function(){
			this.build();
		},
		
		build : function(){
			if($("#getaways").length > 0 && $("#getaways").children('.getaway').length > 1) {
				
				var transition = 'scrollRight'; 
				
				if( $("body").hasClass("sub")){
					transition = 'scrollRight';
				}				
		
				$('#getaways').cycle({ 
			    fx:     transition, 
			    speed:  700,
			    timeout: 4000, 
			    pager:  '#getawaysPager',
          cleartypeNoBg: true,
			    pause: 0,     // true to enable "pause on hover" 
			    pauseOnPagerHover: 1   // true to pause when hovering over pager link      
				});
			}	
			
			if($("div#photoRotator").length > 0 && $("div#photoRotator").children('a').length > 1){
				$('div#photoRotator').cycle({ 
                    width: '1400px',
					fx:     'fade', 
					speed:  1500,
					timeout: 6000, 
					pause: 0,     // true to enable "pause on hover" 
					pauseOnPagerHover: 1   // true to pause when hovering over pager link      
				});
                var wid = ( $(window).width() > 1400 ) ? '1400px' : $(window).width() + 'px';
                //window resize fix
                $('#photoRotator').css({
                    overflowX: 'hidden',
                    width: wid
                });
                $('#photoRotator a').css({
                    backgroundPosition: 'center center',
                    backgroundRepeat: 'no-repeat'
                });
                $(window).resize(function() {
                    if ( $(window).width() > 1400 )
                        $('#photoRotator').css('width', '1400px')
                    else
                        $('#photoRotator').css('width', $(window).width() + 'px');
                });
			}
		}
		
	};
	
//
	
	Interface.readMore = function(){

		var text = {
			open : "- Read Less",
			closed : "+ Read More"
		};

		$("a.readMore").click(function(e){
			e.preventDefault();
			var id = $(this).attr("href");
			if( ! $(this).hasClass("open") || $(this).hasClass("closed") ){
				$(id).fadeIn(200);
				$(this).text(text.open).addClass("open").removeClass("closed");
			}
			else {
				$(id).fadeOut(200);
				$(this).text(text.closed).addClass("closed").removeClass("open");
			}
		});
	
	
	};

//
Interface.gallery = function(){
	
	var Gallery = this;

	// jQ objects
	var $images = $("#photoGallery a");
	var $thumbsList = $("#homePGThumbs");
	var $prev = $("#homePGPrev");
	var $next = $("#homePGNext");
	
	// global vars
	var	global = {
		active : 0,
		tspeed : 500,
		fspeed : 8000
	};
	var data = {};
//
	Gallery.init = function() {
		global.total = $images.length;
		this.images.init();
		this.thumbs.init();
		this.controls.init();
		this.controls.play();
		this.rotator.start();
	};
//
	Gallery.change = function(rindex){
		if(rindex < 0) { index = (global.total-1); }			
		else if(rindex >= global.total){ index = 0; }
		else { index = rindex; }
		global.active = index;
		Gallery.images.change(index);
		Gallery.thumbs.activate(index);
	};
//	
	Gallery.images = {
		init : function() {
			this.build();
		},
		build : function () {
			$images.hide().eq(global.active).fadeIn(global.tspeed);		
		},
		change : function(index) {
			$images.fadeOut(global.tspeed);
			$images.eq(index).fadeIn(global.tspeed);			
			global.title = $images.eq(index).attr("title");
		}
	};
//	
	Gallery.thumbs = {
		init : function(){
			this.build();
			this.observe();
		},
		build : function(){
			$thumbsList.find("li").remove();
			$images.each(function(){
				var $li = $("<li />");
				var $a = $("<a />").attr("href","#");
				var $img = $(this).find("img").clone();
				$a.append($img).appendTo($li);
				$li.appendTo($thumbsList);
			});
			Gallery.thumbs.activate(global.active);			
		},
		observe : function(){
			$thumbsList.find("a").click(function(e){
				e.preventDefault();
				var index = $(this).parent("li").index();
				if(index != global.active) {
					Gallery.controls.pause();
					Gallery.thumbs.activate(index);
					Gallery.change(index);
				}
			});
		},
		activate : function(index){
			$thumbsList.find(".active").removeClass("active");
			$thumbsList.find("a").eq(index).addClass("active");			
		}
	};
//	
	Gallery.controls = {
		init : function() {
			this.build();
			this.observe();
		},
		build : function(){
			data.playing = true;
			$next.unbind('click');
			$prev.unbind('click');
		},
		observe : function() {
			$next.click(function(){
				Gallery.controls.next();
				Gallery.controls.pause();
			});
			$prev.click(function(){
				Gallery.controls.prev();
				Gallery.controls.pause();
			});
		},
		pause : function(){
			Gallery.rotator.stop();
		},
		play : function(){
			Gallery.rotator.start();		
		},
		next : function(){
			Gallery.change(global.active + 1);
		},
		prev : function(){
			Gallery.change(global.active - 1);
		}
	};
//
	Gallery.rotator = {
		start : function() {
			$.doTimeout('gallery2', global.fspeed, function(){
				Gallery.change(global.active + 1);
				data.playing = true;
				return true;
			});
		},
		stop : function(){
			$.doTimeout('gallery2');
			data.playing = false;
		}
	};
//	
};		
//	
};

