//Window onLoad Events
function winOnLoad(){
    window.onload = winOnLoadGo;
}

function winOnLoadGo(){
    for(var i = 0;i < winOnLoadEvents.length;i++)
	eval(winOnLoadEvents[i]);
}

function winOnLoadAdd(func){
    winOnLoadEvents[winOnLoadEvents.length] = func;
}
var winOnLoadEvents = new Array();

winOnLoadAdd('resetWindowSize();');
winOnLoadAdd('setNavigation();');
winOnLoadAdd('clickWishListAnchor();');
winOnLoad();

window.onresize = new Function("resetWindowSize();");

// Browser Detection
function BrowserCheck() {
    var b = navigator.appName;	
    if (b=="Netscape") this.b = "ns";
    else if (b=="Microsoft Internet Explorer") this.b = "ie";
    else this.b = b;
    this.version = navigator.appVersion;
    // if (this.version.indexOf('Win')>0) this.os = "PC";
    // else if (this.version.indexOf('Mac')>0) this.os = "Mac";
    this.WinOs = (this.version.indexOf('Win')>0);
    this.v = parseInt(this.version);
    this.ns = (this.b=="ns" && this.v>=4);
    this.ns4 = (this.b=="ns" && this.v==4);
    this.ns5 = (this.b=="ns" && this.v>=5);
    this.ie = (this.b=="ie" && this.v>=4);
    this.ie4 = (this.version.indexOf('MSIE 4')>0);
    this.ie5 = (this.version.indexOf('MSIE 5')>0);
    this.ie6 = (this.version.indexOf('MSIE 6')>0);
    this.min = (this.ns||this.ie);
}
var browser = new BrowserCheck();

/***********************************************************************************************************************
 * Dynamic Ajax Content- Dynamic Drive DHTML code library (www.dynamicdrive.com) This notice MUST stay intact for legal
 * use Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
 **********************************************************************************************************************/

var loadedobjects=""
    var rootdomain="http://"+window.location.hostname

    function ajaxpage(url, containerid){
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
	page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
	try {
	    page_request = new ActiveXObject("Msxml2.XMLHTTP")
	} 
    catch (e){
	try{
	    page_request = new ActiveXObject("Microsoft.XMLHTTP")
	}
	catch (e){}
    }
    }
    else
	return false
	page_request.onreadystatechange=function(){
	loadpage(page_request, containerid)
    }
    page_request.open('GET', url, true)
    page_request.send(null)
}

function loadpage(page_request, containerid){
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
	document.getElementById(containerid).innerHTML=page_request.responseText;
    }
}


function setTabOn(tab,pageURL,divID){
    var e=document.getElementsByTagName("div");
    for(var i=0;i<e.length;i++){							
	if(e[i].className.indexOf("contentTab_Links") > -1){														
	    var k=e[i].getElementsByTagName("li");								
	    for(var n=0;n<k.length;n++){									
		if (k[n].innerHTML.indexOf(tab.innerHTML) > -1){
		    k[n].className = 'tabOn';
		    ajaxpage(pageURL, divID);
		}else{
		    k[n].className = '';
		}									
	    }	
	}
    }
}

function popWindow(url, width, height, name, scrollbars){
    if (!scrollbars) scrollbars = false;
    if (!width) width = 500;
    if (!height) height = 500;
    var realW = (width)/2;
    var realH = (height)/2;
    if (document.all){		
	var xMax = screen.width, yMax = screen.height;
    }else if (document.layers){       
	var xMax = screen.width, yMax = screen.height;
    }else if (document.getElementById){
	var xMax = screen.width, yMax = screen.height;
    }else{
	var xMax = 800, yMax=600;
    }
    var xOffset = ((xMax)/2) - realW, yOffset = (((yMax)/2)) - realH; 
    if (yMax==600){
	yOffset = 0;
    }	

    if (scrollbars) {
	var options = "directories=no,status=no,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=no" + ",screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",width=" + width + ",height=" + height;
    }else{
	var options = "directories=no,status=no,location=no,scrollbars=no,menubar=no,toolbar=no,resizable=no" + ",screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",width=" + width + ",height=" + height;
    }

    if (!name) name = "default_window";

    popup = window.open(url,name,options);
    popup.focus();	
}


