// JavaScript Document

$(document).ready(function(){
						   
	// STOP IE6 FLICKER
	if ($.browser.msie && $.browser.version.substr(0,1)<7) { 
		document.execCommand('BackgroundImageCache', false, true);
		
	};
	
	///////// Navigation IE Fix  /////////////////
	 $("ul.dropdown li").hover(function(){
	   $(this).addClass("hover");
	   $('> .dir',this).addClass("open");
	   $('ul:first',this).css('visibility', 'visible');
	 },function(){
	   $(this).removeClass("hover");
	   $('.open',this).removeClass("open");
	   $('ul:first',this).css('visibility', 'hidden');
	 });

	// BUTTON SETUP
	 $(function(){
		//all hover and click logic for buttons
		$(".fg-button:not(.ui-state-disabled)")
		.hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		)
		.mousedown(function(){
				$(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
				if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
				else { $(this).addClass("ui-state-active"); }	
		})
		.mouseup(function(){
			if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
				$(this).removeClass("ui-state-active");
			}
		});
	});


	// SCROLL TO TOP OF PAGE
	
	$('.TopOfPage a').click(function() {
		$('html').animate({scrollTop:0}, 'slow'); 
	});
	
	
	// Set up footer borders
	
	$('.FooterList').each(function() {
		$(this).find('li:first').addClass('nopadding').addClass('noborder');
	});
	
	
	// Set up footer borders
	
	$('.Bread').each(function() {
		$(this).find('li:first').addClass('nopaddingleft');
	});
	
	
	
	// Set up hints
	
	$('input[title!=""]').hint();
	$('textarea[title!=""]').hint();
	
	
	// Submt button animate
	
	$('.SearchButton, .SubscribeButton, .Submit, .SubscribeLink, .CommentButton').css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -35px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0 0"})
		}})
	});
	
	// Form Input animate
	
	
	$('.input').css( {backgroundPosition: "0% 0%"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0% 100%)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0% 0%)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0% 0%"})
		}})
	});
	
	
	// Thumbs Scroller
	if ($("div.scrollable").length > 0) {
		/*$("div.scrollable").scrollable({
									   
				size: 1,
				items: '#thumbs',  
				hoverClass: 'hover',
				interval: 3000			
				
		}).circular();*/
		
		
		
		$("div.scrollable").scrollable({size: 1,
				items: '#thumbs'}).circular().autoscroll().navigator();
		
		
	};
	// Scroll Bar
	//
	
	$('.Tags a').css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -35px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0 0"})
		}})
	});
 
 
 	//
	
	$('.Page a').css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -35px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0 0"})
		}})
	});
 	
 	
	//
	
	
	
	$('#DistMap area').each(function () {
			
			var distance = 5;
			var time = 250;
			var hideDelay = 100;
			var hideDelayTimer = null;
			var beingShown = false;
			var shown = false;
			var triggerHold =  $(this).attr('class');
			
			$('.' + triggerHold).mouseover(function (e) {
				
				var info = '#' + triggerHold + 'MapPopUp';
				
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				
				if (beingShown || shown) {
					// don't trigger the animation again
					return;
				} else {
					
					//console.log('Trigger is = ' + triggerHold );
					//console.log('Thing to pop up = ' + info);
					
					// reset position of info box
					beingShown = true;
					
					var divhehight = $(info).height()+30;
					
					var pos = $("#DistImage").position();
					
					if ($.browser.msie && $.browser.version.substr(0,1)<7) { 
						var	topHold = pos.top-150;
					} else {
						var	topHold = e.pageY-divhehight;
						
					};
					
					
					
					var	leftHold = e.pageX-290;
					
					
					//console.log("Left Position = " + $('.' + triggerHold).position().left );
					//console.log("Top Position = " + $('.' + triggerHold).position().top );
					
					//console.log( $(info).height() );
					
					$(info).css({
						top: topHold,
						left: leftHold ,
						display: 'block'
					}).animate({
						top: '-=' + distance + 'px',
						opacity: 1
					}, time, 'swing', function() {
						beingShown = false;
						shown = true;
					});
					
					$("."+triggerHold).mousemove(function(e){
     					 	//var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
      						$(info).css({
								//top: topHold,
								left: e.pageX-290 ,
								display: 'block'
							})
    				});

					
					
					if ($.browser.msie) { 
						//$(info+ ' .MapPopUpInner').style.removeAttribute('filter');
					};
					
				}
				return false;
				}).mouseout(function () {
					if (hideDelayTimer) clearTimeout(hideDelayTimer);
						
						var info = '#' + triggerHold + 'MapPopUp';
						//console.log(triggerHold + 'Rollout');
						
						hideDelayTimer = setTimeout(function () {
						hideDelayTimer = null;
						
						$(info).animate({
							top: '-=' + distance + 'px',
							opacity: 0
						}, time, 'swing', function () {
							shown = false;
							$(info).css('display', 'none');
						});
						
	
					}, hideDelay);
	
					return false;
				});
			
			});
