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

var rotator_qty = 5;	// 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 + ')',4000);	//Call the rotator function to run the slideshow
	//setInterval('rotate()', 4500);
	
}

function rotate() {	
	for (var i=1; i<=rotator_qty; i++)	
	{	
		rotator_id = 'div#rotator' + i; // 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');
	}		
};

$(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>");
		
		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
	$(".tab-menu a").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");
	  
	});
});