var timerID;
var timeout = 500;

function overMenuParent(listId){	
    if (timerID) clearTimeout(timerID);
    tempClassName = listId.className;	
    if (tempClassName.indexOf("NavOver") == -1 && tempClassName.indexOf("NavNoChildOver") == -1){
	closeMenus();			
	displayChildMenu(listId);					
    }	
}
function overChildMenu(){
    if (timerID) clearTimeout(timerID);		
}
function displayChildMenu(listId){
    navRoot = getElmtRef("gblMainNavList");
    navContainer = getElmtRef("gblMainNav");
    for (i=0; i<navRoot.childNodes.length; i++) {				
	node = navRoot.childNodes[i];			
	if (node==listId) {					
	    for (j=0; j<node.childNodes.length; j++) {	
		node2 = node.childNodes[j];				
		if (node2.nodeName=="UL") {		
		    node.className = tempClassName + ' NavOver';	
		    node2.style.display = "block";	
		    leftPosition = 0;
		    topPosition = 0;

		    if(findGlobalPosX(listId) != 0){
			leftPosition = findGlobalPosX(listId) + 1;
			
		    }

		    if (leftPosition + node2.offsetWidth > getElmtRef("header").offsetWidth){
			leftPosition = (findGlobalPosX(listId) + listId.offsetWidth) - node2.offsetWidth;
		    }	
		    leftPosition = leftPosition - 14;
		    node2.style.left = leftPosition+'px';
		    //node2.style.top = topPosition + navContainer.offsetHeight +'px';
		    hideShowSelectBox(findGlobalPosX(node2),findGlobalPosY(node2),node2.offsetWidth,node2.offsetHeight);

		    if(browser.ie6){						
			linkWidth = node2.offsetWidth - 2;					
			for(var z=0;z<node2.childNodes.length;z++){	
			    var x=node2.childNodes[z].getElementsByTagName("a");
			    for(var y=0;y<x.length;y++){							
				x[y].style.width = (linkWidth - 45)+ "px";																
			    }									
			}
		    }
		    node2.style.visibility = "visible";	
		    break;
		}else{					
		    node.className = tempClassName + ' NavNoChildOver';	
		}
	    }						
	}
    }	
}
function offMenuParent(listId){
    timerID = setTimeout('closeMenus();',timeout);
}

function closeMenus(){	
    showAllSelectBoxes();
    navRoot = getElmtRef("gblMainNavList");
    for (i=0; i<navRoot.childNodes.length; i++) {				
	node = navRoot.childNodes[i];			
	if (node.nodeName=="LI") {	
	    for (j=0; j<node.childNodes.length; j++) {	
		node2 = node.childNodes[j];				
		if (node2.nodeName=="UL") {						
		    if (node.className.indexOf("NavOver") > -1){											
			if (node.className.indexOf(" ") > -1){
			    beginSpace = node.className.indexOf(" NavOver");
			    node.className = node.className.substr(0,beginSpace);								
			}else{
			    node.className = '';
			}	
		    }	
		    node2.style.visibility = "hidden";	
		    node2.style.display = "none";								
		    break;
		}else{					
		    if (node.className.indexOf("NavNoChildOver") > -1){											
			if (node.className.indexOf(" ") > -1){
			    beginSpace = node.className.indexOf(" NavNoChildOver");
			    node.className = node.className.substr(0,beginSpace);								
			}else{
			    node.className = '';
			}	
		    }
		}
	    }	
	}
    }	
}



