var toggleSpeed = "fast";
var blue = "#3300ff";
var red = "#cc3333";
var black = "#000000";
var isTShirt = false;
var tShirt_NewAPNum = '';
var bSeeAllActive = false;
var CONST_CAROUSEL_NUM_ITEMS_VISIBLE = 2;
var carouselObjectArray = new Array();
var ci = 0;
var bIsZoomOpen = false;
var clickCount = 0;
$(document).ready(function(){
	
	formatMainImage();
	
	$('.RecentlyViewedInner ul li').css('color', blue);
	$('.RecentlyViewedInner ul li').css('text-decoration', 'underline');
	
	$('.sizeOptionBlock .sizePriceDetails').hide();
	$('.sizeOptionBlock .price .saveAmount').hide();
	$('.sizeOptionBlockSelected .sizeOptionBlockHolidayMsg').hide(); //Holiday code
	sizeOptionBlockSelected_price_bold = $('.sizeOptionBlockSelected .price .bold');
	sizeOptionBlockSelected_price_bold.addClass('size');
	sizeOptionBlockSelected_price_bold.addClass('txtRed');
	
	$('.sizeOptionBlock').live("click", function() {
												 
		if ($(this).parent().hasClass('tShirtContainer')  )
		{
			isTShirt = true;
			$('#tShirtError').hide();
			
		}
		
		/*
		sizeOptionBlockSelected = $('#sizeTypeContainer').find('.sizeOptionBlockSelected');
		sizeOptionBlockSelected_Price = sizeOptionBlockSelected.find('div.price');
		sizeOptionBlockSelected_Price_Bold = sizeOptionBlockSelected_Price.find('div.bold');
		sizeOptionBlockSelected_Price_saveAmount = sizeOptionBlockSelected_Price.find('div.saveAmount');
		sizeOptionBlockSelected_Details_Bold = sizeOptionBlockSelected.find('div.details div.bold');
		sizeOptionBlockSelected_sizePriceDetails = sizeOptionBlockSelected.find('div.sizePriceDetails');
		
		
		sizeOptionBlockSelected_sizePriceDetails.toggle(toggleSpeed);
		sizeOptionBlockSelected_Price_saveAmount.toggle();
		sizeOptionBlockSelected_Price_Bold.removeClass('size');
		sizeOptionBlockSelected_Price_Bold.css('color', black);
		sizeOptionBlockSelected_Details_Bold.removeClass('size');
		sizeOptionBlockSelected.addClass('sizeOptionBlock').removeClass('sizeOptionBlockSelected');
		$(this).removeClass('sizeOptionBlock');
		$(this).addClass('sizeOptionBlockSelected');
		sizeOptionBlockSelected_Price_Bold.addClass('size');
		sizeOptionBlockSelected_Price_Bold.css('color', red);
		sizeOptionBlockSelected_Details_Bold.addClass('size');
		sizeOptionBlockSelected_sizePriceDetails.toggle(toggleSpeed);
		sizeOptionBlockSelected_Price_saveAmount.toggle();
		*/
		
		
		$(".sizeOptionBlockSelected .sizePriceDetails").toggle(toggleSpeed);
		$(".sizeOptionBlockSelected .price .saveAmount").toggle();
		$(".sizeOptionBlockSelected .price .bold").removeClass('size');
		$(".sizeOptionBlockSelected .price .bold").css('color', black);
		$(".sizeOptionBlockSelected .details .bold").removeClass('size');
		$(".sizeOptionBlockSelected").addClass('sizeOptionBlock').removeClass('sizeOptionBlockSelected');
		$(this).removeClass("sizeOptionBlock");
		$(this).addClass("sizeOptionBlockSelected");
		$(".sizeOptionBlockSelected .price .bold").addClass('size');
		$(".sizeOptionBlockSelected .price .bold").css('color', red);
		$(".sizeOptionBlockSelected .details .bold").addClass('size');
		$(".sizeOptionBlockSelected .sizePriceDetails").toggle(toggleSpeed);
		$(".sizeOptionBlockSelected .price .saveAmount").toggle();
		
		//ajax
		if (! isTShirt){
			var selectedAPNum = $(this).find('.apnum').text();
			theURL = location.href;
				var theURLCopy = theURL.toLowerCase();
				newString = 'apnum=' + selectedAPNum;
				var loc1 = theURLCopy.indexOf('apnum=');
				if (loc1 > 0)
					var loc2 = theURL.indexOf('&',loc1);
				else
				{
					newString = '_i' + selectedAPNum;
					loc1 = theURLCopy.indexOf('_i');
					var loc2 = theURL.indexOf('_',loc1+1);
				}
				var sub1 = theURL.substring(loc1,loc2);
				theURL = theURL.replace(sub1,newString);
				window.location = theURL;
		}
		else
		{
			tShirt_NewAPNum = $(this).attr('id');
    		$('.sizeOptionBlockSelected .sizeOptionBlockHolidayMsg').hide(); //Holiday code
			$('.sizeOptionBlock .sizeOptionBlockHolidayMsg').show(); //Holiday code	
		}
	})
	
	$(".sizeOptionBlock").live("mouseover", function() {
		$('> * .bold', this).css('color', red);	
	});
	
	$(".sizeOptionBlock").live("mouseout", function() {
		$('> * .bold', this).css('color', black);											
	});
	
	$(".sizeOptionBlockSelected").live("mouseover", function() {
		$('> .details .bold', this).css('color', black);										
	});
	
	$(".sizeOptionBlockSelected").live("mouseout", function() {
		$('> .details .bold', this).css('color', black);										
	});
	
	
	 $('#ArtistName').hover(
      function () {
        $(this).css('text-decoration','underline');
      }, 
      function () {
        $(this).css('text-decoration','none');
      }
    );

	//hide secondary actions block if no content below it
	$("#ServiceAndShareContainer .secondaryActions").each(function(i){								 
		var x = $(this).find("li").length;	
		if (x == 0)
			$(this).hide();
	});
	
	var x = $("#ProductContent").find("p").length;
	if (x == 0 )
		$("#ProductContentContainer").hide();
	
	$("#AddToCart").hover(function() {
		$("#AddToCart, #AddToCart *").each(function(i){
			var str = $(this).css('backgroundImage');
			str = str.replace(/.gif/i, '_hover.gif');
			$(this).css('backgroundImage', str);
		});
	}, function(){
		$("#AddToCart, #AddToCart *").each(function(i){
			var str = $(this).css('backgroundImage');
			str = str.replace(/_hover.gif/i, '.gif');
			$(this).css('backgroundImage', str);
		});
	});
	
	 /* Changes Done for ASAP -APC Custom  Frame It Button */

    $("#cf_FrameContainerPortrait").hover(function() {
        $("#cf_FrameContainerPortrait, #cf_FrameContainerPortrait *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/1.png/i, '2.png');
            $(this).css('backgroundImage', str);
        });
    }, function() {
        $("#cf_FrameContainerPortrait, #cf_FrameContainerPortrait *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/2.png/i, '1.png');
            $(this).css('backgroundImage', str);
        });
    });

    $("#cf_FrameContainerLandscape").hover(function() {
        $("#cf_FrameContainerLandscape, #cf_FrameContainerLandscape *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/1.png/i, '2.png');
            $(this).css('backgroundImage', str);
        });
    }, function() {
        $("#cf_FrameContainerLandscape, #cf_FrameContainerLandscape *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/2.png/i, '1.png');
            $(this).css('backgroundImage', str);
        });
    });


    $("#CustomFrame").hover(function() {
        $("#CustomFrame, #CustomFrame *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/.gif/i, '_hover.gif');
            $(this).css('backgroundImage', str);
        });
    }, function() {
        $("#CustomFrame, #CustomFrame *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/_hover.gif/i, '.gif');
            $(this).css('backgroundImage', str);
        });
    });

    $("#CustomFrameInModule").hover(function() {
        $("#CustomFrameInModule, #CustomFrameInModule *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/.gif/i, '_hover.gif');
            $(this).css('backgroundImage', str);
        });
    }, function() {
        $("#CustomFrameInModule, #CustomFrameInModule *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/_hover.gif/i, '.gif');
            $(this).css('backgroundImage', str);
        });
    });
