/*----------------------------------------------------

	JSONLOAD.JS

----------------------------------------------------*/

$(document).ready(function(){

	var bodyid = $('body').attr('id');
	
	// A. Close Response Messages
	//------------------------------------------------------------------------------------------

	$('#msg-response').bind("click", function(){
		if(!$('#msg-response').find('a').length){
			if($('#msg-response').is(':visible')){
				$("#msg-response").slideUp();
			}
		}
	});
	if($('#msg-response').find('a').length){ $("#msg-response span").hide(); }
	
	// B. Input Hints
	//------------------------------------------------------------------------------------------	

	$('input[type="text"]').each(function(){
		if(!$(this).val()){
			this.value = $(this).attr('title');
		}
		$(this).focus(function(){
			if(this.value == $(this).attr('title')) {
				this.value = '';
			}
		});
		$(this).blur(function(){
			if(this.value == '') {
				this.value = $(this).attr('title');
			}
		});
	});
	
	// C. In Page Links
	//------------------------------------------------------------------------------------------
		
	$('a.in_link').click(function(){  
 		if(location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname){
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if($target.length){
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 900);
				return false;
			}
		}  
  	});
	
	// D. Banner Cycle
	//------------------------------------------------------------------------------------------

	if(bodyid == 'index'){
		
		var banners = '<div id="banner-2"><div class="banner-content"><h2>Sash window draught proofing kits</h2><p>We offer a sash window draught proofing kit for the diy enthusiast. Each Kit contains an easy to follow step by step guide and all the specialist materials needed to fully draught proof a traditional sliding sash window.</p><a href="/diy/sash-window-kits.html"><span>Find Out More</span></a></div></div><div id="banner-3"><div class="banner-content"><h2>Contact us for a free written quotation</h2><p>We have over twenty years experience in the sash window industry, our unique repair and draught proofing services avoids the need for unnecessary replacement. Contact us for a free site survey and quotation.</p><a href="/contact/"><span>Contact Us</span></a></div></div>';
		$('#banner').append(banners);
		$(function() {
		eval($('#banner').cycle({
				fx: 'scrollUp',
				speed: 2500,
				timeout: 10000,
				pager: '#banner-paging',
				//random: 1,
				pause: 1
			}));
		});	
	}

	// E. Colorbox
	//------------------------------------------------------------------------------------------
	
	$(".img-container a").colorbox()
	$(".img-gallery-view a").colorbox({rel:'gallery'});

});


// 01. trim
//------------------------------------------------------------------------------------------

function trim(str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}


