 $(document).ready(function() { 	
	Cufon.replace('h1, h2, h3, h4, .cufon');
	$('.corner').corner();	
	// Navigation Hovers
	$('#pri-nav li').append('<span class="hover"> </span>').each(function () {
		var $span = $('span.hover', this).css('opacity', 0);
	  	$(this).hover(function () {
	    	$span.stop().fadeTo(500, 1);
	 	}, function () {
	   		$span.stop().fadeTo(500, 0);
	  	});
	});
		//Templates Page - Overlay
		$("body.templates div#templates-wrapper a.template-link").append('<span class="overlay "></span>');
		 $('div#templates-wrapper span.overlay').css({opacity : '0'});
	 	$('div#templates-wrapper .template-chooser').hover(function () {
		 $(' span.overlay', this).css("display","block").fadeTo(200, 0.7);
	 }, function () {
	 	$(' span.overlay',this).fadeTo(200, 0).css({opacity : '0', display : 'none'});
	 });
	//Templates Page - Gallery(small)
	$('body.templates  div#templates-wrapper div.template-chooser').each(function() {
		var $pager = $('<div class="pager"></div>').insertAfter(this);
		$(this).cycle({fx:  'scrollLeft', speed:  'slow', timeout: 0, pager:  $pager,
		pagerAnchorBuilder: function(idx, slide) {
				var swatch = $('img',slide).attr('class');
				return '<a class="template-anchor '+swatch+'" href="#"><img alt="'+swatch+' colour swatch"src="assets/images/swatches/'+swatch+'.png" /></a>'; 
			} 
		});
	});

	//Templates Page - Gallery(large)
		var startSlide = window.location.toString().replace(/\D/g,'');
		startSlide--;
	$('#large-template-chooser').each(function() {
	$('#large-template-chooser').cycle({
		fx:     'scrollLeft', speed:  'slow', timeout: 0, startingSlide: startSlide, pager:  '#large-pager', 	
		pagerAnchorBuilder: function(idx, slide) {
			var swatch = $('img',slide).attr('class');
			return '<a class="template-anchor '+swatch+'" href="#"><img src="../assets/images/swatches/'+swatch+'.png" /></a>'; 
			} 
		});	
	});  

    $('#testimonials').before('<div class="pager testipager"></div>').cycle({fx:'fade', speed:  'fast', timeout: 20000, pager:  '.testipager'});		
    $('#portfolio-gallery').before('<div class="pager port-pager"></div>').cycle({fx:'fade', speed:  'fast', timeout: 20000, pager:  '.port-pager'});	
//Website Preview Boxes
	$('.website-preview-window').each(function () {
		var $span = $('.caption', this).css('opacity', 0);
	  	$(this).hover(function () {
	    	$span.stop().fadeTo(500, 1);
	 	}, function () {
	   		$span.stop().fadeTo(500, 0);
	  	});
	});	
	$(".page-jump").click(function(event){
		event.preventDefault();
		var full_url = this.href;
		var parts = full_url.split("#");
		var trgt = parts[1];
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;
		$('html, body').animate({scrollTop:target_top}, 500);
	});
	$('a[href^="http://"]').not("#footer a").attr("target", "_blank");
	//Template Preview nav fades
	/*
	$(function() {
		$("a.template-anchor:not(.activeSlide)").fadeTo("fast", 0.4); 
		$("a.template-anchor:not(.activeSlide)").hover(function()	{	
			$(this).fadeTo("fast", 1.0);	
		}, function(){ 	
			$(this).not(".activeSlide").fadeTo("fast", 0.4);
		});			
	});	
	//Template Preview nav fades, click fixes
	$(function() {
		$("a.template-anchor").click(function()	{	
			$(this).fadeTo("fast", 1.0);
			$("a.template-anchor:not(.activeSlide)").fadeTo("fast", 0.4); 
		});	
	});	*/	
});