/* END OF: Changes Done for ASAP -APC Custom  Frame It Button */
	
	//hide all contentBoxes that aren't first
	$('.contentBox + .contentBox').hide();
	
	
	//legacy add to favorites code positioning
	//add to favorites is in getPosterNew.asp
	var favoritesLi = $('#Favorites');
	var saveFavoritesObj = $('#saveFavoritesContent').find('#add_to_gallery').parent();
	if (saveFavoritesObj.length == 0)
		var saveFavoritesObj = $('#saveFavoritesContent').find('#add_item').parent();
	var saveFavoritesContents = saveFavoritesObj.html();
	//var saveFavoritesOnClick = saveFavoritesObj.attr('onclick');
	favoritesLi.html(saveFavoritesContents);
	favoritesLi.click(function () { 
      saveFavoritesObj.click();
    });
	
	
	//tab wrapping
	//for each set of tabs in contentBoxHeaderTab
	
	$('div.contentBoxHeaderTab').each(function(i){
		var setOfChildTabs, firstItem, secondItem;
		setOfChildTabs = $(this).find('li');
		containerWidth = $(this).width();
		containerWidth = containerWidth - 30;
		
		firstItem = setOfChildTabs[0];
		secondItem = setOfChildTabs[1];
		
		firstItemWidth = $(firstItem).width();
		secondItemWidth = $(secondItem).width();
		firstItemHeight = $(firstItem).height();
		secondItemHeight = $(secondItem).height();
		
		
		if (firstItemWidth + secondItemWidth > containerWidth)
		{
			if (firstItemWidth < containerWidth/2)
				$(secondItem).css('width',containerWidth-firstItemWidth-20);
			else if (secondItemWidth < containerWidth/2)
				$(firstItem).css('width',containerWidth-secondItemWidth-20);
			else{
					$(firstItem).css('width',containerWidth/2 - 10);
					$(secondItem).css('width',containerWidth/2 - 10);
			}
				
			firstItemHeight = $(firstItem).height();
			secondItemHeight = $(secondItem).height();
		}
		
		if (firstItemHeight > secondItemHeight){
			$(secondItem).height(firstItemHeight);
		}
		else if (secondItemHeight > firstItemHeight){
			$(firstItem).height(secondItemHeight);
		}
	});
	
	$(".contentBoxHeaderTab li.tabDefault").live("click", function() {
		var parentContainer = $(this).parents(".contentBoxOuter");
		var tabIndex = $(parentContainer).find('.contentBoxHeaderTab li').index(this);
		$(this).siblings('li').removeClass('tabSelected').addClass('tabDefault');
		$(this).removeClass('tabDefault').addClass('tabSelected');
		$(this).css('color',black);
		var parentContainer = $(this).parents(".contentBoxOuter");
		$(parentContainer).find("div.contentBox").hide();
		$(parentContainer).find("div.contentBox:eq("+tabIndex+")").fadeIn('normal');
		var i = 0;
		var j = 0;
		if (bSeeAllActive)
			j = 1;
		for (i=j;i<ci;i++)
			carouselObjectArray[i].reload();
	});
	
	$(".contentBoxHeaderTab li.tabDefault").live("mouseover", function() {
		$(this).css('color',red);															   
	});
	$(".contentBoxHeaderTab li").mouseout(function() {
		$(this).css('color',black);															   
	});	
	
	$(".slidingModule").each(function(i){
		var thisCarousel = $(this);
		//ie fix: make each li element the same height as the tallest element\
		//loop through all li elements, note tallest
		var thisHeight;
		var theTallest = 0;
		$(this).find("li div.equalHeight").each(function(i){								 
			thisHeight = $(this).height();
			//alert('thisheight ' + thisHeight);
			if (thisHeight > theTallest){
				theTallest = thisHeight + 4;
				//alert('tallest ' + theTallest);
			}
			
		});
		//alert(theTallest);
		$(this).find("li div.equalHeight").each(function(i){								 
			$(this).css('height',theTallest);
		});
		
		$(this).jcarousel({
		scroll: getWidthOfCarousel(thisCarousel),
		initCallback: mycarousel_initCallback,
		itemFirstInCallback: mycarousel_itemFirstInCallback,			
		wrap: "both",
		size:getNumberOfCarouselItems(thisCarousel),
		visible: getWidthOfCarousel(thisCarousel),
		itemVisibleOutCallback: mycarousel_loadImages
		});
	});

	$('.vAlign').vAlign();
	
	$(".jcarousel-next-horizontal").mouseover(function(){
		$(this).addClass("jcarousel-next-horizontal-hover");
		}).mouseout(function(){
		$(this).removeClass("jcarousel-next-horizontal-hover");		
	});
	
	$(".jcarousel-prev-horizontal").mouseover(function(){
		$(this).addClass("jcarousel-prev-horizontal-hover");
		}).mouseout(function(){
		$(this).removeClass("jcarousel-prev-horizontal-hover");		
	});
	
	$('.link, .standardLink, .standardLinkNoUnderline, #add_to_gallery, #add_item').live('mouseover', function() {
		$(this).css('color',red);
		$(this).css('text-decoration','underline');		
	});
	$('.link').bind('mouseout', function() {
		$(this).css('color',black);
		$(this).css('text-decoration','none');		
	});
	
	$('.standardLink').live('mouseout', function() {
		$(this).css('color',blue);
		$(this).css('text-decoration','underline');		
	});
	
	$('.standardLinkNoUnderline, #add_to_gallery, #add_item').live('mouseout', function() {
		$(this).css('color',blue);
		$(this).css('text-decoration','none');		
	});
	
	$('.codeBox').bind('click', function() {
		this.focus();
		this.select();
	});
	
	$('.blogHeader').hover(function() {
		$(this).css('color', red);
		$(this).css('text-decoration', 'underline');
		}, function(){
			$(this).css('color', '#768193');
			$(this).css('text-decoration', 'none');
	});
	
	$('.blogHeader, .closeBlog').click(function () {
		$('.blogContentBox').toggle();
	});

	$(document).bind('click', function(e) {
		if (bIsZoomOpen){
			if (clickCount > 0){
				$('.hiResView').click();
				bIsZoomOpen = false;
				clickCount = 0;
			}
			else
				clickCount = 1;
		}
	});
	
	$('.enlarge, .hasZoom').live('click', function() {
		
		buildEnlargeImage();
	});
	
	$('.hiResView').live('click', function() {
		$(this).hide();
		bIsZoomOpen = false;
		clickCount = 0;
	});
	
	var contentBoxSets = $('.contentBoxSets');
	var setSize = contentBoxSets.attr('id');
	$('.setSize').append(setSize);
	if (setSize > 2) //set height to the height of the first two items
		contentBoxSets.addClass('contentBoxSetsHeight');	
	$('.seeSetDetails').bind('click', function() {
		var offset = $('.contentBoxSets').offset();
		var scrollAmount = offset.top - 20;
		$(document).scrollTop(scrollAmount);
	});
	
	//t-shirt logic
	
	//if item is already in cart then select it
	var tShirt_selectedAPNum = '';
	tShirt_selectedAPNum = $('#tShirtSelectedAPNum').text(); //this is only set if iid <> ''
	if (tShirt_selectedAPNum != '')
	{
		tShirt_selectedOption = '#' + tShirt_selectedAPNum + ':visible';
		$(tShirt_selectedOption).click();
	}
	
	
	$('select#tColor').change(function () {
			var currentColor = $('select#tColor option:selected').attr('value');
			var currentColorDiv = '#' + currentColor;
			sizeOptionBlock = $('.sizeOptionBlock');
			
			sizeOptionBlock.hide();
			if (tShirt_NewAPNum != '') //a size has been selected
			{
				var currentSelectedTShirt = '#' + tShirt_NewAPNum;
				$(currentSelectedTShirt).removeClass('sizeOptionBlockSelected');
				$(currentSelectedTShirt).addClass('sizeOptionBlock');
				$(currentSelectedTShirt).find('.sizePriceDetails').hide();
				$(currentSelectedTShirt).find('.saveAmount').hide();
				$(currentSelectedTShirt).hide();
				tShirt_NewAPNum = '';
				
			}
			sizeOptionBlock.each(function(i){
				
				if ( $(this).hasClass(currentColor) )
					$(this).show();
			});
	
			newImageURL = $(currentColorDiv).text();
			newImageURLs = newImageURL.split('@');
			$('#mainImage').attr('src',newImageURLs[0]);
			$('#hiResHref').text(newImageURLs[1]);
			

	});
	
	$('#scrollControlSeeAllID').live("click", function() {
		notifyTealeaf('see_all_link');
	});
	
	$('#customFramingTab').bind('click', function() {
		notifyTealeaf('custom_framing_tab');
	});
	
	$('.jcarousel-prev').bind('click', function() {
		arrowClickCount = $(this).data('arrowClickCount');
		if (arrowClickCount != parseInt(arrowClickCount))
			arrowClickCount = 1;
		else
			arrowClickCount  = arrowClickCount+1;
		$(this).data('arrowClickCount', arrowClickCount);
		notifyTealeaf('left_arrow_'+arrowClickCount);	
	});
	
	$('.jcarousel-next').bind('click', function() {
		arrowClickCount  = $(this).data('arrowClickCount');
		if (arrowClickCount != parseInt(arrowClickCount))
			arrowClickCount = 1;
		else
			arrowClickCount = arrowClickCount+1;
		$(this).data('arrowClickCount', arrowClickCount);
		notifyTealeaf('right_arrow_'+arrowClickCount);	
	});
	
	$('#items_DesignerRec li, #items_Sets li').bind('click', function() {
		notifyTealeaf('upsell_item');
	});
	
	
	$('#itemNotAvailable .SectionTable').width('395px');
	var $popupContainer = $('#inPageFS');
	var gCloseText = 'close';
         $popupContainer.dialog({ modal: true, autoOpen:false, width:'900'});
	$popupContainer.dialog('option', 'height', '725');
	$popupContainer.dialog('option', 'title', gCloseText);
	$popupContainer.dialog('option', 'position', ['center','top']);
	$popupContainer.dialog('open');
	$('.ui-widget').css('margin-top','10px');
	$('.ui-dialog-content').css("min-height", "0");
	$('.ui-widget').css('height','725px');
	$('.ui-dialog-titlebar').live('click',function(){
		$('#inPageFS').dialog( 'close' );
	});
	
});