function hideShowSelectBox(menuLeftPos,menuTopPos,menuWidth,menuHeight){	
    for(slectLoop1=0;slectLoop1<document.forms.length;slectLoop1++){		
	for(slectLoop2=0;slectLoop2<document.forms[slectLoop1].elements.length;slectLoop2++){			
	    if(document.forms[slectLoop1].elements[slectLoop2].type.indexOf("select") > -1){
		var tempSelectY = findGlobalPosY(document.forms[slectLoop1].elements[slectLoop2]);
		var tempSelectX = findGlobalPosX(document.forms[slectLoop1].elements[slectLoop2]);
		var tempSelectWidth = document.forms[slectLoop1].elements[slectLoop2].offsetWidth;
		var tempSelectHeight = document.forms[slectLoop1].elements[slectLoop2].offsetHeight;
		if((tempSelectY <= menuTopPos + menuHeight && tempSelectY + tempSelectHeight >= menuTopPos ) && ((tempSelectX <= menuLeftPos && menuLeftPos <= (tempSelectWidth + tempSelectX)) || ((menuLeftPos <= tempSelectX) && (menuLeftPos + menuWidth > tempSelectX)))){
		    document.forms[slectLoop1].elements[slectLoop2].style.visibility = 'hidden';
		}else{
		    document.forms[slectLoop1].elements[slectLoop2].style.visibility = 'visible';
		}
	    }
	}
    }

}

function showAllSelectBoxes(){
    for(i=0;i<document.forms.length;i++){		
	for(j=0;j<document.forms[i].elements.length;j++){			
	    if(document.forms[i].elements[j].type.indexOf("select") > -1){					
		document.forms[i].elements[j].style.visibility = 'visible';					
	    }
	}
    }
}


function getElmtRef(strElmtId) {
    if (!document.getElementById) {
	return document.all[strElmtId];
    } else {
	return document.getElementById(strElmtId);
    }
}
function findGlobalPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
	while (obj.offsetParent) {
	    curleft += obj.offsetLeft;
	    obj = obj.offsetParent;
	}
    } else if (obj.x) {
	curleft += obj.x;
    }
    return curleft;
}

function findGlobalPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
	while (obj.offsetParent) {
	    curtop += obj.offsetTop;
	    obj = obj.offsetParent;
	}
	curtop += 1;
    } else if (obj.y) {
	curtop += obj.y;
    }
    return curtop;
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
	//Netscape compliant
	scrOfY = window.pageYOffset;
	scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	//DOM compliant
	scrOfY = document.body.scrollTop;
	scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	//IE6 standards compliant mode
	scrOfY = document.documentElement.scrollTop;
	scrOfX = document.documentElement.scrollLeft;
    }
    //return [ scrOfX, scrOfY ];
    return scrOfY;
}

function resetWindowSize(){	
    if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	window_width = window.innerWidth;
	window_height = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	window_width = document.documentElement.clientWidth;
	window_height = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	window_width = document.body.clientWidth;
	window_height = document.body.clientHeight;
    }
}



function setNavigation() {	
    if(getElmtRef("gblMainNavList")){
	navRoot = getElmtRef("gblMainNavList");
	for (i=0; i<navRoot.childNodes.length; i++) {				
	    node = navRoot.childNodes[i];			
	    if (node.nodeName=="LI") {						
		node.onmouseover=function() {
		    overMenuParent(this);
		}
		node.onmouseout=function() {
		    offMenuParent(this);
		}						
	    }
	}	
    }
}
//window.onload=startList;





