
$(document).ready(function(){

if (document.form2) init_makemodel(document.form2);

//HOMEPAGE SLIDER
$('#slides').slides({
	preload: true,
	preloadImage: 'http://mazda.carzone.com/templates/mazda2011dealer/img/loading.gif',
	play: 5000,
	slideSpeed: 620,
	pause: 5500
});

// Homepage Showroom background animation:
 	
	$('.mazda2, .mazda3, .mazda5, .mazda6, .mazda-mx-5, .mazda-cx-7')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-162px 0)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0)"}, {duration:1, complete:function(){
				$(this).css({backgroundPosition: "0 0"})
			}})
		});
		

		
		$('ul.homepage-widget-featured li')
		.css( {backgroundPosition: "0px 0px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px -50px)"}, {duration:200})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0px 0px"})
			}})
		})
		

		
	$('.mazda2, .mazda3, .mazda5, .mazda6, .mazda-mx-5, .mazda-cx-7')
	.mouseover(function(){
	$(this).next('a').css('background-color', '#dde7ed');
	})
	.mouseout(function(){
	$(this).next('a').css('background-color', '#d2dee6');
	});





//Special Offers Carusel
$("div#widget-offers").carousel({
	direction: "vertical",
	dispItems: 1,
	loop: true,
	autoSlide: true,
	effect: "fade"
});
/* NEW CAR GALLERY*/

$("a[rel=mazda_gallery_group]").fancybox({
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'titlePosition' 	: 'over',
	'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {return '<span id="fancybox-title-over">Mazda image ' + (currentIndex + 1) + ' / ' + currentArray.length + ' &nbsp; : &nbsp; Model shown may not be to Ireland specification. Colours and some exterior and/or interior elements may differ on screen from the actual model.' + '</span>';}
});

$("a[rel=mazda_dealer_img]").fancybox({
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'titlePosition' 	: 'over',
	'titleFormat'		: function(title, currentOpts) {
	return '<span id="fancybox-title-over">' + (title.length ? ' &nbsp; ' + title : '') + '</span>';}
	});

//END

});


function ShowEm(str)
{
	var sp,a,e;
	if (sp = document.getElementById("hirajem"))
	{
		if (e = sp.getAttribute("str"))
		{
			var e2="";
			for (var b=0;b<e.length;b++) e2+=String.fromCharCode(e.charCodeAt(b)-1);
			sp.innerHTML = "E-mail: ";
			a = document.createElement("a");
			a.href = "mailto:"+e2;
			a.innerHTML = e2;
			$('#hirajem').after(a);
			$('#hirajem').removeAttr("str")
			$('#hirajem').removeAttr("id")
		}
	}
}