function formatMainImage()
{
	var iw = $("#mainImage").attr('width');
	var cw = $("#MainImageContainer").width();
	var mw = (cw - iw)/2 + 5;
	var mainImageContainer = $("#MainImageContainer");
	mainImageContainer.css('margin-left',mw);
	mainImageContainer.css('width','');
	
	
	if ( $('#dleIcon').length == 0)
		$('.enlarge').css('width',(iw/2)+28);
	else {		
		var newEnlargePosition = $('#A1').position().left;
		$('.enlarge').css('position','absolute');
		$('.enlarge').css('left',newEnlargePosition);
		$('.enlarge').css('width','100px');
	}
}

(function ($) {
// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	$(this).css('margin-top', mh);
	});
};
})(jQuery);

function buildEnlargeImage()
{
	//get Image src and image size
	var imageSrc = $("#hiResHref").text();
	var hw = $("#hiResHref").attr('className');
	var aHeightWidth = hw.split("_");
	var theHeight = aHeightWidth[0];
	var theWidth = aHeightWidth[1];
	//add background image to imageContainer
	$('.hiResImageContainer').css('background-image','url('+imageSrc+')');
	//set width of imageContainer
	$('.hiResImageContainer').css('height',theHeight);
	$('.hiResImageContainer').css('width',theWidth);
	$('.hiResView').show();
	bIsZoomOpen = true;
}

