//when page loads start standard functions
function initialize() {
	//replace external links with open in new window
	externalLinks();
}

window.onload = initialize;


function $import(src){
	var scriptElem = document.createElement('script');
  scriptElem.setAttribute('src',src);
	scriptElem.setAttribute('type','text/javascript');
	document.getElementsByTagName('head')[0].appendChild(scriptElem);
}


// import with a random query parameter to avoid caching
function $importNoCache(src){
	var ms = new Date().getTime().toString();
	var seed = "?" + ms; 
	$import(src + seed);
}


function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors .length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
			anchor.title = (anchor.title != "") ? anchor.title+" (opens in a new window) ": "opens in a new window";
			anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external';
//			anchor.onclick = 'javascript: pageTracker._trackPageview (\'/outgoing/'+anchor.href+'\');';
			var track = anchor.href;
			track = track.replace('http://','');
			anchor.onclick = function() { 
				pageTracker._trackPageview('/outgoing/'+track);
			}
		}
	}
}

function prepareSearchBox ()
{
	document.getElementById('q').style.width = '200px';
	document.getElementById('search-area').style.width = '300px';
	if(document.getElementById('q').value=='enter keywords') document.getElementById('q').value='';
}

function resetSearchBox ()
{
	document.getElementById('search-area').style.width = '200px';
	document.getElementById('q').style.width = '100px';
}

function prepareName()
{

	if(document.getElementById('name').value=='your name') document.getElementById('name').value='';
}

function prepareEmail()
{
	if(document.getElementById('email').value=='your email address') document.getElementById('email').value='';
}

function sendRegisterForm()
{
	var string = $("#registerForm").serialize();
	$.getJSON("/content/processregister.php?" + string + "&callback=?", function(json) { 
		if(json.result==true)
		{
			$("#registerContent").html("<br/><h2>Thank you for adding your details.</h2><br/>");
		} else {
			$("#registerContent").append("<p style=\"color:red;\">There was a problem please refresh the page and try again</p>");
		}
	}); 

	return false;
}

$(document).ready(function() {

	// Reset Font Size
	var originalFontSize = $('html').css('font-size');
		  $(".resetFont").click(function(){
		  $('html').css('font-size', originalFontSize);
	});
	
	// Increase Font Size
	$(".increaseFont").click(function(){
		var currentFontSize = $('html').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		$('html').css('font-size', newFontSize);
		return false;
	});
	
	// Decrease Font Size
	$(".decreaseFont").click(function(){
		var currentFontSize = $('html').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.8;
		$('html').css('font-size', newFontSize);
		return false;
	});

	//menu initialiser
	$('#main-links > li').bind('mouseover', mmul_open);
	$('#main-links > li').bind('mouseout',  mmul_timer);

	if ($(".compact_description").length > 0 ) {
		$(".compact_description").each(function(){
			$(this).append("<div class=\"read_more_div\"><a href=\"#empty\" class=\"read_more\">read more...</a></div>");

			$(".read_more", $(this)).bind("click", (function () {
				if($(this).html()=="read more...")
				{
					$(this).parent().css("position","relative");
					$(this).parent().parent().css("height","auto");
					$(this).html("read less...");
				} else {
					$(this).parent().css("position","absolute");
					$(this).parent().parent().css("height","150px");
					$(this).html("read more...");
				}
			}));
		});
	}

	if ($(".compact_booking_information").length > 0 ) {
		$(".compact_booking_information").each(function(){
			$(this).append("<div class=\"read_more_div\"><a href=\"#empty\" class=\"read_more\">read more...</a></div>");

			$(".read_more", $(this)).bind("click", (function () {
				if($(this).html()=="read more...")
				{
					$(this).parent().css("position","relative");
					$(this).parent().parent().css("height","auto");
					$(this).html("read less...");
				} else {
					$(this).parent().css("position","absolute");
					$(this).parent().parent().css("height","150px");
					$(this).html("read more...");
				}
			}));
		});
	}


});