/* Code for Layer Pop Ups */
function dynInfo(linkObj,header,content){
    closeDynInfo();	
    getElmtRef("popDynInfoHeader").innerHTML = header;
    getElmtRef("popDynInfoContent").innerHTML = content;
    getElmtRef("popDynInfoContainer").style.display = 'block';	

    var popLayerXpos = findGlobalPosX(getElmtRef("popDynInfoContainer"));
    var popLayerYpos = findGlobalPosY(getElmtRef("popDynInfoContainer"));
    var popLayerHeight = getElmtRef("popDynInfoContainer").offsetHeight;
    var popLayerWidth = getElmtRef("popDynInfoContainer").offsetWidth;
    var popLayerArrowWidth = getElmtRef("popDynArrow").offsetWidth;
    var popLayerArrowHeight = getElmtRef("popDynArrow").offsetHeight;
    var pageWidth = getElmtRef("main").offsetWidth;	

    var arrowTopPos = ((popLayerHeight / 2) - (popLayerArrowHeight / 2));	
    var topPos = (findGlobalPosY(linkObj) - (popLayerHeight / 2));	

    if (topPos - getScrollXY() + popLayerHeight > window_height){		
	tempDifference = topPos - getScrollXY() + popLayerHeight - window_height;		
	topPos = topPos - tempDifference;
	arrowTopPos = arrowTopPos + tempDifference;
	if(arrowTopPos + popLayerArrowHeight > popLayerHeight){
	    arrowTopPos = popLayerHeight - popLayerArrowHeight - 2;
	}	
    }else if (topPos - getScrollXY() < 0){		
	tempDifference = topPos - getScrollXY();
	topPos = topPos - tempDifference;
	arrowTopPos = arrowTopPos + tempDifference + 2;	
	if(arrowTopPos < 1){
	    arrowTopPos = 2;
	}		
    }

    getElmtRef("popDynInfoContainer").style.top = topPos + 'px';

    var leftPos = findGlobalPosX(linkObj) + linkObj.offsetWidth + popLayerArrowWidth;

    if(leftPos + popLayerWidth > pageWidth){
	leftPos = findGlobalPosX(linkObj) - popLayerWidth - popLayerArrowWidth;
	getElmtRef("popDynArrow").style.left = popLayerWidth - 3 + 'px';
	getElmtRef("popDynArrow").className = 'right';
    }else{		
	getElmtRef("popDynArrow").style.left = 0 - popLayerArrowWidth + 'px';
	getElmtRef("popDynArrow").className = 'left';
    }

    getElmtRef("popDynArrow").style.top = arrowTopPos + 'px';
    getElmtRef("popDynInfoContainer").style.left = leftPos + 'px';	

    hideShowSelectBox(leftPos,topPos,popLayerWidth,popLayerHeight);

    getElmtRef("popDynInfoContainer").style.visibility = 'visible';

}

function closeDynInfo(){
    showAllSelectBoxes();
    getElmtRef("popDynInfoContainer").style.visibility = 'hidden';
    getElmtRef("popDynInfoContainer").style.display = 'none';
    getElmtRef("popDynInfoContainer").style.top = '0px';
    getElmtRef("popDynInfoContainer").style.left = '0px';
    getElmtRef("popDynArrow").className = '';
    getElmtRef("popDynInfoHeader").innerHTML = '';
    getElmtRef("popDynInfoContent").innerHTML = '';
}

//Form Inputs (Text) Clear and Replace
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
	element.addEventListener(eventType, lamdaFunction, useCapture);
	return true;
    } else if (element.attachEvent) {
	var r = element.attachEvent('on' + eventType, lamdaFunction);
	return r;
    } else {
	return false;
    }
}

// pknoll 6/7/2007

// This event handler functionality is causing problems with dsp:input tags which set "value=" from bean properties.
// if the clear/replace default text functionality is required, a separate function should be written to set these
// using another method than the "value" attribute

/*
 * addEvent(window, 'load', init, false);
 * 
 * function init() { var formInputs = document.getElementsByTagName('input'); for (var i = 0; i < formInputs.length;
 * i++) { var theInput = formInputs[i];
 * 
 * if (theInput.type == 'text') { // Add event handlers addEvent(theInput, 'focus', clearDefaultText, false);
 * addEvent(theInput, 'blur', replaceDefaultText, false); // Save the current value if (theInput.value != '') {
 * theInput.defaultText = theInput.value; } } } }
 */
function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;

    if (target.value == target.defaultText) {
	target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;

    if (target.value == '' && target.defaultText) {
	target.value = target.defaultText;
    }
}