function linkForm(action)
{
	document.getElementById('globalLinkForm').action = action;
	document.getElementById('globalLinkForm').submit();
}

function newWindow(action, name, width, height)
{
	var newWin = window.open(action,name,'width=' + width + ',height=' + height + ',status=no,toolbar=no,scrollbars=yes,resizable=yes,left=1,top=1');
}

function addToCart(action, thisObject)
{
	if ($(thisObject).hasClass('tShirtAddToCart'))
	{
		if (tShirt_NewAPNum != '')
			action = replaceAPNumInURL(action, tShirt_NewAPNum);
		else{
			$('#tShirtError').fadeOut('fast');
			$('#tShirtError').fadeIn('normal');
			return false;
		}
	}
	linkForm(action);
}

function replaceAPNumInURL(theURL, selectedAPNum)
{
	var theNewURL = '';
	var theURLCopy = theURL.toLowerCase();
	var newString = 'apnum=' + selectedAPNum;
	var loc1 = theURLCopy.indexOf('apnum=');
	var loc2 = theURL.indexOf('&',loc1);
	var sub1 = theURL.substring(loc1,loc2);
	theNewURL = theURL.replace(sub1,newString);
	return theNewURL;		
}

function taf(localCID, lAPNum) { 
	winPop = window.open("/taf.asp?CID="+localCID + "&apnum="+lAPNum,"TellAFriend",'status=no,toolbar=no,scrollbars=no,resizable=no,width=400,height=400,left=1,top=1')
	if (window.focus) 
		 winPop.focus()
}

