// Simple jQuery Slideshow Script
// Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify,
// not responsible for anything, etc.  Please link out to me if you like it :)
function slideSwitch() {
	if ($('#slideshow img').length>1) {
	    var $active = $('#slideshow img.active');

	    if ( $active.length == 0 ) $active = $('#slideshow img:last');

	    var $next =  $active.next().length ? $active.next()
	        : $('#slideshow img:first');

	    $active.addClass('last-active');
    
//    $('#slideshowCaption').html($active.attr('title'));
// +'<div id="slideshowCaption">Hello world</div>'
//    $next.append('<div id="slideshowCaption">'+$next.attr('title')+'</div>')
	    $next.css({opacity: 0.0})
	        .addClass('active')
	        .animate({opacity: 1.0}, 1000, function() {
	            $active.removeClass('active last-active');
	        });
	}
}

/* x_cook.js compiled from X 4.0 with XC 0.27b. Distributed by GNU LGPL. For copyrights, license, documentation and more visit Cross-Browser.com */
function xDeleteCookie(name, path){if (xGetCookie(name)) {document.cookie = name + "=" +"; path=" + ((!path) ? "/" : path) +"; expires=" + new Date(0).toGMTString();}}function xGetCookie(name){var value=null, search=name+"=";if (document.cookie.length > 0) {var offset = document.cookie.indexOf(search);if (offset != -1) {offset += search.length;var end = document.cookie.indexOf(";", offset);if (end == -1) end = document.cookie.length;value = unescape(document.cookie.substring(offset, end));}}return value;}function xSetCookie(name, value, expire, path){document.cookie = name + "=" + escape(value) +((!expire) ? "" : ("; expires=" + expire.toGMTString())) +"; path=" + ((!path) ? "/" : path);}

// xCookie r2, Copyright 2009 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
var xCookie = {
  get: function(name) {
    var c = document.cookie.match(new RegExp('(^|;)\\s*' + name + '=([^;\\s]*)'));  
    return ((c && c.length >= 3) ? unescape(c[2]) : null);  
  },
  set: function(name, value, days, path, domain, secure) {
    if (days) {
      var d = new Date();
      d.setTime(d.getTime() + (days * 8.64e7)); // now + days in milliseconds
    }
    document.cookie = name + '=' + escape(value) +
      (days ? ('; expires=' + d.toGMTString()) : '') +
      '; path=' + (path || '/') +
      (domain ? ('; domain=' + domain) : '') +
      (secure ? '; secure' : '');
  },
  del: function(name, path, domain) {
    this.set(name, '', -1, path, domain); // sets expiry to now - 1 day
  }
};

function popup(doc,name,scroll,width,height,resize,status,toolbar,locbar,menubar,dirs) {
  var scr = ((scroll) ? ",scrollbars="+scroll : "");
  var wid = ((width) ? ",width="+width : "");
  var hei = ((height) ? ",height="+height : "");
  var res = ((resize) ? ",resizable="+resize : "");
  var sta = ((status) ? ",status="+status : "");
  var too = ((toolbar) ? ",toolbar="+toolbar : "");
  var loc = ((locbar) ? ",location="+locbar : "");
  var men = ((menubar) ? ",menubar="+menubar : "");
  var dir = ((dirs) ? ",directories="+dirs : "");
  remoteWin=window.open(doc,name,scr+wid+hei+res+sta+too+loc+men+dir);
  remoteWin.focus();
}

function ccDialog() {
	$('#currencyConverterModal').dialog({
		width: 295,
		height: 240,
		modal: true,
		title: 'Currency converter'
	});
//		return false;
}


function doSubmission(form) {
  eleArr = form.elements;
  var problems = "";
  var ready = true;
  var flag = false;
  for (i=0; i<eleArr.length; i++) {
    if (eleArr[i].className.match("required")) {
      switch (eleArr[i].type) {
        case 'text' :
        case 'textarea' : {
          flag = (eleArr[i].value=="");
          break;
        }
        case 'checkbox' : {
          flag = !(eleArr[i].checked);
          break;
        }
        case 'select-one' : {
          flag = (eleArr[i].options[eleArr[i].options.selectedIndex].value=="none");
          break;
        }
        default : flag = true;
      }
      if (flag) {
        problems+="  - "+eleArr[i].title+"\n";
        ready = false;
      }
    }
    flag = false;
  }
  if (!ready) alert('The following fields are required\nbut are empty or contain errors:\n\n'+problems+'\nPlease go back and complete the form.');
  return ready;
//  return false;
}


$(function() {

  $('#slideshow').html($('div.slides:eq(0)').html());
  setInterval( "slideSwitch()", 5000 );

	$('#tabs').tabs({
	  select: function(event, ui) {
	    $('#slideshow').html($('#'+ui.panel.id+' .slides').html())
	    ui.tab.blur();
	  }
	});

	$('a.currencyConverter').click(ccDialog);

	$('body.eventsPage ul.events:eq(0)').height(($('body.eventsPage ul.events:eq(0) li:eq(0)').height()*Math.ceil($('body.eventsPage ul.events:eq(0) li').length/4))-10);
	$('body.eventsPage ul.events:eq(1)').height(($('body.eventsPage ul.events:eq(1) li:eq(1)').height()*Math.ceil($('body.eventsPage ul.events:eq(1) li').length/4))-10);

  if ($('body.singleHotel').length==0) {
    $("body.hotelPage #tabs").tabs({ selected: 1 });
  }

	$("a.popup").click(function() { window.open(this.href); return false; });
	
	$("input:submit, button").button();
	$("#backButton, #prevButton").button("option", "icons", { primary: "ui-icon-triangle-1-w" });
	$("#nextButton").button("option", "icons", { secondary: "ui-icon-triangle-1-e" });
	
	if ($("body.homePage #leftCol").outerHeight() > $("body.homePage #rightCol").innerHeight()) $("body.homePage #rightCol").height($("body.homePage #leftCol").outerHeight()-($("body.homePage #rightCol").outerHeight()-$("body.homePage #rightCol").height()))

});

