/****** List Item Scroller - Home Page ******/
jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.025
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).width();
				});
				$strip.width(stripWidth);			
				var defTiming = stripWidth/settings.travelocity;
				var totalTravel = stripWidth+containerWidth;								
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};
/***** Call LI Scroll *****/
$(function(){
	$("ul#ticker01").liScroll();
	$("ul#ticker02").liScroll({travelocity: 0.03});
});
/***** End LI Scroller *****/


/***** IMAGE ROTATOR *****/

var rotator_qty = 12;	// rotator quantity
var rotator_no = 1;		// rotator number order, loop from 1 to rotator_qty

function theRotator() {
	for (var i=1; i<=rotator_qty; i++)
	{
		rotator_id = 'div#rotator' + i;						// calculate rotator id from rotator order	
		$(rotator_id + ' ul li').css({opacity: 0.0});		//Set the opacity of all images to 0		
		$(rotator_id + ' ul li:first').css({opacity: 1.0});	//Get the first image and display it (gets set to full opacity)
	}	
	//setInterval('rotate(' + rotator_qty + ')',1500);	//Call the rotator function to run the slideshow, 1000 = change to next image after 1 seconds	
	
	setInterval('rotate()', 4500);
	
}

function rotate() {	
for (var i=1; i<=rotator_qty; i++)	
{	
	rotator_id = 'div#rotator' + i; //rotator_no;				// calculate rotator id from rotator order	
	
	//Get the first image
	var current = ($(rotator_id + ' ul li.show')?  $(rotator_id + ' ul li.show') : $(rotator_id + ' ul li:first'));
	
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $(rotator_id + ' ul li:first') :current.next()) : $(rotator_id + ' ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 2000);

	//Hide the current image
	current.animate({opacity: 0.0}, 2000).removeClass('show');
	
	/*
	rotator_no++;
	if (rotator_no > rotator_qty)
		rotator_no = 1;
	*/	
}		
		
};

$(document).ready(function() {		
	theRotator();
});

/************ GOOGLE MAPS ***************/
function initialize() {
      if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map_canvas"));
        map.setUIToDefault();
		map.addControl(new GLargeMapControl());
		map.disableScrollWheelZoom();
		map.setCenter(new google.maps.LatLng(51.5170601, -0.116850435734), 15);
		
		function createMarker(point, icon, html) {
			var marker = new GMarker(point, icon);
			GEvent.addListener(marker, "click", function() {
			/*marker.openInfoWindowHtml(html);*/
			});
			return marker;
		}
	
		/*The Lincoln Centre coordinates */
		
		/* other locations */
		var newpoints = Array();
		newpoints[0] = Array(51.5170601,-0.116850435734,'#',"<div class='title'>The Lincoln Centre</div><div class='detail'>18 Lincoln's Inn Fields<br/>London, WC2A 3ED<br/>Tel: 0207 936 1300</div>");
		
		/*newpoints[1] = Array(51.51,-0.1185,'#',"<div class='title'><strong>Holiday Inn London Regents Park</strong></div><div class='detail'>Carburton Street<br />London<br />W1W 5EE<br /><br /><div class='telephone' title='Telephone'>0870 400 9111</div><div class='website' title='Website'><a href=\"http://www.holidayinn.co.uk\" target=\"_blank\">www.holidayinn.co.uk</a></div></div>");
		
		newpoints[2] = Array(51.52,-0.119,'#',"<div class='title'><strong>Grange Fitzrovia Hotel</strong></div><div class='detail'>20-28 Bolsover Street<br />London<br />W1W 5NB<br /><br /><div class='telephone' title='Telephone'>+44 (0) 20 7467 7000</div><div class='fax' title='Fax'>+44 (0) 20 7636 5085</div><div class='email' title='Email'><a href=\"mailto:reservations@grangehotels.com\">reservations@grangehotels.com</a></div><div class='website' title='Website'><a href=\"http://www.grangehotels.com\" target=\"_blank\">www.grangehotels.com</a></div></div>");
		*/
		var icon = new GIcon();
		icon.image = "images/mapicon.png";
		icon.shadow = "images/shadow-mapicon.png";
		icon.iconSize = new GSize(90.0, 77.0);
		icon.shadowSize = new GSize(129.0, 77.0);
		icon.iconAnchor = new GPoint(30, 77.0);
		icon.infoWindowAnchor = new GPoint(30, 77.0);
		
		var point = new GLatLng(newpoints[0][0], newpoints[0][1]);
		map.addOverlay(createMarker(point, icon, newpoints[0][3]));	

		for(var i = 1; i < newpoints.length; i++) {
			var point = new GPoint(newpoints[i][1],newpoints[i][0]);
			var popuphtml = newpoints[i][3] ;
			var marker = createMarker(point,newpoints[i][2],popuphtml);
			map.addOverlay(marker);
		}

      }
    }		

/******** FORM FOCUS **********/
$(document).ready(function() {
	$('input[type="text"]').addClass("idle");
	$('input[type="text"]').focus(function() {
		$(this).removeClass("idle").addClass("focus");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('input[type="text"]').blur(function() {
		$(this).removeClass("focus").addClass("idle");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
});	

$(document).ready(function() {
	$('textarea').addClass("idle");
	$('textarea').focus(function() {
		$(this).removeClass("idle").addClass("focus");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('textarea').blur(function() {
		$(this).removeClass("focus").addClass("idle");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
});

/******** TABBED CONTENT **********/
// When the document loads do everything inside here ...
$(document).ready(function(){
	// When a link is clicked
	$("a.button").click(function () {
		
		// switch all tabs off
		$(".active").removeClass("active");
		
		// switch this tab on
		$(this).addClass("active");
		
		// hide all tabbed-content
		$(".tabbed-content").removeClass("active");
		
		// show active content
		var content_show = $(this).attr("title");
		$("#"+content_show).addClass("active");
	  
	});
});