jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{def:"easeInOutQuad",swing:function(e,f,a,h,g){return jQuery.easing[jQuery.easing.def](e,f,a,h,g)},easeInQuad:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutQuad:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutQuad:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a},easeInQuint:function(e,f,a,h,g){return h*(f/=g)*f*f*f*f+a},easeOutQuint:function(e,f,a,h,g){return h*((f=f/g-1)*f*f*f*f+1)+a},easeInOutQuint:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f*f+a}return h/2*((f-=2)*f*f*f*f+2)+a},easeInExpo:function(e,f,a,h,g){return(f===0)?a:h*Math.pow(2,10*(f/g-1))+a},easeOutExpo:function(e,f,a,h,g){return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a},easeInOutExpo:function(e,f,a,h,g){if(f===0){return a}if(f==g){return a+h}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a}return h/2*(-Math.pow(2,-10*--f)+2)+a},easeInRegular:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutRegular:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutRegular:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a}});

$( document ).ready( function () {

	$('#mod_signup_trackingCode').val(tracking_code);

	
$('#postcode-lookup').show().click(function() {
		var postcode = $('#mod_signup_postcode').val();
		var pcRegExp = /[A-Z][A-Z0-9][A-Z0-9]?[A-Z0-9]? ?[0-9][A-Z]{2}/i;
		if( pcRegExp.test(postcode) ) {
			$.ajax({
				url: '/rest/hiddenhearing-addresslookup/list/' + encodeURI(postcode) + '/',
				dataType: 'json',
				success: function(data) {
					if( data.Status == 'ok' ) {
						var options = '<option value="">Enter address below or select from list</option>';
						for( var i in data.Addresses ) {
							options += '<option value="' + data.Addresses[i].Address + '">' + data.Addresses[i].Address + '</option>';
						}
						$('#address-select').html(options).show();
					} else {
						alert('Postcode not found.');
					}
				}
			});
		} 
		else {
			alert('Please enter a valid postcode.');
		}
	});
	$('#address-select').change(function() {
		$('#mod_signup_address').val( $('#address-select').val() );
		$('#address-select').hide();
	});

if(tracking_code == "") {
	tracking_code = "INTN";
   
}
var pathname = window.location.pathname;
if(typeof(tracking_code) !== 'undefined'){


var dater = tracking_code.substr(4);

 

  var tracking = ["INTN", "PCGB", "CAEM", "BANN"];

  var get = ["HI", "HP", "HC", "HB"]

for(var i=0;i<tracking.length;i++){

 if(tracking_code.substr(0, 4) == tracking[i]){
	 
  $('#hhbanner').attr('href','http://my-story.hiddenhearing.co.uk/video/emma?pfecsrc=HIMY&utm_source=HH%2B&utm_medium=banner&utm_campaign='+get[i]+dater);

  $('#emma').attr('href','http://my-story.hiddenhearing.co.uk/video/emma?pfecsrc=HIMY&utm_source=HH%2B&utm_medium='+pathname+'&utm_campaign='+get[i]+dater);
  $('#emma').attr('target','_blank');

  $('#celia').attr('href','http://my-story.hiddenhearing.co.uk/video/celia?pfecsrc=HIMY&utm_source=HH%2B&utm_medium='+pathname+'&utm_campaign='+get[i]+dater);
  $('#celia').attr('target','_blank');

  $('#lorraine').attr('href','http://my-story.hiddenhearing.co.uk/video/lorraine?pfecsrc=HIMY&utm_source=HH%2B&utm_medium='+pathname+'&utm_campaign='+get[i]+dater);
  $('#lorraine').attr('target','_blank');
  
  $('#michael').attr('href','http://my-story.hiddenhearing.co.uk/video/michael?pfecsrc=HIMY&utm_source=HH%2B&utm_medium='+pathname+'&utm_campaign='+get[i]+dater);
  $('#michael').attr('target','_blank');

  $('#roger').attr('href','http://my-story.hiddenhearing.co.uk/video/roger?pfecsrc=HIMY&utm_source=HH%2B&utm_medium='+pathname+'&utm_campaign='+get[i]+dater);
  $('#roger').attr('target','_blank');

  $('#mystory').attr('href','http://my-story.hiddenhearing.co.uk/?pfecsrc=HIMY&utm_source=HH%2B&utm_medium='+pathname+'&utm_campaign='+get[i]+dater);
  $('#mystory').attr('target','_blank');

  $('#mystorytestimonial').attr('href','http://my-story.hiddenhearing.co.uk/?pfecsrc=HIMY&utm_source=HH%2B&utm_medium='+pathname+'&utm_campaign='+get[i]+dater);

 }

}
}



	/*********************************************************
	*  Home page
	*********************************************************/
	
	if ( $('#bannerSlider-home').length > 0 ) {
		
		var $linkTextMain	= $('#home-banner-link-text-main');
		var $linkTextSub	= $('#home-banner-link-text-sub');

		$('#bannerSlider-home').cycle({
			'fx': 'scrollLeft',
			'timeout': 10000,
			'after': function ( cSlide, nSlide, options ) {
				
				var $banner = $( this );	//  The <a> tag
				
				var href 		= $banner.attr( 'href' );
				var linkTitle	= $banner.attr( 'title' );
				var imageAlt	= $( $banner.children()[0] ).attr( 'alt' );
				
				$linkTextMain.attr( 'href', href ).text( imageAlt );	//  The blue (upper) ribbon
				$linkTextSub.attr( 'href', href ).text( linkTitle );	//  The red (lower) ribbon
				
			}
		});
		
	}
	
	
	/*********************************************************
	*  Hearing Test Experience
	*********************************************************/
	
	if ( $('#hearingTestExperienceSlideShow').length > 0 ) {
		
		var $paused = $('.hearingTestExperiencePaused');
		
		$paused.css( 'opacity', 0.6 );
		
		//  Show paused message
		$('#hearingTestExperienceSlides').hover( function ( ev ) {
			$paused.show();
		}, function ( ev ) {
			$paused.hide();
		});
		
		//  Set opacity of the info divs
		$( 'div.hearingTestExperienceContent' ).css( 'opacity', 0.8 );

		//  Main cycler for the slides
		$('#hearingTestExperienceSlides').cycle({
			'fx': 'scrollHorz',
			'timeout': 10000,
			'pause': 1,
			'height': 460,
			'next': '.hearingTestExperienceNext a',
			'prev': '.hearingTestExperiencePrev a'
		});
		
	}
	
	
	/*********************************************************
	*  Testimonials
	*********************************************************/
	
	if ( $('div.testimonials-container').length > 0 ) {

		//  Cache elements
		var $readMoreButtons = $('a.read-more');
		var $readLessButtons = $('a.read-less');
		var $testimonials    = $('div.testimonials-bottom');

		//  Functions to show/hide testimonials (done this way for easy altering)
		
		var hideTestimonial = function ( testimonial ) {
		    testimonial.slideUp();
		};
		
		var showTestimonial = function ( testimonial ) {
		    testimonial.slideDown();
		};

		//  No direct links so use each to match buttons to text
		$.each( $readMoreButtons, function ( index ) {

		    var $button			= $( this );
		    var $testimonial	= $( $testimonials[index] );

		    $button.click( function ( ev ) {

		        ev.preventDefault();
		        
		        //  If related testimonial is already visible, just hide it
		        if ( $testimonial.is( ':visible' ) ) {

					//  Hide showing
		        	hideTestimonial( $testimonial );
		        	
	        		return false;
				}

				//  Hide any showing
		        hideTestimonial( $testimonials );

		        //  Show selected
		        showTestimonial( $testimonial );

		    });
		    
		});
		
		
		$readLessButtons.click( function ( ev ) {
			
			ev.preventDefault();
			
			var $button 		= $( this );
			var $testimonial 	= $( $button.parents( 'div.testimonials-bottom')[0] );
			
			hideTestimonial( $testimonial );
			
		});
		
	}
	

});

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