/* Homepage Cursor Trail */
function trailLayerobj(){
    if (document.getElementById)
	return document.getElementById("homeProductCursorTrail").style
	else if (document.all)
	    return document.all.homeProductCursorTrail.style
}

function docBodyType(){
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

var cursoroffset=[20,-10];
var cursorTimerID;
var cursorTimecount = 200;
var bolProdLayerShown = false;

function trailCursor(e){
    if (cursorTimerID) clearTimeout(cursorTimerID);
    var xcoordinate=cursoroffset[0];
    var ycoordinate=cursoroffset[1];
    if (typeof e != "undefined"){
	xcoordinate+=e.pageX
	ycoordinate+=e.pageY
    }
    else if (typeof window.event !="undefined"){
	xcoordinate+=docBodyType().scrollLeft+event.clientX
	ycoordinate+=docBodyType().scrollTop+event.clientY
    }		
    trailLayerobj().left=xcoordinate+"px"
    trailLayerobj().top=ycoordinate+"px"

    if (!bolProdLayerShown){
	trailLayerobj().visibility="visible";
	trailLayerobj().display="";
	bolProdLayerShown = true;
    }
}

function completeHideLayer(){		
    trailLayerobj().visibility="hidden";
    bolProdLayerShown = false;
}

function hideTrailLayer(){
    cursorTimerID = setTimeout('completeHideLayer();',cursorTimecount);	
}

function initCursorTrail(){
    getElmtRef("home_product_bkgnd").onmousemove=trailCursor
    getElmtRef("home_product_bkgnd").onmouseout=hideTrailLayer
}

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
	limitField.value = limitField.value.substring(0, limitNum);
    } 
}

function loadBrandsList() {	
    textURL = '/ulta/browse/brandList.jsp';
    $('#brandListOptions').load(textURL,function(){
    	var selectmenu=document.getElementById("brandSelector")
		
    	if(selectmenu || selectmenu != null){
    		selectmenu.onchange=function() { 
				var chosenoption=this.options[this.selectedIndex] // this refers to "selectmenu"
			    if (chosenoption.value!="nothing"){
			    	window.location = chosenoption.value;
			    }
			}
		}
    }); 
}

$(document).ready(function (){

	var checkPhoneURL = document.location.href;
	checkPhoneURL = checkPhoneURL.toLowerCase();
	
	if(checkPhoneURL.indexOf("stores.ulta.com") == -1) {
		checkPhone();
	}
	
	setReminder();
});	

	
//format phone # field as 3 separate fields
function checkPhone(){
	var isPhone = $('.phoneFields').length;
	
	if (isPhone){
		$('.phoneFields .phone').keyup(function(event){
			var phone1 = $('.phoneFields .phone1').val();
			var phone2 = $('.phoneFields .phone2').val();
			var phone3 = $('.phoneFields .phone3').val();
			
			$('.phoneFields .phoneNumber').val(phone1 + '-' + phone2 + '-' + phone3);
			
			var phoneVal = $('.phoneFields .phoneNumber').val();
			if (phoneVal == '--'){
				$('.phoneFields .phoneNumber').val('');
			}
			
		});
	
		$('.phoneFields .phone1').keyup(function(event){
			if($(this).val().length == 3){
				var phoneEle = $(this).parent(".phoneFields");
				var pInd = $('.phoneFields').index(phoneEle);
				$('.phoneFields .phone2').focus().select();
			} 
		});
	
		$('.phoneFields .phone2').keyup(function(event){
			if($(this).val().length == 3){
				var phoneEle = $(this).parent(".phoneFields");
				var pInd = $('.phoneFields').index(phoneEle);
				$('.phoneFields .phone3').focus().select();
			}
		});
		
		phoneNum = $('.phoneFields .phoneNumber').val();
		subPhone = phoneNum.split('-');
		
		$('.phoneFields .phone1').val(subPhone[0]);
		$('.phoneFields .phone2').val(subPhone[1]);
		$('.phoneFields .phone3').val(subPhone[2]);
		
	}
}

