var hasFlash = DetectFlashVer(7,0,0);

sub_path = "";
im1 = new Image(); im1.src = sub_path + "/common/im/wait_msg.gif"

function show_wait_msg(x)
{
  image_name = "wait_msg" + x
  document.images[image_name].src = sub_path + "/common/im/wait_msg.gif"
}

submitted = 0;
function sub ()
{
	if (submitted) return;
	
	act = arguments[0]; //action
	conf = arguments[1]; //confirmation - set to 1 if requiring confirmation. else don't set it at all.
	
	OK = 0;
	if (conf == 1)
	{
		OK = confirm('Are you sure?');
	}
	
	if (OK || !isset(conf))
	{
		submitted = 1;
		df = document.form1;
		df.act.value = act;
		df.action = location.href;
		df.submit();
	}
}

function runCountryCheck(country_var)
{
	id = document.getElementById(country_var); //get country selected
	county_div = document.getElementById('counties'); 
	
	if (county_arr[id.value])
	{
		county_div.innerHTML = county_arr[id.value];
		document.getElementById('county_container').style.display = "block"
	}
	else 
	{
		county_div.innerHTML = county_arr['unsel'];
		document.getElementById('county_container').style.display = "block"
	}
}


/* NAVIGATION */
var main_menu_bg_color = "#877D6D";
var main_menu_bg_hover_color = "#BAAFA2";

function get_start_pos (elem) 
{
	var start_pos = 0;
	var loops1 = 0;
	while (elem.prev().width() > 0)
	{
		elem = elem.prev();
		start_pos += elem.width();	
		if (loops1++ > 50) return;
	}
	return start_pos;
}

function do_load()
{
}

function scroll_header()
{
	if (!location.hash) window.scrollTo(0, 150);
}

function isset(variable) {
    return typeof(variable) != "undefined" && variable !== null;
}

var win1

function newWin(url,w,h) {
if (win1 && win1.open || win1 && !win1.closed){win1.close()}
win1 = window.open(url,"win1","width="+w+",height="+h+",toolbar=no,location=no,menubar=no,status=no,scrollbars=no,resizable=yes")
}

function init_page()
{
	/*$('.mainImg').css("opacity", 0);
	$(".mainImg").animate({ opacity: 1.0 }, 500); */
	
	$('#main_menu ul li ul').hide(); //hide drop downs on entry
	
	$('#main_menu ul li').hover( function() {
	  //keep button's background on while submenu on
	  $(this).children('a.level0').css("background", main_menu_bg_hover_color);
	  //get left pos of sub menu
	  var sub_menu_pos = get_start_pos($(this)) ;
	  $(this).find("ul").css("left", sub_menu_pos + 2); 
	  //get width of sub menu
	  var sub_menu_width = $(this).width() - 2;
	  $(this).find("ul li").css("min-width", sub_menu_width);
	  $(this).find("ul").css("min-width", sub_menu_width); 
	  //show submenu
	  $(this).find("ul").stop(true, true).fadeIn('500'); 
			}, 
		//else hide it
		function () {
			$(this).children('a.level0').css("background", main_menu_bg_color);
			$(this).find("ul").stop(true, true).fadeOut('fast'); 
	});
}

$(document).ready(function() { 	
	init_page (); 
	expand_div();
	show_search();
	toggle_preview_menu();
	fb();
});	

//image expander
function fb() 
{
	$("a.fb").fancybox({
		'transitionIn'					:	'fade',
		'speedIn'						:	700, 
		'speedOut'					:	300, 
		'hideOnContentClick'	:	true,
		'overlayColor'				:	'#FFFFFF',
		'overlayOpacity'			:	0.8,
		'padding'						:	1		
	});
}

//Search stuff --------------------------------

im_s = new Image(); im_s.src = sub_path + "/im_cms/but_search_ani.gif"
im_s1 = new Image(); im_s1.src = sub_path + "/im_cms/but_search_ani1.gif"

var retain_search_box = 0;

/*function submitSearch()
{
	retain_search_box = 1;
	if (document.searchform.searchfield.value.length >= 3)
	{
		document.getElementById('searchButton').src = "/im_cms/but_search_ani.gif"; //dark coloured button
		return true;
	}
	else
	{
		document.searchform.searchfield.focus();
		return false;
	}
}
*/
function submitSearch(form_name)
{
	retain_search_box = 1;
	if (document.getElementById(form_name).searchfield.value.length >= 3)
	{
		if (form_name == "searchform")
		{
			document.getElementById('searchButton').src = "/im_cms/but_search_ani.gif"; //dark button
		}
		else
		{
			document.getElementById('searchButton1').src = "/im_cms/but_search_ani1.gif"; //light button
		}
		return true;
	}
	else
	{
		document.getElementById(form_name).searchfield.focus();
		return false;
	}
}


function show_search() 
{
	$('#searchDivInner').hide();
	
	$('#searchfield').focus(
		function () {
			retain_search_box = 1;
		}
	);
	
	$('a.showSearch').mouseover(
		function() {
			$('#searchDivInner').fadeIn();
		}
	);
	$('div#searchDivInner').mouseleave( 
		function() { 
			if (!retain_search_box) {
				$('#searchDivInner').fadeOut();
			}
		}		
	);
	$('a#but_search_tips').click(
		function() {
			$('#search_tips').toggle('fast');
			return false;
		}
	);	
}


//end search stuff ---------------------------

//preview menu stuff ------------------------
function toggle_preview_menu () {
	$('a#but_pm_show_hide').click( 
		function () {
		 	if ($.cookie("pm_toggle") == "hide") //switch to showing div
			{
				$.cookie("pm_toggle", "show", { expires: 30 });
				$('#preview_menu').addClass("preview_menu_show");
				$('#preview_menu').removeClass("preview_menu_hide");
			}
			else
			{
				$.cookie("pm_toggle", "hide", { expires: 30 });
				$('#preview_menu').addClass("preview_menu_hide");
				$('#preview_menu').removeClass("preview_menu_show");
			}
			this.blur();
		 }
	);
}

//end pm stuff --------------------------------

function expand_div() {	
	$('.slideContent').hide(); //hide all these slides initially
	//expand div if title clicked
	$('a.slideTitle').click(
		function() {
			$(this).blur();
			if(!$(this).next().is(':visible')) var openThis = 1;
			//close all sliders
			$('.slideTitle').removeClass("slideTitleBold");
			$('.slideContent:visible').slideUp('fast');
			$('.slideContentOpen:visible').slideUp('fast');
			$.cookie("slides", "closed", { path: '/' });
			//open this one
			if (openThis) {
				$(this).addClass("slideTitleBold");
				$(this).next().slideDown('fast');
				$.cookie("slides", "open", { path: '/' });
			}
			return false;
		}
	);
	//on close click close all open (i.e. just this div)
	$('a.slideClose').click(
		function() {
			$('.slideTitle').removeClass("slideTitleBold");
			$('.slideContent:visible').slideUp('slow');
			$('.slideContentOpen:visible').slideUp('slow');
			$.cookie("slides", "closed", { path: '/' });
			return false;
		}
	);
}

function hide_slide_divs() {
	$('.slideContent').hide(); //hide all slideable divs
}

function hideIt(div_id) 
{
	document.getElementById(div_id).style.display='none';
}
 
function showIt(div_id) 
{
	document.getElementById(div_id).style.display='block'
}
