/** 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;

/** Gallery **/

function slideSwitch()
{
	var $active = $('#slideshow IMG.active');
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
    var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0}) .addClass('active') .animate({opacity: 1.0}, 1000, function() { $active.removeClass('active last-active'); });
}

$(function() { setInterval( "slideSwitch()", 5000 ); });

/** 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=gallery-maingallery]").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-bridalcar]").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-bridesmaidcar]").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-othercar1]").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-othercar2]").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-othercar3]").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-othercar4]").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-othercar5]").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>'; } }); });

/** Img Preloaders **/

$(function(){ $(".gallery").preloadify({ imagedelay: 30 }); });
$(function(){ $(".ourcarscont").preloadify({ imagedelay: 30 }); });

/** 404 Search Form **/

$(document).ready(function(){
	
	var config = {
		siteURL		: 'oakleyweddingcars.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(''); }
	}
	
	
});

/** Hover Boxes **/

(function($) { $.fn.imageEffects = function(options) {
	   var easingType = "linear";
	   var transitionTimeGo = 200;
	   var imageWidth=0;
	   var imageHeight=0;
	   var totalWidth=[];
	   var totalHeight=[];
	   var tempLeft=0;
	   var left=0;
	   var top=0;
	   var zoomSize=30;
	   var overlaySize=60;
	   var defaults = {}, options = $.extend(defaults, options);
	   this.each(function() { var $this = $(this);	
		var effectOverlayArray = $(".effectoverlay");
		for (i = 0; i < effectOverlayArray.length; i++) {
		 effectOverlayArray.eq(i).wrap('<div class="overlay" style="position:relative; display:inline-block;"/>');
		 imageWidth = effectOverlayArray.eq(i).width();
		  imageHeight = effectOverlayArray.eq(i).height();
		  
		 var aux=$(".overlay").eq(i)
		  if(effectOverlayArray.eq(i)[0].nodeName==="A")
		  {
		  	imageWidth=effectOverlayArray.attr('width');
			imageHeight=effectOverlayArray.attr('height');
			
			var aux2=aux.find('.effectoverlay');
			aux2.append('<div class="overlayBg" style="position:absolute; top:0px; left:0px; background: #000 url(images/zoom.png) center center no-repeat; width:' + imageWidth + 'px;height:' + imageHeight + 'px; opacity:0; filter:alpha(opacity=0);"></div>');	 // load overlay images	
	
		 	
			aux=$(".overlay").eq(i).find('.effectoverlay');
		  }
		  else
		  {
		  	aux.append('<div class="overlayBg" style="position:absolute; top:0px; left:0px; background: #000 url(images/zoom.png) center center no-repeat; width:' + imageWidth + 'px;height:' + imageHeight + 'px; opacity:0; filter:alpha(opacity=0);"></div>');	 // load overlay images	

		  }

		 $(".overlayImgs").eq(i).css({
				   		'position': 'absolute','left': (imageWidth/2 - overlaySize/2),'top':(imageHeight/2 - overlaySize/2),'opacity':0});
						
						
						// on mouse over we change the png file opacity(overlay image) to 1
			aux.mouseover(function(){
			var aux3=$(this).children()
		 	aux3.eq(1).animate({
		 			opacity: 0.7},  {queue: false, duration: transitionTimeGo})
		 	aux3.eq(2).animate({
		 			opacity: 1},  {queue: false, duration: transitionTimeGo})
			 	});
			
	 
	   	// on mouse out we change overlay image	opacity to 0   
			aux.mouseout(function(){
				var aux3=$(this).children()
			 	aux3.eq(1).animate({
			 			opacity: 0},  {queue: false, duration: transitionTimeGo})
			 	aux3.eq(2).animate({
			 			opacity: 0},  {queue: false, duration: transitionTimeGo})
				 	});
		}
            return this;

		}); // end each
	}

})(jQuery);

jQuery(window).load(function() {
  if (jQuery.browser.safari && document.readyState != "complete"){
    console.info('done');
    setTimeout( arguments.callee, 120 );
    return;
  } 
 jQuery('body').imageEffects({
	 
 })
})


