$(document).ready(function(){
	
	$isIE6 = false;
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		$isIE6 = true;
	}
	
	$('body').removeClass('no-js');
	
	var $scrollerWindow = $('#content');
	var $speed = 1000;
	
	var $scrollerWork = $('#workcontent');
	var $speed = 1000;
	
	var div = "#JAbout" // This assumes user visits home page without any hash, below sets correct heights for Home/About page.
    var divHeight = $(div).height()+60; 
	var divLessHeight = $(div).height(); 
    $("#contentwrap").animate({height: divHeight }, 400 );
	$("#contentScroller").animate({height: divLessHeight }, 100 );
	
	
	function gotoAbout() {
		var div = "#JAbout"
    	var divHeight = $(div).height()+60; 
		var divLessHeight = $(div).height(); 
    	$("#contentwrap").animate({height: divHeight }, 400 );
		$("#contentScroller").animate({height: divLessHeight }, 100 );
		$scrollerWindow.stop().scrollTo( $('#JAbout'), $speed, {axis:'x',offset:{left: -30, top:0 }} );
		$('.goto_about').parent().addClass('selected').siblings('li').removeClass('selected');
		Cufon.refresh();
		//return false;
	}
	
	function gotoWork() {
	    hideBanners()
		//var div = "#JWork"
        //var divHeight = $(div).height()+60; 
		//var divLessHeight = $(div).height(); 
        //$("#contentwrap").animate({height: divHeight }, 400 );
		//$("#contentScroller").animate({height: divLessHeight }, 100 );
		// Am handling the Work height adjustments to a fixed height instead, via the hideBanners function.
		$scrollerWindow.stop().scrollTo( $('#JWork'), $speed, {axis:'x',offset:{left: -30, top:0 }} );
		$('.goto_work').parent().addClass('selected').siblings('li').removeClass('selected');
        Cufon.refresh();
		//return false;
	}


	function gotoSkills() {
	    var div = "#JSkills"
        var divHeight = $(div).height()+60; 
		var divLessHeight = $(div).height(); 
        $("#contentwrap").animate({height: divHeight }, 400 );
		$("#contentScroller").animate({height: divLessHeight }, 100 );
		$scrollerWindow.stop().scrollTo( $('#JSkills'), $speed, {axis:'x',offset:{left: -30, top:0 }} );
	    $('.goto_skills').parent().addClass('selected').siblings('li').removeClass('selected');
		Cufon.refresh();
		//return false;
	}

	
	function gotoGallery() {
	    var div = "#JImages"
        var divHeight = 630; 
        $("#contentwrap").animate({height: divHeight }, 400 );
		$("#contentScroller").animate({height: divHeight}, 100 );
		$scrollerWindow.stop().scrollTo( $('#JImages'), $speed, {axis:'x',offset:{left: -30, top:0 }} );
	    $('.goto_gallery').parent().addClass('selected').siblings('li').removeClass('selected');
		Cufon.refresh();
		//return false;
	}

	
	function gotoContact() {
		var div = "#JContact"
        var divHeight = 600; 
        $("#contentwrap").animate({height: divHeight }, 400 );
		$("#contentScroller").animate({height: divHeight-60 }, 001 );
		$scrollerWindow.stop().scrollTo( $('#JContact'), $speed, {axis:'x',offset:{left: -30, top:0 }} );
		$('.goto_contact').parent().addClass('selected').siblings('li').removeClass('selected');
		Cufon.refresh();
		//return false;
	}
	
	
	function gotoGordon()  {
		hideBanners()
		$scrollerWork.stop().scrollTo( $('#Gordon'), $speed, {axis:'x',offset:{left: 0, top:0 }} );
		return false;
	}
	
	
	function gotoGreener() {
		hideBanners()
		$scrollerWork.stop().scrollTo( $('#Greener'), $speed, {axis:'x',offset:{left: 0, top:0 }} );
		return false;
	}	


	function gotoYesjob() {
		hideBanners()
		$scrollerWork.stop().scrollTo( $('#Yesjob'), $speed, {axis:'x',offset:{left: 0, top:0 }} );
		return false;
	}
	
	
	function gotoFiat()  {
		hideBanners()
		$scrollerWork.stop().scrollTo( $('#Fiat'), $speed, {axis:'x',offset:{left: 0, top:0 }} );
		return false;
	}	
	
	
	function gotoPerfect()  {
		hideBanners()
		$scrollerWork.stop().scrollTo( $('#Perfect'), $speed, {axis:'x',offset:{left: 0, top:0 }} );
		return false;
	}
		
	function gotoReputation() {
		hideBanners()
		$scrollerWork.stop().scrollTo( $('#Reputation'), $speed, {axis:'x',offset:{left: 0, top:0 }} );
		return false;
	}
	
			
	function gotoMerc() {
		hideBanners()
		$scrollerWork.stop().scrollTo( $('#Merc'), $speed, {axis:'x',offset:{left: 0, top:0 }} );
		return false;
	}
	
			
	function gotoBanners() {
		hideBanners()
		$scrollerWork.stop().scrollTo( $('#Banners'), $speed, {axis:'x',offset:{left: 0, top:0 }} );
		return false;
	}
	
	
	function hideBanners() {
	 	$("#BT-Vault").hide();
	 	$("#BA-Carib").hide();
	 	$("#BT-Vision").hide();
	 	$("#BT-Contact").hide();
	 	$("#HP-Deals").hide();
	 	$("#Nike-Run").hide();
	 	$("#Tesco-Green").hide();
	 	$("#Veet-WaxCream").hide();
	 	$("#Vodafone-Curve").hide();
	 	$("#workScroller").animate({height: 400 }, 400 );
	 	$("#contentScroller").animate({height: 590 }, 400 );
	 	$("#contentwrap").animate({height: 590 }, 400 ) 
    };	
	
	
	function noScroll() {
		return false;
	}
	
	
	//$(hash.replace( /^#/, '' )).live("click", hash.replace( /^#/, '' ));
	//$('.goto_work').live("click", gotoWork);
    //$('.goto_skills').live("click", gotoSkills);
    //$('.goto_gallery').live("click", gotoGallery);	
    //$('.goto_contact').live("click", gotoContact);	
	
	
	$('.goto_gordon').live("click", gotoGordon);
	$('.goto_greener').live("click", gotoGreener);
	$('.goto_yesjob').live("click", gotoYesjob);
	$('.goto_fiat').live("click", gotoFiat);
	$('.goto_perfect').live("click", gotoPerfect);
	$('.goto_reputation').live("click", gotoReputation);
	$('.goto_merc').live("click", gotoMerc);
	$('.goto_banners').live("click", gotoBanners);
	
	
	
	// Since the event is only triggered when the hash changes, we need to trigger
    // the event now, to handle the hash the page may have loaded with.	
		
	$(window).hashchange( function(){
    var hash = location.hash;
	if (hash == '#About') { gotoAbout()};
	if (hash == '#Work') { gotoWork()};
	if (hash == '#Skills') { gotoSkills()};
	if (hash == '#Contact') { gotoContact()};
	if (hash == '#Gallery') { gotoGallery()};
    
    // Set the page title based on the hash.
	if (hash != '') { 
	document.title = (hash.replace( /^#/, '' ) || 'blank' ) + ' | JimOnEarth.co.uk | Freelance Web Design & Development By Jamie Kemp'
	};
	// Prefer the Home/About page to not have addtional hash titling.
	if (hash == '' || hash == '#About') { 
    document.title = 'JimOnEarth.co.uk | Freelance Web Design & Development By Jamie Kemp'
	};
	
	
});	

$(window).hashchange();

}); 

var clicky_pause_timer = 10;
$(function() {
  $('a').bind('click', function(e){
    clicky.log($(this).attr('href'), $(this).html());
  });
});  