$.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}

function twitter(){
		var twitfeed = "hiddenhearinguk";
		$('#twitter_update_list').html('<li>Loading Twitter feed</li>');
		$.getScript("http://twitter.com/javascripts/blogger.js", function(){
			$.getScript("http://api.twitter.com/1/statuses/user_timeline.json?callback=twitterCallback2&screen_name="+ twitfeed +"&include_rts=true&count=1");
		});
	}

$(document).ready(function(){
	if($("#twitterCallout").length !== 0){twitter();}

	$('.bottom-footer-nav span:last').remove();
	
	$('#resizeA').click(function(){
		$('.text-size-container-a a').removeClass('on');
		$('body').removeClass('mediumText').removeClass('largeText');
		$('p').removeClass('mediumText').removeClass('largeText');
		$('h1').removeClass('mediumText').removeClass('largeText');
		$('.crumbtrail_holding a').removeClass('mediumText').removeClass('largeText');
		$('h2').removeClass('mediumText').removeClass('largeText');
		$('#twitterText').removeClass('mediumText').removeClass('largeText');
		$('h3').removeClass('mediumText').removeClass('largeText');
		$('span').removeClass('mediumText').removeClass('largeText');
		$('.bottom-footer-nav a').removeClass('mediumText').removeClass('largeText');
		$('.header-nav_container a').removeClass('mediumText').removeClass('largeText');
		$('#brochurecall').css('height','285px');
		$('#brochuretextbottom').css('top','149px');
		$('#callout1').css('height','380px');
		$('#callout2').css('height','380px');
		$('#callout3').css('height','380px');
		$(this).addClass('on');
		$.cookie('textSize', '0', {expires:30, path: '/', domain: 'hiddenhearing.wickedservers.co.uk'});
		return false;
	});
	$('#resizeAA').click(function(){
		$('.text-size-container-a a').removeClass('on');
		$('body').addClass('smediumText').removeClass('slargeText');
		$('p').addClass('mediumText').removeClass('largeText');
		$('h1').addClass('mediumText').removeClass('largeText');
		$('.crumbtrail_holding a').addClass('mediumText').removeClass('largeText');
		$('h2').addClass('mediumText').removeClass('largeText');
		$('h3').addClass('mediumText').removeClass('largeText');
		$('span').addClass('mediumText').removeClass('largeText');
		$('.bottom-footer-nav a').addClass('mediumText').removeClass('largeText');
		$('.header-nav_container a').addClass('mediumText').removeClass('largeText');
		$('#twitterText').addClass('mediumText').removeClass('largeText');
		$('#brochurecall').css('height','355px');
		$('#brochuretextbottom').css('top','185px');
		$('#callout1').css('height','390px');
		$('#callout2').css('height','390px');
		$('#callout3').css('height','390px');
		$(this).addClass('on');
		$.cookie('textSize', '1', {expires:30, path: '/', domain: 'hiddenhearing.wickedservers.co.uk'});
		return false;
	});
	$('#resizeAAA').click(function(){
		$('.text-size-container-a a').removeClass('on');
		$('body').removeClass('smediumText').addClass('slargeText');
		$('p').removeClass('mediumText').addClass('largeText');
		$('h1').removeClass('mediumText').addClass('largeText');
		$('.crumbtrail_holding a').removeClass('mediumText').addClass('largeText');
		$('h2').removeClass('mediumText').addClass('largeText');
		$('h3').removeClass('mediumText').addClass('largeText');
		$('.header-nav_container a').removeClass('mediumText').addClass('largeText');
		$('#twitterText').removeClass('mediumText').addClass('largeText');
		$('span').removeClass('mediumText').addClass('largeText');
		$('.bottom-footer-nav a').removeClass('mediumText').addClass('largeText');
		$('#brochurecall').css('height','460px');
		$('#brochuretextbottom').css('top','237px');
		$('#callout1').css('height','430px');
		$('#callout2').css('height','430px');
		$('#callout3').css('height','430px');
		$(this).addClass('on');
		$.cookie('textSize', '2', {expires:30, path: '/', domain: 'hiddenhearing.wickedservers.co.uk'});
		return false;
	});
	if($.cookie('textSize') == '1'){
		$('#resizeAA').click();
	}
	else if($.cookie('textSize') == '2'){
		$('#resizeAAA').click();
	}
	else{
		$('#resizeA').click();
	}
});

