var IrishSlot1;
var IrishSlot2;
var IrishSlot3;
var OtherSlot1;
var OtherSlot2;
var OtherSlot3;
var SlotImage1,SlotImage2,SlotImage3,SlotImage4,SlotImage5,SlotImage6;
var SlotText1,SlotText2,SlotText3,SlotText4,SlotText5,SlotText6;

		$(document).ready(function(){
		IrishSlot1= $('ul#promoirish li#section1 div');
		IrishSlot2 = $('ul#promoirish li#section2 div');
		IrishSlot3 = $('ul#promoirish li#section3 div');
		OtherSlot1 = $('ul#promoother li#section1 div');
		OtherSlot2 = $('ul#promoother li#section2 div');
		OtherSlot3 = $('ul#promoother li#section3 div');

		var featured =	$("#featured > ul");
		if(featured.length > 0){
		featured.tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
		}



		//booking.com ad
		$.getJSON('http://www.dublinevents.com/json/BookingPromoBanner.json', function(data) {

			showPicView(data);
		});
	});

$.fn.preload = function() {
	
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}

// Usage:



	function showPicView(data){

		//$([data.ireland.slot1.image,data.ireland.slot2.image,data.ireland.slot3.image,data.othercountries.slot1.image,data.othercountries.slot2.image,data.othercountries.slot3.image]).preload();
		
		IrishSlot1.click(function(){
			_gaq.push(['_trackEvent', 'Booking', 'BannerTop', data.ireland.slot1.place]);
			window.location = data.ireland.slot1.link;
		});
		IrishSlot2.click(function(){
			_gaq.push(['_trackEvent', 'Booking', 'BannerTop', data.ireland.slot2.place]);
			window.location = data.ireland.slot2.link;
		});
		IrishSlot3.click(function(){
			_gaq.push(['_trackEvent', 'Booking', 'BannerTop', data.ireland.slot3.place]);
			window.location = data.ireland.slot3.link;
		});
		OtherSlot1.click(function(){
			_gaq.push(['_trackEvent', 'Booking', 'BannerTop', data.othercountries.slot1.place]);
			window.location = data.othercountries.slot1.link;
		});
		OtherSlot2.click(function(){
			_gaq.push(['_trackEvent', 'Booking', 'BannerTop', data.othercountries.slot2.place]);
			window.location =  data.othercountries.slot2.link;
		});
		OtherSlot3.click(function(){
			_gaq.push(['_trackEvent', 'Booking', 'BannerTop', 'Car Hire']);
			window.location =  data.othercountries.slot3.link;
		});

		SlotImage1 = $('<img class="bookingslot" style="width:80px; height:80px;" src="'+data.ireland.slot1.image+'" />');
		SlotImage1.appendTo(IrishSlot1);
		SlotImage2 = $('<img class="bookingslot" style="width:80px; height:80px;" src="'+data.ireland.slot2.image+'" />');
		SlotImage2.appendTo(IrishSlot2);
		SlotImage3 = $('<img class="bookingslot" style="width:80px; height:80px;" src="'+data.ireland.slot3.image+'" />');
		SlotImage3.appendTo(IrishSlot3);
		SlotText1 = $('<span style="font-size:12px;">Stay In<br/>'+data.ireland.slot1.place + '</span><br/><span style="font-size:12px;"> From </span><span style="color:red; font-size:13px;">&euro;'+ data.ireland.slot1.price+'</span><br/><span style="font-size:12px;"><b>Book Now</b></span>');
		SlotText2 = $('<span style="font-size:12px;">Stay In<br/>'+data.ireland.slot2.place + '</span><br/><span style="font-size:12px;"> From </span><span style="color:red; font-size:13px;">&euro;'+ data.ireland.slot2.price+'</span><br/><span style="font-size:12px;"><b>Book Now</b></span>');
		SlotText3 = $('<span style="font-size:12px;">Stay In<br/>'+data.ireland.slot3.place + '</span><br/><span style="font-size:12px;"> From </span><span style="color:red; font-size:13px;">&euro;'+ data.ireland.slot3.price+'</span><br/><span style="font-size:12px;"><b>Book Now</b></span>');
		
		SlotImage4 = $('<img class="bookingslot" style="width:80px; height:80px;" src="'+data.othercountries.slot1.image+'" />');
		SlotImage4.appendTo(OtherSlot1);
		SlotImage5 = $('<img class="bookingslot" style="width:80px; height:80px;" src="'+data.othercountries.slot2.image+'" />');
		SlotImage5.appendTo(OtherSlot2);
		SlotImage6 = $('<img class="bookingslot" style="width:80px; height:80px;" src="'+data.othercountries.slot3.image+'" />');
		SlotImage6.appendTo(OtherSlot3);
		
		SlotText4 = $('<br/><span style="font-size:12px;">Stay In<br/>'+data.othercountries.slot1.place + '</span><br/><span style="font-size:12px;"> From </span><span style="color:red; font-size:13px;">&euro;'+ data.othercountries.slot1.price+'</span><br/><span style="font-size:12px;"><b>Book Now</b></span>');
		SlotText5 = $('<br/><span style="font-size:12px;">Stay In<br/>'+data.othercountries.slot2.place + '</span><br/><span style="font-size:12px;"> From </span><span style="color:red; font-size:13px;">&euro;'+ data.othercountries.slot2.price+'</span><br/><span style="font-size:12px;"><b>Book Now</b></span>');
		SlotText6 = $('<br /><span style="font-size:12px;">Irish</span><br /> <span style="font-size:12px;">Car Hire</span><br /><span style="font-size:12px;"> From </span><span style="color:red; font-size:13px;">&euro;24'+'</span><br /> <span style="font-size:12px;"><b>Book Now</b></span>');
		
		showInfoView(data);
	}

debug = false;
function showInfoView(data){
	setTimeout(function(){
		OtherSlot1.html('');
		SlotText4.appendTo(OtherSlot1);
		IrishSlot3.html('');
		SlotText3.appendTo(IrishSlot3);
		setTimeout(function(){
			OtherSlot3.html('');
			SlotImage6.appendTo(OtherSlot3);
			IrishSlot1.html('');
			SlotImage1.appendTo(IrishSlot1);
		},6000);
	},2500);
	setTimeout(function(){
		OtherSlot2.html('');
		SlotText5.appendTo(OtherSlot2);
		IrishSlot2.html('');
		SlotText2.appendTo(IrishSlot2);
		setTimeout(function(){
			OtherSlot2.html('');
			SlotImage5.appendTo(OtherSlot2);
			IrishSlot2.html('');
			SlotImage2.appendTo(IrishSlot2);
		},4000);
	},4500);
	setTimeout(function(){
		OtherSlot3.html('');
		SlotText6.appendTo(OtherSlot3);
		IrishSlot1.html('');
		SlotText1.appendTo(IrishSlot1);
		setTimeout(function(){
			OtherSlot1.html('');
			SlotImage4.appendTo(OtherSlot1);
			IrishSlot3.html('');
			SlotImage3.appendTo(IrishSlot3);
		},2000);
	},6500);
	//restart call
	setTimeout(function(){
		showInfoView(data);
	},8600);
}

