// JavaScript Document

var Includer = {
	inc : function (filename)
	{
		$("body").append("<script type='text\/javascript' src='" +filename+ "'><\/script>");	
	}
}

function add_load_event(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

	
function share(){
	if (!document.getElementById("bookmark_link")) return false;
	var bookmark = document.getElementById("bookmark_link");
		bookmark.onclick=function(){
			var ul = document.getElementById("bookmark").getElementsByTagName("ul")[0];
			ul.style.display = "block";
			/*this.getElementsByTagName('a')[0].style.backgroundColor="#FFAA13";
			var linktous = document.getElementById("link");
			var email = document.getElementById("email");
			linktous.getElementsByTagName('a')[0].style.backgroundColor="#e6e6e6";
			email.getElementsByTagName('a')[0].style.backgroundColor="#e6e6e6";*/
			var linktous = document.getElementById("link");
			var dl = linktous.getElementsByTagName("dl")[0];
			dl.style.display = "none";
			var email = document.getElementById("email_to_friend");
			//var email_dl = email.getElementsByTagName("dl")[0];
			email.style.display = "none";
			return false;
		}
		
		var linktous = document.getElementById("link_to_us_link");
		
		linktous.onclick = function(){
			var linktous = document.getElementById("link");
			var dl = linktous.getElementsByTagName("dl")[0];
			
			dl.style.display = "block";
			
			var bookmark = document.getElementById("bookmark");
			
			var ul = bookmark.getElementsByTagName("ul")[0];
			ul.style.display = "none";
			var email = document.getElementById("email_to_friend");
			//var email_dl = email.getElementsByTagName("dl")[0];
			email.style.display = "none";
			
			return false;
			
		}
		
		/*
var email = document.getElementById("email_link");
		email.onclick=function(){
			var email = document.getElementById("email_to_friend");
			//var email_dl = email.getElementsByTagName("dl")[0];
			email.style.display = "block";
			var linktous = document.getElementById("link");
			var dl = linktous.getElementsByTagName("dl")[0];
			dl.style.display = "none";
			var bookmark = document.getElementById("bookmark");
			var ul = bookmark.getElementsByTagName("ul")[0];
			ul.style.display = "none";
			return false;
			
		}
*/
		// email to friend
		$('a#email_link').click(function(){
			$('form#email_to_friend').slideToggle();
			$('#bookmark ul').slideToggle();
			return false;
		});
		
		
		var printpage = document.getElementById("print_link");
		printpage.onclick=function(){
			window.print();
			return false;
		}
		
		var myform= document.getElementById("email_to_friend");
		var button = myform.getElementsByTagName("button")[0];
		button.onclick = function(){
			var myform= document.getElementById("email_to_friend");
			 myform.submit();
		}
		
	
}
add_load_event(share);


/****************************** Secondary Drop Down Menu ********************/
function showDropDown(){
	$(this).find('ul').show();
}

function hideDropDown(){
	//alert("hello");
	$(this).find('ul').hide();
}

function initDropDown(){
	$('ul#primary_navigation li ul').hide();
	
	$('ul#primary_navigation > li').mouseover(showDropDown);
	$('ul#primary_navigation > li').mouseout(hideDropDown);
}

add_load_event(initDropDown);


/****************************** Search Box ********************/

function add_search_box_behaviour() {
	$('input#keywords').focus(function() {
		$(this).val('');
		$(this).addClass('focussed');
	});
}
add_load_event(add_search_box_behaviour);




/**********************************Pop Ups***********************************/

function loadPopUp(src) {
	//alert(src);
	$("#WLpopUp").attr('src',src);
	$("#WLbackgroundPopUp").css({  "opacity": "0.7"  });
	$("#WLbackgroundPopUp").fadeIn("fast");
	$("#WLpopUp").fadeIn("slow");
	centrePopUp();
}

function centrePopUp() {
	//request data for centering  
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = $("#WLpopUp").height();  
	var popupWidth = $("#WLpopUp").width();  
	//centering  
	$("#WLpopUp").css({ 
		"top": windowHeight/2-popupHeight/2,  
		"left": windowWidth/2-popupWidth/2  
	});  
	//only need force for IE6  
	  
	$("#WLbackgroundPopUp").css({  
	"height": windowHeight  
});  
}

function unloadPopUp() {

	$("#WLbackgroundPopUp").fadeOut("fast");
	$("#WLpopUp").fadeOut("fast");

}


$(function() {	
	$(".WLpopUp").click(function() {
		loadPopUp($(this).attr('href'));
		return false;
	});
	
	$("#WLbackgroundPopUp").click(function() {
		unloadPopUp();
	});
	
	$("#WLpopUp").click(function() {
		unloadPopUp();
	});
});






/********************************** Enquiry Form ***********************************/

$(function() {
	if ($("#enquiry_form").length) {
		$("#enquiry_form").validate();
	}
});

// --------------------------------- jquery image fader -----------------------------------
$(function() {
	if ($('#slider').length) {
		//initiate slider
		$('#slider').nivoSlider({
			effect: 'fade'
		});
		//centre navigation
		$('.nivo-controlNav').css('margin-left',(($('#slider').width())/2-($('.nivo-controlNav').width())/2)+'px');
	}
});

// ---------------------------------- Google+ --------------------------------------------
$(function() {
  window.___gcfg = {lang: 'en-GB'};

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
})