//Open offsite links in new window script- http://www.dynamicdrive.com/
//Created: August 28th, 2007'

var ddwindowlinks={
//1)Enter domains to be EXCLUDED from opening in new window:
excludedomains: ["hiddenhearing.wickedservers.co.uk", "hiddenhearing.co.uk"],

//2) Target for links that should open in a new window (ie: "_blank", "secwin" etc):
linktarget: "_blank",

//3) Specify operating mode ("auto" or "manual"):
mode: "auto",

//4) If mode is "manual", customize checkbox HTML to show to users (Preserve id attribute):
toggleHTML: '<form><input type="checkbox" id="targetcheckbox" checked="checked" /><label for="targetcheckbox">Open off-site links in new window?</label></form>',

//5) If mode is "manual", enable user persistence so the state of the checkbox is remembered?
persist: true,

assigntarget:function(){
	var rexcludedomains=new RegExp(this.excludedomains.join("|"), "i")
	var all_links=document.getElementsByTagName("a")
	if (this.mode=="auto" || (this.mode=="manual" && this.togglebox.checked)){
		for (var i=0; i<=(all_links.length-1); i++){
			if (all_links[i].hostname.search(rexcludedomains)==-1 && all_links[i].href.indexOf("http:")!=-1)
				all_links[i].target=ddwindowlinks.linktarget
		}
	}
	else{
		for (var i=0; i<=(all_links.length-1); i++)
			all_links[i].target=""
	}
	if (this.mode=="manual" && this.persist)
		this.setCookie("dlinktarget", (this.togglebox.checked)? "yes" : "no", 30) //remember user setting for 30 days (set to -1 then reload page to erase cookie)
},

init:function(){
	if (document.getElementById && this.mode=="manual"){
		document.write(this.toggleHTML)
		this.togglebox=document.getElementById("targetcheckbox")
		this.togglebox.onclick=function(){ddwindowlinks.assigntarget()}
		if (this.persist && this.getCookie("dlinktarget")!="")
			this.togglebox.checked=(this.getCookie("dlinktarget")=="yes")? true : false
	}
	if (window.addEventListener)
		window.addEventListener("load", function(){ddwindowlinks.assigntarget()}, false)
	else if (window.attachEvent)
		window.attachEvent("onload", function(){ddwindowlinks.assigntarget()})
},

getCookie:function(Name){
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
},

setCookie:function(name, value, days){
	var expireDate = new Date()
	//set "expstring" to either an explicit date (past or future)
		var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
		document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/"
}

}

