// JavaScript Document

// EDIT THESE VALUES IF REQUIRED
var alertText = 'Are you sure you wish to perform this action' + "\n"; //DEFAULT TEXT DISPLAYED ON CONFIRM BUTTONS/LINKS WHEN NO ALT/TITLE
var newWindowLink = true; //OPEN EXTERNAL LINKS BY DEFAULT IN A NEW WINDOW (TRUE/FALSE)?


var woms = new Array(); //CREATE ARRAY OF FUNCTIONS TO LAUNCH ONLOAD

//ONLOAD MANAGER
function womOn(){
  window.onload = womGo;
}

function womGo(){
  for(var i = 0;i < woms.length;i++)
    eval(woms[i]);
}

function womAdd(func){
  woms[woms.length] = func;
}

function CreateBookmarkLink() {

	title = document.title;
	url = window.location.href;
	
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,"");
	} else if(window.external) {
		window.external.AddFavorite( url, title); 
	} else if(window.opera && window.print) {
		return true;
	}
	
}

function objToggle(obj) { 

	var obj = document.getElementById(obj);

	if(obj.style.display == "block") { 
		obj.style.display = "none";
	} else { 
		obj.style.display = "block";
	}

}

function sectorGallery() {
	
	if($('.gallerylinks').length == 0) return false;
	
	$('.gallerylinks ul li a').click(function() {
		
		var href = $(this).attr('href');
		
		var image = imageInfo(href); //Get the image information

		layoutUpdate(image); //Update the layout

		$('#place_holder').attr('src', href);
		
		return false;
	
	});
	
	$('.gallerythumbs ul li a').click(function() {
		
		var href = $(this).attr('href');
		
		var image = imageInfo(href); //Get the image information
		
		layoutUpdate(image); //Update the layout
		
		$('#place_holder').attr('src', href);
		
		return false;
	
	});
	
}

function layoutUpdate(image) {

	var css_style = '_landscape'; //Set the style for the page layout

	if(image['width'] < image['height']) { //Portrait Image
		
		css_style = '_portrait';
		
	}
	
	$('#place_holder').parent().attr('id', 'galleryimage' + css_style); //Set the id of the div above the main image
	$('.gallerythumbs').attr('id', 'gallerythumbs' + css_style); //Update the id of the thumbnails
	$('.gallerylinks').attr('id', 'gallerylinks' + css_style);

}

function imageInfo(imageSrc) {
		
	var image = new Image(); //Create a new image object
	
	image.src = imageSrc; //Set the location of the image
	
	var dimentions = {
		'width' : image.width,
		'height' : image.height
	}
	
	return dimentions;

}

$(document).ready(function(){

	maps(); //On js/gmaps.js
	sectorGallery();

});
