/** External Links **/

function externalLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) { var anchor = anchors[i]; if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; } } window.onload = externalLinks;

/** Sexy Slider **/

$(document).ready(function() { $("#gallerycont").SexySlider({ width: 820, height: 250, delay: 4000, strips: 15, effect: 'fade' }); });

/** Fancy Box **/

$(document).ready(function() { $("a[rel=sidebargallery]").fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition' : 'over', 'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">(' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ') &nbsp; ' + title : '') + '</span>'; } }); });
$(document).ready(function() { $("a[rel=carscarriages]").fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition' : 'over', 'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">(' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ') &nbsp; ' + title : '') + '</span>'; } }); });

$(document).ready(function() { $("a[rel=gallery-landau]").fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition' : 'over', 'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">(' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ') &nbsp; ' + title : '') + '</span>'; } }); });
$(document).ready(function() { $("a[rel=gallery-victoria]").fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition' : 'over', 'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">(' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ') &nbsp; ' + title : '') + '</span>'; } }); });

$(document).ready(function() { $("a[rel=gallery-badsworth]").fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition' : 'over', 'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">(' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ') &nbsp; ' + title : '') + '</span>'; } }); });
$(document).ready(function() { $("a[rel=gallery-ryecroft]").fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition' : 'over', 'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">(' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ') &nbsp; ' + title : '') + '</span>'; } }); });
$(document).ready(function() { $("a[rel=gallery-limousines]").fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition' : 'over', 'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">(' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ') &nbsp; ' + title : '') + '</span>'; } }); });
$(document).ready(function() { $("a[rel=gallery-silverspirit]").fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition' : 'over', 'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">(' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ') &nbsp; ' + title : '') + '</span>'; } }); });
$(document).ready(function() { $("a[rel=gallery-mercedes]").fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition' : 'over', 'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">(' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ') &nbsp; ' + title : '') + '</span>'; } }); });
$(document).ready(function() { $("a[rel=gallery-imperial]").fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition' : 'over', 'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">(' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ') &nbsp; ' + title : '') + '</span>'; } }); });

/** jQuery.ScrollTo - Required for ScrollTo **/

;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

$(document).ready(function() { $('a.backtotop').click(function(e) { $.scrollTo( this.hash || 0, 600); e.preventDefault(); }); });

/** Img Preloaders **/

$(function(){ $(".gallerycont").preloadify({ imagedelay: 30 }); });
$(function(){ $("ul.carcarriagesimgs").preloadify({ imagedelay: 30 }); });
$(function(){ $("#sidebargallery").preloadify({ imagedelay: 30 }); });

/** 404 Search Form **/

$(document).ready(function(){
	
	var config = {
		siteURL		: 'cottamcarriagesandweddingcars.co.uk',	// Change this to your site
		searchSite	: true,
		type		: 'web',
		append		: false,
		perPage		: 8,			// A maximum of 8 is allowed by Google
		page		: 0				// The start page
	}
	
	// The small arrow that marks the active search icon:
	var arrow = $('<span>',{className:'arrow'}).appendTo('ul.icons');
	
	$('ul.icons li').click(function(){
		var el = $(this);
		
		if(el.hasClass('active')){
			// The icon is already active, exit
			return false;
		}
		
		el.siblings().removeClass('active');
		el.addClass('active');
		
		// Move the arrow below this icon
		arrow.stop().animate({
			left		: el.position().left,
			marginLeft	: (el.width()/2)-4
		});
		
		// Set the search type
		config.type = el.attr('data-searchType');
		$('#more').fadeOut();
	});
	
	// Adding the site domain as a label for the first radio button:
	$('#siteNameLabel').append(' '+config.siteURL);
	
	// Marking the Search tutorialzine.com radio as active:
	$('#searchSite').click();	
	
	// Marking the web search icon as active:
	$('li.web').click();
	
	// Focusing the input text box:
	$('#s').focus();

	$('#searchForm').submit(function(){
		googleSearch();
		return false;
	});
	
	$('#searchSite,#searchWeb').change(function(){
		// Listening for a click on one of the radio buttons.
		// config.searchSite is either true or false.
		
		config.searchSite = this.id == 'searchSite';
	});
	
	
	function googleSearch(settings){
		
		// If no parameters are supplied to the function,
		// it takes its defaults from the config object above:
		
		settings = $.extend({},config,settings);
		settings.term = settings.term || $('#s').val();
		
		if(settings.searchSite){
			// Using the Google site:example.com to limit the search to a
			// specific domain:
			settings.term = 'site:'+settings.siteURL+' '+settings.term;
		}
		
		// URL of Google's AJAX search API
		var apiURL = 'http://ajax.googleapis.com/ajax/services/search/'+settings.type+'?v=1.0&callback=?';
		var resultsDiv = $('#resultsDiv');
		
		$.getJSON(apiURL,{q:settings.term,rsz:settings.perPage,start:settings.page*settings.perPage},function(r){
			
			var results = r.responseData.results;
			$('#more').remove();
			
			if(results.length){
				
				// If results were returned, add them to a pageContainer div,
				// after which append them to the #resultsDiv:
				
				var pageContainer = $('<div>',{className:'pageContainer'});
				
				for(var i=0;i<results.length;i++){
					// Creating a new result object and firing its toString method:
					pageContainer.append(new result(results[i]) + '');
				}
				
				if(!settings.append){
					// This is executed when running a new search, 
					// instead of clicking on the More button:
					resultsDiv.empty();
				}
				
				pageContainer.append('<div class="clear"></div>')
							 .hide().appendTo(resultsDiv)
							 .fadeIn('slow');
				
				var cursor = r.responseData.cursor;
				
				// Checking if there are more pages with results, 
				// and deciding whether to show the More button:
				
				if( +cursor.estimatedResultCount > (settings.page+1)*settings.perPage){
					$('<div>',{id:'more'}).appendTo(resultsDiv).click(function(){
						googleSearch({append:true,page:settings.page+1});
						$(this).fadeOut();
					});
				}
			}
			else {
				
				// No results were found for this search.
				
				resultsDiv.empty();
				$('<p>',{className:'notFound',html:'No Results Were Found!'}).hide().appendTo(resultsDiv).fadeIn();
			}
		});
	}
	
	function result(r)
	{
		var arr = [];
		switch(r.GsearchResultClass)
		{
			case 'GwebSearch':
				arr = [
					'<div class="webResult">',
					'<h2><a title="" href="',r.unescapedUrl,'">',r.title,'</a></h2>',
					'<p><a title="" href="',r.unescapedUrl,'">',r.visibleUrl,'</a> - ',
					'',r.content,'</p>',
					'</div>'
				];
			break;
		}
		this.toString = function(){ return arr.join(''); }
	}
	
	
});