function mycarousel_initCallback(carousel) {
	carouselObjectArray[ci] = carousel;
	ci = ci+1;
	var currentDiv;
	var carouselContainer = '#' + carousel.container[0].id;
	var paginationID = $(carouselContainer).find('div.jcarousel-control').attr('id');
	var paginationContainer = '#' + paginationID;
	var numItemsVisible = carousel.options.scroll;
	//create pagination: get all li elements and build squares
	var n = $(carouselContainer).find('ul.jcarousel-list li').length;
	//add dummy items to create equal # of items on all pages
	var nCount = n;
	var numPages = n / numItemsVisible;
	numPages = Math.ceil(numPages);
	var numDummyItems = (numPages * numItemsVisible) - n;
	for (i=0;i<numDummyItems;i++){
			carousel.add(nCount+1, "");
			nCount = nCount+1;
	}	
	var j = 1;
	i=0;
	var textToAppend = '';
	for (i=0;i<numPages;i++){
		divName = j + '_' + paginationID;
		//currentDiv = $('#'+divName);
		pageNumber = i+1;
		textToAppend = textToAppend + '<div thePage="'+j+'" id="'+divName+'" title="page '+pageNumber +'" class="scrollControl scrollControlInactive"></div>';
		//currentDiv.data('pagination', j);
		
		//currentDiv.attr('title','page ' + pageNumber);
		j = j + numItemsVisible;
	}
	if ( $(carouselContainer).hasClass('addSeeAllOption') ){
		textToAppend = textToAppend + '<div id="scrollControlSeeAllID" class="scrollControlSeeAll floatLeft link">';
		seeAllTextStr = $('#seeAllText').text();	
		textToAppend = textToAppend + seeAllTextStr + ' ('+n+')</div><div class="clear"></div>';
	}
	
	if (textToAppend.length)
		$(paginationContainer).append(textToAppend);
	
	if (numPages == 1) //there is only one page so don't show arrows or pagination
		carouselShowAll(carouselContainer,paginationContainer);
	
	$(carouselContainer).find('div.jcarousel-control div.scrollControlSeeAll').bind('click', function() {
		carouselShowAll(carouselContainer,paginationContainer);
	});
	
	$(carouselContainer).find('div.jcarousel-control div.scrollControl').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('thePage')));
	});
};
		