function selectError(elements){
	if($.browser.msie && $.browser.version <= "7.0"){
		$(elements).each(function(index) {
			if (this.tagName == 'SELECT'){
				$(this).wrap('<div class="selError" />');
			}
		});
	}
}


function clickWishListAnchor() {
	var wishLocation = window.location.href;
	var element = document.getElementById("wishanchor");
	if(element != null) {
	  if(wishLocation.indexOf("dowish=1") > -1) {
		window.location.replace(element.href);   
	  }	  
	}	
}

function selectNewAddress() {
  var selectElement = document.getElementById("addressselect");
  selectElement.options[selectElement.options.length - 1].selected="1";	
}

function setReminder(){
	
	$('.setReminder select').bind('change', function(e) {
		loadReminder(this);
		e.preventDefault();
	});
	
	$('.setReminder a.remove').bind('click', function(e) {
		loadReminder(this);
		e.preventDefault();
	});
		
}

function loadReminder(e){
	var userId = $('#profileId').val();
	
	var skuId = $(e).siblings('.skuId').val();
	var prodId = $(e).siblings('.prodId').val();
	
	var interval = $(e).val();
	if (!interval){
		//set to remove
		interval = -1
	}
	var httpProtocol = location.protocol;
	
	if (httpProtocol.indexOf('https') == -1){
		var path = '/ulta/reminder/';
	} else {
		var path = '/ulta/myaccount/';
	}
	var url = path + 'reminder_message.jsp?userID=' + userId + '&skuID=' + skuId + '&productID=' + prodId + '&interval='+interval ;
	
	$('.setReminder .response').text('');
	
	if (userId){
		var isProdDetail = $('#myAccount').length;
		if (isProdDetail > 0){
			$(e).closest('.setReminder').find('.response').load(url, function(response) {});
		} else {
			$(e).closest('.setReminder').load(url, function(response) {});
		}
		
	} else {
		//not loged in
		window.location = '/ulta/myaccount/login.jsp?addReminder=true&skuID=' + skuId + '&productID=' + prodId + '&interval='+interval ;
	}
	
}