ddwindowlinks.init()

$('.termsLink').live('click', function(e){

	if ( navigator.userAgent.match(/(iPad|iPhone)/i) != null ) {
		alert( 'Apple iPhone and iPad users may scroll through the terms and conditions by pressing with two fingers instead of one on the popup.' );
	}

	openLightBox('#termsAndConditions?width=760&height=550&id=termsAndConditions');

	return false;

});

navWidth = function(){
	totalWidth = 879;
	itemWidth = 0;
	$('#main-nav_holding > li:first').addClass('first');
	$('#main-nav_holding > li:last').addClass('last');
	$('#main-nav_holding > li > ul').find('li:last').addClass('curve');
	$('#main-nav_holding > li > a').css('padding-left', '0px').css('padding-right', '0px');
	$('#main-nav_holding > li').each(function(){
		itemWidth += $(this).width();
	});
	spaceLeft = (totalWidth - itemWidth);
	padding = Math.floor((spaceLeft / $('#main-nav_holding > li').size()) / 2);
	$('#main-nav_holding > li > a').css('padding-left', padding + 'px').css('padding-right', padding + 'px');
	remainder = (totalWidth - $('#main-nav_holding').width());
	$('#main-nav_holding > li:last > a').css('padding-right', padding + Math.ceil(remainder/2) + 'px');
	$('#main-nav_holding > li:first > a').css('padding-left', padding + Math.floor(remainder/2) + 'px');
}

	

function removeLast(){
    $('.header-nav_container a:last').next('span').remove();
	$('.header-nav_container a:last').css('margin-right','4px');
}

function removeSpace() {
	$('.subnav-section-name').show();
	$('.main_content-left ul').show();	
}

$(document).ready(function(){
	$('#imagetwo').css('display','block');
	$('.subnav-section-name').hide();
	$('.main_content-left ul').hide();	
	navWidth();
	removeLast();
	$('.main_content-left ul li').each(function(){removeSpace()});
});