function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
	var numItemsVisible = carousel.options.scroll;
	var activeBoxID = idx;
	if  ((activeBoxID % numItemsVisible == 0) && numItemsVisible > 1)
		activeBoxID = ++activeBoxID;
	globalActiveBoxID = activeBoxID;
	
	var carouselContainer = '#' + carousel.container[0].id;
	var carouselControl = $(carouselContainer).find('div.jcarousel-control');
	var paginationID = carouselControl.attr('id');
	var theDiv = activeBoxID + '_' + paginationID; //for example, 1_carouselPage-designer
	var currentBlock = carouselControl.find('#'+theDiv);
	var allOthers = carouselControl.find('div.scrollControl').not(currentBlock);
	allOthers.removeClass('scrollControlActive').removeClass('scrollControlActive-hover').addClass('scrollControlInactive');
	currentBlock.removeClass('scrollControlInactive').removeClass('scrollControlInactive-hover').addClass('scrollControlActive');
	allOthers.mouseover(function(){
		$(this).removeClass("scrollControlActive-hover").addClass("scrollControlInactive-hover");
		}).mouseout(function(){
		$(this).removeClass("scrollControlInactive-hover");		
	});
	currentBlock.mouseover(function(){
		$(this).removeClass("scrollControlInactive-hover").addClass("scrollControlActive-hover");
		}).mouseout(function(){
		$(this).removeClass("scrollControlActive-hover");		
	});	
	/*if (state != 'init'){
		notifyTealeaf(state + '_arrow_click_' + idx);	
	}*/
};
		
