var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

BrowserDetect.init();

//document.write('<p class="accent">You\'re using ' + BrowserDetect.browser + ' ' + BrowserDetect.version + ' on ' + BrowserDetect.OS + '!</p>');

$(document).ready(function() {

	if(BrowserDetect.browser == 'Opera') {
	
		//alert(BrowserDetect.browser);
		
		$('#sitenav li').css({fontSize:'11px'});
		$('h3').css({fontSize:'10px'});
		$('#subnav').css({fontSize:'10px'});
		$('#subnav li.selected a').css({fontSize:'11px'});
		$('#reservations li').css({fontSize:'10px'});

	}

	$('#btnSearch').hover(function() {
    	$(this).css({'cursor' : 'pointer'});
    });
    
    $('#home-slideshow div.ss-caption').hide();
    
    var urls = [ '1', '2', '3', '4', '5', '6' ];
		
	$.preload( urls, {
		base:'http://eastbaysuites.fasterproductions.com/assets/slides/',
		ext:'.jpg',
		onComplete:function( data ){
		},
		onFinish:function(){
			$('#home-slideshow div.ss-caption').fadeIn();
			$('#home-slideshow').cycle({ 
			    fx:		'fade', 
			    speed:	 800, 
			    timeout: 8000
			});
		}
	});

	$("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'facebook', showTitle: false, animationSpeed: 'slow', opacity: 0.5 });

	var roomLinks = $("a.room-link");
	var roomTypes = $("div.room-set");
		
	roomLinks.parent("li").hover(function() {
		$(this).css({'cursor' : 'pointer'});
	});
	
	roomLinks.click(function(e) {
	
		e.preventDefault();
		var a = this.hash;
			a = a.replace("#","rs-");
			
		roomTypes.hide().filter('#' + a).fadeIn("normal");
		roomLinks.parent("li").removeClass("selected");
		$(this).parent("li").addClass("selected");
	
	});
	
	
	if(document.getElementById("neighbor-slides")) {
		$('#neighbor-slides').cycle({ 
		    fx:		 'scrollLeft', 
		    speed:	 500,
		    timeout: 8000, 
		    pager:   '#nav',
		    pagerAnchorBuilder: function(idx, slide) { 
		        // return selector string for existing anchor 
		        return '#nav li:eq(' + idx + ') a';
		    }
		});
		
		$('#nav li a').click(function() {
			$('#neighbor-slides').cycle('pause');
		})
	}

	// set room galleries
	var cnt=1;

	$('.room-gallery').each(function() {
	
		$(this).children("ul.thumbs").show();
	
		$('#g' + cnt + ' .slideshow').cycle({ 
		    fx:     'fade', 
		    speed:  'fast', 
		    timeout: 0, 
		    pager:  '#g' + cnt + ' .thumbs', 
		    pagerAnchorBuilder: function(idx, slide) {  
		        return '#g' + cnt + ' .thumbs li:eq(' + idx + ') a'; 
		    } 
		});
		cnt++;
    });

	function formatTitle(title, currentArray, currentIndex, currentOpts) {
	    //return '<div id="gallery-title">' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
	}
	
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
   		return this.animate({opacity: 'toggle'}, speed, easing, callback);
	};
	
	if(document.getElementById("commentform")) {
		$("#commentform").validate();
	}
	
	if(document.getElementById("mc-embedded-subscribe-form")) {
		$("#mc-embedded-subscribe-form").validate();
	}
	
	if(document.getElementById("fsForm966039")) {
		$("#fsForm966039").validate();
	}

});

$.fn.cycle.updateActivePagerLink = function(pager, currSlide, clsName) {
	$(pager).each(function() {
		$(this).children('li').children('a').removeClass('activeSlide').fadeTo(0, 1.0).filter(':eq('+currSlide+')').fadeTo(150, 0.6).addClass('activeSlide');
	});
};

// original pop-up

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

