/* sIFR Config */

var helvetica = {src: '/media/swf/helvetica.swf'};
sIFR.activate(helvetica);

sIFR.replace(helvetica, {
	selector: '#content>h2, .videos h2, .blog h2, .news h2, .faq h2',
	ratios: [8, 1.41, 11, 1.31, 15, 1.29, 25, 1.25, 28, 1.23, 32, 1.22, 33, 1.23, 43, 1.22, 61, 1.21, 64, 1.2, 65, 1.21, 112, 1.2, 113, 1.19, 115, 1.2, 118, 1.19, 122, 1.2, 124, 1.19, 1.2],
	thickness: 130,
	tuneHeight: -6,
	wmode: 'transparent',
	css: [
		'.sIFR-root { color: #0F394F }'
	]
});
sIFR.replace(helvetica, {
	selector: '.gallery h3',
	ratios: [8, 1.41, 11, 1.31, 15, 1.29, 25, 1.25, 28, 1.23, 32, 1.22, 33, 1.23, 43, 1.22, 61, 1.21, 64, 1.2, 65, 1.21, 112, 1.2, 113, 1.19, 115, 1.2, 118, 1.19, 122, 1.2, 124, 1.19, 1.2],
	thickness: 130,
	tuneHeight: -6,
	wmode: 'transparent',
	css: [
		'.sIFR-root { color: #333333 }'
	]
});

/* Addthis Config */

var addthis_pub="4a12aca440be8b2d"; // Required for addthis button (http://www.addthis.com/)

/* Liveperson Config */

var lpNumber = "81954423"; // Add Site ID (LP-NUMBER)
var lpServerName = "server.iad.liveperson.net";

// DEFINED REP STATES :
// var LPREPSTATEONLINE = "online" : Reps available online
// var LPREPSTATEOFFLINE = "offline" : No available reps online - offline or away
// var LPREPSTATEOCCUPIED = "occupied" : Rep in "back in 5" state
// var LPREPSTATEUNKNOWN = "unknown" : Unable to contact server

function repStateNotifyFunction(state) {
	if (state==LPREPSTATEONLINE){
	$(".live-chat p").html('Online Now');
	}
	else if (state==LPREPSTATEOCCUPIED){
	$(".live-chat p").html('Back in 5 mins');
	}
	else {
	$(".live-chat p").html('<em>Online</em> Mon-Fri 9am-late');
	}
}

$(function(){
	
	// include external js
	$.getScript('http://server.iad.liveperson.net/hcp/html/lpCheckRepState.js');
	$.getScript('http://s7.addthis.com/js/200/addthis_widget.js');
	
	//manipulate document
	$('#postcode').val('Enter postcode');
	$('.live-chat span').after('<p>Fetching status...</p>');
	
	var bindActions = function(hash) {
		$('.terms').click(function() {
			$('.book').hide();			   
			$('#offer').slideUp('normal',function() {
				$('#terms').slideDown();
				$('.back-to-offers').fadeIn();
			});		
			return false;
		})
		$('.back-to-offers').click(function() {
			$('#terms').slideUp('normal',function() {
				$('#offer').slideDown('normal',function() {
					$('.back-to-offers').fadeOut();
					$('.book').fadeIn('fast');			   
				});
			});		
			return false;
		})
	}
	
	//jqModal functionality
	$('body').append('<div class="jqmWindow" id="ex2">Please wait... <img src="/media/images/loading.gif" alt="loading" /></div>');
	$('#ex2').jqm({ajax: '/media/jqm-latest-offers-newyear.html', trigger: '#sub-content .latest-offers a'});
	$('#ex2').jqmAddClose('#ex2 a');
	 
	//jqModal functionality
	//$('body').append('<div class="jqmWindowLarge" id="ex3">Please wait... <img src="/media/images/loading.gif" alt="loading" /></div>');
	//$('#ex3').jqm({ajax: '/media/jqm-latest-offers-xmas.html', trigger: '#sub-content .latest-offers a',onLoad:bindActions});
	//$('#ex3').jqmAddClose('#ex3 .offer-close');
	
	// documents and external links to open in new window
	$("a[href^='http:']").not("[href*='5day']").attr('target','_blank');
	$("a[href$='pdf']").attr('target','_blank');
	
	$('#postcode')
	.focus(function(){if ($(this).val() == 'Enter postcode') {$(this).val('');}})
	.blur(function(){if ($(this).val() == '') {$(this).val('Enter postcode');}});
	
	$('#frm-directions').submit(function(){
		usePointFromPostcode(this.postcode.value, setDirections);
		return false;
	});
	
	$('.videos .features div').each(function(){
		var id = this.id.replace('vid-','','');
		if (id != '')
		{
			var so = new SWFObject('http://www.youtube.com/v/' + id + '&amp;rel=0', '' + id + '', '256', '215', '8', '#FFFFFF');
			so.addParam('rel', '0');
			so.addParam('wmode', 'opaque');
			so.write(this.id);
		}
	});
	
	$('.addthis')
	.mouseover(function(){return addthis_open(this, '', '[URL]', '[TITLE]')})
	.mouseout(function(){addthis_close()})
	.click(function(){return addthis_sendto()});
	
	$('.live-chat').click(function(){
		pageTracker._trackPageview('/live-chat/');
		$("body").append("<script type=\"text/javascript\"><!-- var google_conversion_id = 1071399571;	var google_conversion_language = \"en\";var google_conversion_format = \"3\";var google_conversion_color = \"ffffff\";	var google_conversion_label = \"2tWACLONtQEQk4Xx_gM\"; var google_conversion_value = 0;	//--></script><script type=\"text/javascript\" src=\"http://www.googleadservices.com/pagead/conversion.js\"></script>");
		lpButtonCTTUrl = 'http://server.iad.liveperson.net/hc/81954423/?cmd=file&amp;file=visitorWantsToChat&amp;site=81954423&amp;imageUrl=http://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/English/General/1c&amp;referrer=' + escape(document.location);
		lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); window.open(lpButtonCTTUrl,'chat81954423','width=510,height=400,resizable=yes');
		return false;
	});
	
	$('#faqs h2, #faqs .toggle').click(function(){
		$(this).siblings('div').slideToggle();
		$(this).parent('li').children('.toggle').toggleClass('hide');
		return false;
	});
	
	// extend tracking to latest offers panel manual launch
	$('#sub-content .latest-offers a').click(function(){
		pageTracker._trackPageview('/latest-offers/');
	});

	if (!$.cookie('latest-offers-newyear')) {
		$('#ex2').jqmShow();
		$.cookie('latest-offers-newyear', '1', { expires: 7 }); // set cookie with an expiration date 7 days in the future
	}
	
});