/*
 * label2value
 * jquery based script for using form labels as text field values
 * more info on http://cssglobe.com/post/1500/using-labels- 
 *
 * Copyright (c) 2008 Alen Grakalic (cssglobe.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 */

this.label2value = function(){	

	// CSS class names
	// put any class name you want
	// define this in external css (example provided)
	var inactive = "inactive";
	var active = "active";
	var focused = "focused";
	
	// function
	$("label").each(function(){		
		obj = document.getElementById($(this).attr("for"));
		if(($(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){			
			$(obj).addClass(inactive);			
			var text = $(this).text();
				$(this).css("display","none");	
			$('#searchinput label').css('display','block');		
			$('#w2bFields label:first').css('display','block');
			$('#locationinput label:first').css('display','block');
			$(obj).val(text);
			$(obj).focus(function(){	
				$(this).addClass(focused);
				$(this).removeClass(inactive);
				$(this).removeClass(active);								  
				if($(this).val() == text) $(this).val("");
			});	
			$(obj).blur(function(){	
				$(this).removeClass(focused);													 
				if($(this).val() == "") {
					$(this).val(text);
					$(this).addClass(inactive);
				} else {
					$(this).addClass(active);		
				};				
			});				
		};	
	});		
};
// on load
$(document).ready(function(){	
	label2value();	
	if($.cookie("formfilled") == "1") {
		$("#showyes #title").val($.cookie("title"));
		$("#mod_signup_title").val($.cookie("title"));
		$("#mod_signup_firstname").val($.cookie("firstname"));
		$("#mod_signup_lastname").val($.cookie("lastname"));
		$("#mod_signup_phone").val($.cookie("phone"));
		$("#mod_signup_email").val($.cookie("email"));
		$("#mod_signup_postcode").val($.cookie("postcode"));
		$("#mod_signup_address").val($.cookie("addresstwo"));
	}
});

jQuery(document).ready(function()
{
	$('#homefinderright a').click(function() {
		var postcode = $('#w2bAddress').attr('value');
		$.cookie("address", postcode, { path: '/' });
	});
	
	$('#homefinder form').submit(function(){
		return false;
	});
	
	$('#w2bAddress').keyup(function(event){
           if(event.which == '13'){
	  		    var postcode = $('#w2bAddress').attr('value');
		        $.cookie("address", postcode, { path: '/' });
        		window.location.href = "/branch-finder-landing/";
		   }
	});
	
	$("#w2bAddress").val($.cookie("address"));
	
	if($('#w2bAddress').val() != "") {
		$('#w2bRadius').val('15');
		if( document.location.href == 'http://www.hiddenhearing.co.uk/branch-finder-landing/' ) {
			theForm = $('#storelocator').get(0);
			findBranch(theForm,$('#w2bAddress',theForm).val() + ", UK",true);
		}
	}
});

function testimonials(){
 $("#testimonialsshade #testimonialLarge a").attr("href", $("#testimonialsshade ul li").first().find("img").attr("link"));
 $("#testimonialsshade ul li").click(function(){
  var thisSrc = $(this).find("img").attr("largeSrc");
  var oldSrcer=$(this).find("img").attr("src");
  $("#testimonialsshade ul li .selected").attr("src", $("#testimonialsshade ul li .selected").attr("oldSrc"));
  $("#testimonialsshade ul li .selected").removeClass("selected");
  
  $("#testimonialsshade #testimonialLarge a").attr("href", $(this).find("img").attr("link"));
  
  $(this).find("img").attr("oldSrc", oldSrcer).attr("src", $(this).find("img").attr("hover")).addClass("selected");
  
   $("#testimonialsshade  .window").stop().animate({
    "margin-left": (($(this).index())*$(this).width())+"px"
   },500);
   $("#testimonialsshade #testimonialLarge").fadeTo(250, 0, function(){
    $(this).find("img").attr("src", thisSrc);
    $(this).fadeTo(250, 1);
   });
 });
}

$(document).ready(function(){
		testimonials();
		$('.branch_results_container .branch_results-callout:last').css('border-bottom','0');

});
