$(function() {
	$('#sc_loc').submit(function(e){
		if($.trim($('#sc_postcode').val())==''){
			alert('Please enter a postcode first.');
			$('#sc_postcode').focus();
			e.preventDefault();
		}else {
			return true;
		}
	});
	var selected = null;
	$('#main_navigation .top_link').each(function(){
		if(document.location.href.indexOf($(this).attr('href')) != -1){
			if(selected){
				selected.removeClass('active');
			}
			selected = $(this);
			$(this).addClass('active');
		}
	});
	// Make CSS work in older browsers
	$('body').delegate('a', 'mousedown', function() {
		$(this).get(0).hideFocus = true;
	});
	$('#page_banner .subheading li').each(function() {
		var $w = $(this).width();
		$(this).css({'width': $w + 'px'});
	});
	$('div.nav ol li:first-child a').addClass('first');
	$('div.nav ol li li:last-child, #pre_footer section:last-child, footer .half_col:last-child, #page_banner div.nav li:last-child').addClass('last');
	$('#page_banner .subheading li:first-child').addClass('first');

	// Navigation
// 	$('div.nav > ol> li > div').css('opacity', '0.95').hide();
// 	$('div.nav > ol > li').live('mouseenter mouseleave', function() {
// 		$(this).toggleClass('hover');
// 		$(this).children('div').toggle(200);
// 	});

	// Rounded corners on buttons as IE doesn't support border-radius
	if ($.browser.msie) {
	    $('.blue_btn, .dark_btn')
	    .css({
			'background-color': 'transparent',
			'padding-top': 0,
			'padding-bottom': 0,
			'border': 'none'
	    })
	    .html(function(ind, htm) {
			return '<span>' + htm + '</span>';
		})
		.live('mouseenter', function() {
			$(this).css('background-position', 'right -24px');
			$(this).children('span').css('background-position', '0 -24px');
		})
		.live('mouseleave', function() {
			$(this).css('background-position', 'right 0');
			$(this).children('span').css('background-position', '0 0');
		});
		$('div.nav > ol > li').hover(
			function(){$(this).addClass('hover')},
			function(){$(this).removeClass('hover')}
		);
		$('.gray_btn')
	    .css({
			'background-color': 'transparent',
			'padding-top': 0,
			'padding-bottom': 0,
			'border': 'none'
	    })
	    .html(function(ind, htm) {
			return '<span>' + htm + '</span>';
		})
		.live('mouseenter', function() {
			$(this).css('background-position', 'right -30px');
			$(this).children('span').css('background-position', '0 -30px');
		})
		.live('mouseleave', function() {
			$(this).css('background-position', 'right 0');
			$(this).children('span').css('background-position', '0 0');
		})
	}
	
	// Detail page tabbed panel
	var $tabContent = $('.tabbed_panel .tabbed_content');
	var $tabs = $('.tabbed_panel ul li a');
	var $contHeight = 0;
	$tabContent.each(function() {
		if ($(this).outerHeight() > $contHeight) {
			$contHeight = $(this).outerHeight();
		}
	});
	$tabContent.css({
		'position': 'absolute',
		'top': '30px',
		'left': '10px',
		'display': 'none',
		'height': $contHeight + 'px'
	});
	$('.tabbed_panel .canvas').css('height', $contHeight + 'px');
	$tabContent.eq(0).css('display', 'block');
	$tabs.eq(0).addClass('active');
	$tabs.click(function() {
		$tabs.removeClass('active');
		$(this).addClass('active');
		var $contentID = $(this).attr('href');
		$tabContent.hide();
		$($contentID).delay(200).slideDown(200);
		return false;
	});
	if ($.browser.msie) {
		$('.tabbed_panel ul li a').append('<span class="cr" />');
	}

	$('#btn_book').click(function(e){
	
		if ($.cookie('default_remember')=="true") {
			$('#username').val($.cookie('default_username'));
			$('#password').val($.cookie('default_password'));
			$('#remember').attr('checked', 'checked');
		};

		$('#loginPanel').show();
		$('#startPanel').hide();
		
		e.preventDefault();
	});
	
	$('#cancel_btn').click(function(e){
		$('#loginPanel').hide();
		$('#startPanel').show();
		e.preventDefault();
	});
	
	$('#btn_quik').click(function(e){
		$('#quikPanel').show();
		$('#startPanel').hide();
		e.preventDefault();
	});
	
	$('#cancelquik_btn').click(function(e){
		$('#quikPanel').hide();
		$('#startPanel').show();
		e.preventDefault();
	});
	
	$('#loginBtn').click(function(e){

		if (($('#username').val()=='') || ($('#password').val()=='')) {
			alert("Please enter your account number and password.");
			e.preventDefault();
		}	
	});
	$('#loginForm').submit(function(e){
	
		var winOptions = "";
		var width = $(document).width();
		var height = $(document).height();
		
 		var l = (width-960)/2;
  		var h = 50;
		
		winOptions="left="+l+",top="+h+",width=960,height=800,toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes,titlebar=no";
		
		var newWindow = window.open($(this).attr('action'), "newWindow", winOptions);
		if(newWindow.blur){$(newWindow).focus();};
		$(this).attr('target','newWindow');
		//e.preventDefault();
	});
	
	$('#serviceDemo').click(function(e){
	
		var winOptions = "";
		var width = $(document).width();
		var height = $(document).height();
		
 		var l = (width-720)/2;
  		var h = 150;
		
		winOptions="left="+l+",top="+h+",width=720,height=550,toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes,titlebar=no";
		
		var newWindow = window.open($(this).attr('href'), "newWindow", winOptions);
		if(newWindow.blur){newWindow.focus();};
 		e.preventDefault();
	});
	
	$('#technologyDemo').click(function(e){
	
		var winOptions = "";
		var width = $(document).width();
		var height = $(document).height();
		
 		var l = (width-520)/2;
  		var h = 150;
		
		winOptions="left="+l+",top="+h+",width=520,height=440,toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes,titlebar=no";
		
		var newWindow = window.open($(this).attr('href'), "newWindow", winOptions);
		if(newWindow.blur){newWindow.focus();};
 		e.preventDefault();
	});
	
	$('#onlineDemo').click(function(e){
	
		var winOptions = "";
		var width = $(document).width();
		var height = $(document).height();
		
 		var l = (width-1030)/2;
  		var h = 50;
		
		winOptions="left="+l+",top="+h+",width=1030,height=778,toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes,titlebar=no";
		
		var newWindow = window.open($(this).attr('href'), "newWindow", winOptions);
		if(newWindow.blur){newWindow.focus();};
 		e.preventDefault();
	});
	
	// Sub Detail page subnav
// 	var $navSub = $('#page_subnav ul');
// 	var $navTabs = $('#page_subheadings ul li a');
// 	var $navSubHeight = 0;
// 	$navSub.each(function() {
// 		if ($(this).outerHeight() > $navSubHeight) {
// 			$navSubHeight = $(this).outerHeight();
// 		}
// 	});
// 	$navSub.css({
// 		'position': 'absolute',
// 		'top': '0px',
// 		'left': '8px',
// 		'display': 'none',
// 		'height': $navSubHeight + 'px'
// 	});
// 	$('#page_subnav').css('height', $navSubHeight + 'px');
// 	$navSub.eq(0).css('display', 'block');
// 	$navTabs.parent('li').eq(0).addClass('active');
// 	$navTabs.click(function() {
// 		$navTabs.parent('li').removeClass('active');
// 		$(this).parent('li').eq(0).addClass('active');
// 		var $contentID = $(this).attr('href');
// 		$navSub.hide();
// 		$($contentID).show(0);
// 		return false;
// 	});
});