function mycarousel_loadImages(carousel, item, idx, state){
	
	var listID = '#' + carousel.list[0].id;
	if ($(listID).data('imagesLoaded') != 'yes'){
		var nextImages = $(listID).find('li * img');
		nextImages.each(function(i){
			var theSRC = '';
			theSRC = $(this).attr('src');
			if (theSRC == '' || theSRC == undefined)
				$(this).attr('src', $(this).attr('id'));
				$(this).css('visibility','visible');
		});
		//alert('images now loaded');
		$(listID).data('imagesLoaded', 'yes');
	}			
};
		
function carouselShowAll(carouselContainer,paginationContainer){
	$(carouselContainer).find(".jcarousel-clip").css('max-height','none');
	$(carouselContainer).find(".jcarousel-clip").css('overflow','visible');
	
	$(carouselContainer).find(".jcarousel-clip").attr({ 
		style: "#margin-left:5px;#margin-right:5px;#width:400px;"
	});
	
	$(carouselContainer).find(".jcarousel-list").attr({ 
		style: "width:366px; left:0;#width:400px;"
	});
	$(carouselContainer).find(".jcarousel-prev").hide();
	$(carouselContainer).find(".jcarousel-next").hide();
	$(paginationContainer).hide();
	mycarousel_loadImages(carouselObjectArray[0], '','','');
	bSeeAllActive = true;
}

function getNumberOfCarouselItems(carousel){ 
	var numItems = 0;
	var numItemsVisible = getWidthOfCarousel(carousel);
	var n = $(carousel).find("li").length;
	var numPages = n / numItemsVisible;
	numPages = Math.ceil(numPages);
	var numItems = (numPages * numItemsVisible);
	return numItems;
}
			
function getWidthOfCarousel(carousel){
	var numItems = 2;
	if ( $(carousel).hasClass("threeItems") )
		numItems = 3;
	else if ( $(carousel).hasClass("oneItem") )
		numItems = 1;
	return numItems;
}

function notifyTealeaf(actionName)
{
	var sendString;
	sendString = "elementID=productPage&theAction=" + actionName;
	$.get("/tealeaf/notify.asp", { elementID: "productPage", theAction: actionName } );
}