delay = delay * 1000;
var timerOn = true;
var slideNum = 0;
var currentDiv = 0;	
var bgColorOn = "#254897";
var bgColorOff = "#55a2ec";
var playButtonPath = "/ue/home/blockyPlay_btn.gif";
var pauseButtonPath = "/ue/home/blockyPause_btn.gif";

if(!isSears){
	bgColorOn = "#7d0707";
	bgColorOff = "#d2021c";
	playButtonPath = "/ue/home/km_blockyPlay_btn.gif";
	pauseButtonPath = "/ue/home/km_blockyPause_btn.gif";
	borderColor = "#EBEBEB";
}

$(function(){
	
	//get the number of slides that are going to play
	slideNum = $(".blockySlider_main").find("#blockySlideShow .blockySlide").length;
	//default timer
	defaultTimer = setTimeout('changeSlider(currentDiv,slideNum)', delay);
	
	
			
	//create buttons
	var buttonContent = "<div id='blockySlideBtns'>\n\r";
	for(var j=0; j < slideNum; j++){
		buttonContent += "<div class='blockNumberButtons' id='" +j+ "'>" +(j+1)+ "</div>\n";
	}
	buttonContent += "<div class='blockNumberButtons' id='play'><img src='" + pauseButtonPath + "' /></div>\n\r</div>\n\r";	
	$(".blockySlider_main").append(buttonContent);
	
	//Set up initial look
	$("#blockySlideShow .blockySlide").eq(0).css("display","block");
	$(".blockNumberButtons").css("background-color", bgColorOff);
	$(".blockNumberButtons#play").css("background-color","white");
	$("#blockySlideBtns .blockNumberButtons:eq(" +currentDiv+ ")").css("background", bgColorOn);
	if(isBorderOn){
		$(".blockySlider_main").css("border","1px solid "+borderColor);	
		}		
	$(".blockySlider_main").css("height", sliderHeight).css("background","none");
	//button functionality
	$(".blockNumberButtons").click(function(){
		var thisID = $(this).attr("id");
		
		if(thisID=="play"){
			timerRevolt();
		} else if(thisID == currentDiv){

		} else {
			thisID;
			clickChangeSlider(thisID);
			$(this).css("background",bgColorOn);
		}
	});
	
	$(".blockNumberButtons").hover(function(){
		var thisID = $(this).attr("id"); 
		if(thisID != "play"){
			$(this).css("background",bgColorOn);
		}
	},function(){
		var thisID = $(this).attr("id"); 
		if(thisID != "play" && thisID != currentDiv){
				$(this).css("background",bgColorOff);
		}
	});
	
});

//timed change
function changeSlider(changeThisDiv,slideNum){ 
	$("#blockySlideShow .blockySlide:eq(" +changeThisDiv+ ")").fadeOut(1000);//.css("display", "none");
	$("#blockySlideBtns .blockNumberButtons:eq(" +changeThisDiv+ ")").css("background", bgColorOff);
	if(changeThisDiv >= slideNum-1){
		currentDiv = 0;
	} else {
		currentDiv++;
	}
	$("#blockySlideShow .blockySlide:eq(" +currentDiv+ ")").fadeIn(1000);//.css("display", "block");
	$("#blockySlideBtns .blockNumberButtons:eq(" +currentDiv+ ")").css("background", bgColorOn);
	defaultTimer = setTimeout('changeSlider(currentDiv,slideNum)', delay);	
}

//click change
function clickChangeSlider(toThisDiv){ 
	$("#blockySlideShow .blockySlide:eq(" +currentDiv+ ")").fadeOut(1000);//.css("display", "none");
	$("#blockySlideBtns .blockNumberButtons:eq(" +currentDiv+ ")").css("background", bgColorOff);
	$("#blockySlideShow .blockySlide:eq(" +toThisDiv+ ")").fadeIn(1000);//.css("display", "block");
	$("#blockySlideBtns .blockNumberButtons:eq(" +toThisDiv+ ")").css("background", bgColorOn);
	clearTimeout(defaultTimer);
	defaultTimer = 0;
	timerOn = false;
	currentDiv = toThisDiv;	
	$(".blockNumberButtons#play img").attr("src",playButtonPath);
}

//playbutton
function timerRevolt(){
	if(timerOn){
		clearTimeout(defaultTimer);
		defaultTimer = 0;
		timerOn = false;
		$(".blockNumberButtons#play img").attr("src",playButtonPath);
	} else {
		timerOn = true;
		changeSlider(currentDiv,slideNum);
		$(".blockNumberButtons#play img").attr("src", pauseButtonPath);
	}
}
