// JavaScript Document

$(document).ready(function() {		
	
	//Execute the slideShow, set 4 seconds for each images
	slideShow(4000);
 
});
 
function slideShow(speed) {
 
 
	//append a LI item to the UL list for displaying caption
	$('ul.slideshow3').append('<li id="slideshow3-caption" class="caption"><span class="slideshow3-caption-container"><span class="corp_title"></span><span class="offer_title"></span><span class="discount"></span><span class="dates"></span></span></li>');
 
	//Set the opacity of all images to 0
	$('ul.slideshow3 li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.slideshow3 li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#slideshow3-caption .dates').html($('ul.slideshow3 a:first').find('img').attr('title'));

//	$('#slideshow3-caption .corp_title').html('CORP');
//	$('#slideshow3-caption .offer_title').html('OFFER');
//	$('#slideshow3-caption .discount').html('DISCOUNT');

//	var alt_text=$('#slideshow3-caption .info').html($('ul.slideshow3 a:first').find('img').attr('alt'));
//	$('#slideshow3-caption strong').html($('ul.slideshow3 a:first').find('img').attr('alt'));
	var alt_text=$('.slideshow3').find('img').attr('alt');

var mySplitResult = alt_text.split("--");
var corp_title=mySplitResult[0];
var offer_title=mySplitResult[1];
var discount=mySplitResult[2];

$('#slideshow3-caption .corp_title').html(corp_title);
$('#slideshow3-caption .offer_title').html(offer_title);
$('#slideshow3-caption .discount').html(discount);



//////
//alert (corp_title);
//alert (offer_title);
//alert (discount);


	//Display the caption
	$('#slideshow3-caption').css({opacity: 1.0, bottom:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('gallery()',speed);
	
	//pause the slideshow on mouse over
	$('ul.slideshow3').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery()',speed);			
		}
	);
	
}
 
function gallery() {
 
 
	//if no IMGs have the show class, grab the first image
	var current = ($('ul.slideshow3 li.show')?  $('ul.slideshow3 li.show') : $('#ul.slideshow3 li:first'));
 
	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow3-caption')? $('ul.slideshow3 li:first') :current.next()) : $('ul.slideshow3 li:first'));
		
	//Get next image caption
	var title = next.find('img').attr('title');	
//	var desc = next.find('img').attr('alt');	
 
 	var alt_text=next.find('img').attr('alt');

var mySplitResult = alt_text.split("--");
var corp_title=mySplitResult[0];
var offer_title=mySplitResult[1];
var discount=mySplitResult[2];

 
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	//Hide the caption first, and then set and display the caption
	$('#slideshow3-caption').animate({bottom:-94}, 300, function () {
			//Display the content
			$('#slideshow3-caption .dates').html(title);
		//	$('#slideshow3-caption strong').html(desc);				
			$('#slideshow3-caption .corp_title').html(corp_title);
			$('#slideshow3-caption .offer_title').html(offer_title);
			$('#slideshow3-caption .discount').html(discount);

			$('#slideshow3-caption').animate({bottom:0}, 500);	
	});		
 
	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');
 
}