//
	
	
	
	$('#HouseMap area').each(function () {
			
			var distance = 5;
			var time = 250;
			var hideDelay = 100;
			var hideDelayTimer = null;
			var beingShown = false;
			var shown = false;
			var triggerHold =  $(this).attr('class');
			
			$('.' + triggerHold).mouseover(function (e) {
				
				var info = '#' + triggerHold + 'HousePopUp';
				
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				
				if (beingShown || shown) {
					// don't trigger the animation again
					return;
				} else {
					
					//console.log('Trigger is = ' + triggerHold );
					//console.log('Thing to pop up = ' + info);
					
					// reset position of info box
					beingShown = true;
					
					var divhehight = $(info).height()+30;
					
					var pos = $("#HouseImage").position();
					
					if ($.browser.msie && $.browser.version.substr(0,1)<7) { 
						var	topHold = pos.top-100;
					} else {
						var	topHold = e.pageY-divhehight;
						
					};
					var	leftHold = e.pageX-240;
					
					
					//console.log("Left Position = " + $('.' + triggerHold).position().left );
					//console.log("Top Position = " + $('.' + triggerHold).position().top );
					
					//console.log( $(info).height() );
					
					$(info).css({
						top: topHold,
						left: leftHold ,
						display: 'block'
					}).animate({
						top: '-=' + distance + 'px',
						opacity: 1
					}, time, 'swing', function() {
						beingShown = false;
						shown = true;
					});
					
					$("."+triggerHold).mousemove(function(e){
     					 	//var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
      						$(info).css({
								top: topHold,
								left: e.pageX-140 ,
								display: 'block'
							})
    				});

					
					
					if ($.browser.msie) { 
						//$(info+ ' .HousePopUpInner').style.removeAttribute('filter');
					};
					
				}
				return false;
				}).mouseout(function () {
					if (hideDelayTimer) clearTimeout(hideDelayTimer);
						
						var info = '#' + triggerHold + 'HousePopUp';
						//console.log(triggerHold + 'Rollout');
						
						hideDelayTimer = setTimeout(function () {
						hideDelayTimer = null;
						
						$(info).animate({
							top: '-=' + distance + 'px',
							opacity: 0
						}, time, 'swing', function () {
							shown = false;
							$(info).css('display', 'none');
						});
						
	
					}, hideDelay);
	
					return false;
				});
			
			});
	//
	
	
	
	//
	
});

/////


function livepersonclick () {
	
		lpButtonCTTUrl = 'http://server.iad.liveperson.net/hc/49620649/?cmd=file&amp;file=visitorWantsToChat&amp;site=49620649&amp;imageUrl=http://www.soundreduction.co.uk/LivePerson&amp;referrer='+escape(document.location); 
		lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); 
		lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);
		window.open(lpButtonCTTUrl,'chat49620649','width=472,height=320,resizable=yes');
		return false;

	}
	function livepersonrateclick () {
	
		window.open('http://solutions.liveperson.com/customer-service/?site=49620649&amp;domain=server.iad.liveperson.net&amp;origin=chatbutton&amp;referrer='+escape(document.location));return false;
		
	}
	
	var lpMTagConfig = {'lpServer' : "server.iad.liveperson.net",'lpNumber' : "49620649",'lpProtocol' : "http"}; 
	
	function lpAddMonitorTag(src){

	if(typeof(src)=='undefined'||typeof(src)=='object') {
	
		src=lpMTagConfig.lpMTagSrc?lpMTagConfig.lpMTagSrc:'/hcp/html/mTag.js';
		
	}

	if(src.indexOf('http')!=0){

		src=lpMTagConfig.lpProtocol+"://"+lpMTagConfig.lpServer+src+'?site='+lpMTagConfig.lpNumber;
	
	} else {

		if(src.indexOf('site=')<0){
			if(src.indexOf('?')<0)
				src=src+'?';else src=src+'&amp;';src=src+'site='+lpMTagConfig.lpNumber;
			}
		};
	 
		var s=document.createElement('script');
		s.setAttribute('type','text/javascript');
		s.setAttribute('charset','iso-8859-1');
		s.setAttribute('src',src);
		document.getElementsByTagName('head').item(0).appendChild(s);
 
	} 
	
	if (window.attachEvent) window.attachEvent('onload',lpAddMonitorTag); 
	else window.addEventListener("load",lpAddMonitorTag,false);
	



// JavaScript Document

/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/

(function ($) {
	$.fn.hint = function (blurClass) {	
	
	
		if (!blurClass) { 
			blurClass = 'blur';
		}			
		return this.each(function () {	
								   		   
			// get jQuery version of 'this'
			var $input = $(this),				
			// capture the rest of the variable to allow for reuse
			title = $input.attr('title'),		
			$form = $(this.form),
			$win = $(window);
			//console.log('title=' + title);
			$(this).val('');
			
			function remove() {
				if( $(this).val() == title) {
					$(this).val('');
				};				
				$input.addClass(blurClass);		
				
			
				
			}	
			
			// only apply logic if the element has the attribute
			if (title) {
			
				// on blur, set value to title attr if text is blank
				$input.blur(function () {
					$input.removeClass(blurClass);					
					if( $(this).val() == '') {
						$(this).val(title);					
					}
					
				if  ( $(this).attr('id') == 'Website' )  {	
					var valueHolder = $(this).val().replace('http://','');
					//console.log(valueHolder);	
					$(this).val(valueHolder);
				};
				
				
				}).focus(remove).blur(); // now change all inputs to title			
			};
		});
	};
})(jQuery);




/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);