﻿Cufon.replace('h2, h3, .button, .content p',{hover:true});

$(document).ready(function(){
    $('#services .nav').hide();

    var oldHash='';
    $(window).hashchange(function(){
		var newHash=(location.hash=='')?'home':location.hash.match(/#\/?(.+)$/)[1];
		if(newHash!=oldHash){
		    if($('.page').index($('#'+newHash))>-1)
		    scrollToUrl(newHash)
		}
    })
    $(window).hashchange()


    $('#mainRight').css({overflow:'hidden',height:800});
    $('#wrapper').append($('<div id="shadow"></div>'));

    function scrollToUrl(url){
        var trgt=$('#mainRight');
        if(url.indexOf('#')>-1) url=url.substr(url.indexOf('#')+1)
        // var url=url.substr(1); // strip # or replace absolute link before proceding
        trgt.stop().animate({'scrollLeft':(parseInt($('#'+url).position().left))},'slow',function(){oldHash=url;if(url!='home')self.location.href='#/'+url});
    }

    $('.nav').click(function(){scrollToUrl($(this).attr('href'));return false})

    $("a.colorboxed").each(function(){
        $(this).data('rTitle',$(this).attr('title')).attr('title','')
        var hh=($(this).attr('href').indexOf('Enquiry.aspx')>-1)?566:480;
        $(this).colorbox({title:$(this).data('rTitle'),
            initialWidth:10,initialHeight:10,width:620,height:hh,scrolling:false,
            onLoad:function(){$('#cboxClose').hide()},
            onComplete:function(){$('#cboxClose').show();Cufon.replace('h1')}
        });
    });
    $("a[rel$='gallery']").colorbox({initialWidth:10,initialHeight:10,previous:'&laquo; previous',next:'next &raquo;',
        onLoad:function(){$('#cboxClose').hide()},
        onComplete:function(){$('#cboxClose').show()}
    });


    /* create cover for home and services "pages" */
    $('<div class="cover"></div>').css('opacity',.5).appendTo($('#services .flL, #home'));
    /* rollover/click for the same pages */
    $('#services .flL, #home')
        .css('cursor','pointer')
        .mouseenter(function(){$(this).find('.cover').stop().animate({'opacity':0},'fast')})
        .mouseleave(function(){$(this).find('.cover').stop().animate({'opacity':.5},'fast')})
        .click(function(){scrollToUrl($(this).find('.nav').attr('href'))});
})