sfHover = function() {
	var sfEls = document.getElementById("headerAcctNav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

var isAcctNav = $('#headerAcctNav').length;
if (isAcctNav > 0){
	if (window.attachEvent) window.attachEvent("onload", sfHover);

}



$(document).ready(function(){
	var cacheArr = "";
	
	var imgArr = $('.slideShow .hiddenVar').toArray()
	
	$.each(imgArr, function(key, value) { 
		imgPath = $(value).text();
		if (imgPath != ''){
			cacheArr = cacheArr + imgPath + ' || ';
		}
	});
	
	
	strEnd = cacheArr.lastIndexOf(' || ');
	cacheArr = cacheArr.slice(0,strEnd);
	cacheArr = cacheArr.split(" || ");
	
	//caches images, and starts show once loaded
	$.loadImages(cacheArr, function(){
		//alert('loadedddd:'+cacheArr)
		addImages(cacheArr);
	});
	
	setTabs();
});



function addImages(){
	var shows = $('.slideShow');
	
	//loop through all the .slideShow divs
	$.each(shows, function(key, value) { 
		var parentShow = $(value);
		var test = $(value).children('.slide');
		var whichShow = key;
		var liTag = '';
		
		
		
		//loop through the contents of each .slideShow div
		$.each(test, function(key, value) {
			var numSlides = $(test).size();
			
			
			if (key != 0){
				imgClass = $(value).hasClass('image')
				mapClass = $(value).hasClass('imageMap')
				if (imgClass || mapClass){
					var imgPath = $(value).find('.hiddenVar').text()
					$(value).find('.mainImg').attr('src',imgPath)
				}
				liTag = liTag + '<li><b>'+parseInt(key+1)+'</b></li>'
			} else{
				liTag = liTag + '<li class="on"><b>'+parseInt(key+1)+'</b></li>'
			}
			
			//console.log(key +' '+ numSlides)
			if (key+1 == numSlides){
				var nav = '<div class="bar"><ul>'+liTag+'</ul></div>';
				$(parentShow).append(nav);
			}
		});
	});

	autoStart();
	bindShow();
}



function autoStart(){
	var shows = $('.slideShow');
	$.each(shows, function(key, value) { 
		$('.slideShow div.slide:first').eq(key).fadeIn('fast');
		
		var slideLen = $(value).find('.bar li').size()-1;
		if (1 <= slideLen){
			$('.hero .slideShow div.bar').eq(key).fadeTo('fast', 1);
		}
			
	});

	showTimer = setInterval(function(){
		changeSlide();
	}, 4000); 
}

function changeSlide(setSlide){

	var shows = $('.slideShow');
	$.each(shows, function(key, value) { 
		var slideLen = $(value).find('.bar li').size()-1;
		
		if (1 <= slideLen){

			if (!setSlide && setSlide != 0){
				var slideNum = $(value).find('.bar li.on').index()+1;
			} else {
				var slideNum = setSlide;
				
			}
			//console.log( 'slidelen:'+slideLen + ' || slideNum:'+slideNum );
			
			if(slideLen + 1 == slideNum){
				slideNum = 0;
			}
			
			/*
				$(value).find('div.slide:visible').css('display','none');
				$(value).find('div.slide:eq('+slideNum+')').css('display','block');
			*/
			$(value).find('div.slide:visible').fadeOut('fast', function(){
				$(value).find('div.slide:eq('+slideNum+')').fadeIn('slow');
				$(value).find('.bar li').removeClass('on');
				$(value).find('.bar li:eq('+slideNum+')').addClass('on');
				
				var isOffers = $('.specialOffers .slideShow').length;
				
				if (isOffers > 0){
					//console.log('set nav to: ' + slideNum)
					$(value).parent('div').find('ul.tabs li a').removeClass('current');
					$(value).parent('div').find('ul.tabs li:eq('+slideNum+') a').addClass('current');
				}
				
				
			});
		}
	});
}

function bindShow(){
	$('.hero .slideShow .bar li').click(function(){
		clearInterval(showTimer);
		
		var slideNum = $('.hero .slideShow .bar li').index(this);
		changeSlide(slideNum);
	});
	
	var isOffers = $('.specialOffers .slideShow').length;
	
	if (isOffers > 0){
		$('.tabs.slideShow li a').click(function(e){
			clearInterval(showTimer);
		
			var slideNum = $('.tabs.slideShow li a').index(this);
			changeSlide(slideNum);
			
			e.preventDefault();
		});
		
	}
}


function setTabs(){
	var isTab = $('.tabs .pane').length;
	
	if (isTab > 0){
		var tabObj = $('.tabHead li');		
		var selTab = $('.tabHead li').index($('.on'));
		
		
		$('.tabs .pane').removeClass('on');
		
		if (selTab < 0){
			//select the first
			$('.tabHead li').eq(0).addClass('on');
			$('.tabs .pane').eq(0).addClass('on');
		}	else {
			$('tabHead li').eq(selTab).addClass('on');
			$('.tabs .pane').eq(selTab).addClass('on');
			
		}
		
		
		$('.tabHead li').click(function(){
			$('.tabHead li, .tabs .pane').removeClass('on');
			var selTab = $(this).index();
			$('.tabs .pane').eq(selTab).addClass('on');
			$(this).addClass('on');
			
			var isCarousel = $('.tabs .pane:eq('+selTab+') div.productDisplay').length;
			//alert(isCarousel)
			
			if (isCarousel > 0){
				//alert('prodddd')
				$(document).ready(function(){
					jQuery("#carousel-demo1").sliderkit({
						auto:false,
						shownavitems:5
					});
				});
			}
		});		
	}
}

