$().ready(function(){

	/*
	 *		Get the height and width of the browser window
	 *		
	 *		by Andy Langton - 12/04/2007
	*/

	var viewportwidth;
	var viewportheight;

	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	 
	} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	 
	}else{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}


	/*
	 *		Set coverage viewport overflow to hidden if JavaScript is enabled
	 *		
	 *		by Ricky Stevens - 16/06/2009
	*/
	
	$('#coverage-wrap').css({'overflow' : 'hidden'});
	

	/*
	 *		Configure FancyBox for use, and hijack the href it uses [ aditional fancybox hacks created in core fancybox file ]
	 *		
	 *		by Ricky Stevens - 18/06/2009
	*/

	$('.fancy').each(function(){
		
		var page = $(this).attr('href').split('/press-archive');
		var link = '/doAjax/article' + page[1];
		var details = [{href: link, title: ''}];

		$(this).fancybox({
			'itemArray': details,
			'hideOnContentClick': false,
			'padding': 0,
			'zoomSpeedIn': 300,
			'zoomSpeedOut': 300,
			'frameWidth':	(viewportwidth - 200),
			'frameHeight':	(viewportheight - 200),
			'overlayShow':	true,
			'overlayOpacity':	0.6,
			'easingIn' : 'easeOutBack',
			'easingOut' : 'easeInBack',
			'centerOnScroll': false
		});
		
	});
	

	/*
	 *		Window re-locator using onChange event of a <select>
	 *		
	 *		by Ricky Stevens - 12/06/2009
	*/

	$('#who').change(function(){

		switch($('#who').val()) {

			case "1":
				window.location.replace('/who-are-you/startups-and-small-companies');
			break;

			case "2":
				window.location.replace('/who-are-you/internet-based');
			break;

			case "3":
				window.location.replace('/who-are-you/large-or-corporate');
			break;

			case "4":
				window.location.replace('/who-are-you/pr-agency');
			break;

			case "5":
				window.location.replace('/who-are-you/individuals');
			break;

		}

		return false;

	});


	/*
	 *		Remove the default text from a <input> onClick
	 *		
	 *		by Ricky Stevens - 08/06/2009
	*/

	$('#telephone').click(function(){
		
		if($('#telephone').val() == 'Insert Telephone Number') $('#telephone').val('');

		return false;

	});


	/*
	 *		Add the default text from a <input> when it loses focus, if it is blank
	 *		
	 *		by Ricky Stevens - 08/06/2009
	*/

	$('#telephone').blur(function(){
		
		if($('#telephone').val() == '') $('#telephone').val('Insert Telephone Number');

		return false;

	});


	/*
	 *		Slider function to manipulate specified site content using jQueries .slideToggle
	 *		
	 *		by Ricky Stevens - 16/06/2009
	*/

	$('.slider').each(function() {
		if ($(this).hasClass('firstSlider')) {
			$('.slider-footer',this).html('<span style="margin-right: 15px;">CLOSE</span>');
		}else{
			$('.slider-body',this).css({'display': 'none'});
			$('.slider-footer',this).html('<span style="margin-right: 15px;">OPEN</span>');
		}
	});

	$(".slider").click(function() {

		$(".slider-body",this).slideToggle();

		if($('.slider-footer',this).html() == '<span style="margin-right: 15px;">CLOSE</span>') { 
			$('.slider-footer',this).html('<span style="margin-right: 15px;">OPEN</span>');
		}else{
			$('.slider-footer',this).html('<span style="margin-right: 15px;">CLOSE</span>');
		}

		return false;
 	});

	/*
	 *		Form element styling, that gives selected form elements a border change
	 *		
	 *		by Ricky Stevens - 24/06/2009
	*/

	$('.form-hover').focus(function() {
		$(this).css("background","#e8f3fb");
		$(this).css("border","1px solid #5babec");
	});

	$('.form-hover').blur(function() {
		$(this).css("background","#fff");
		$(this).css("border","1px solid #999");
 	});

	$('.search-button').hover(
		function(){
			$(this).css('background','url(/interface/images/showlinks2-form2.jpg) no-repeat 0 -16px');
		},
		function(){
			$(this).css('background','url(/interface/images/showlinks2-form2.jpg) no-repeat 0 0');
		}
	);

});

