var sImgPath = "web/pix/";

/********************************************************************/
// text browser
/********************************************************************/
function browseText(direction) {
	var nTextParts = aTextParts.length;

	if (direction == "prev") {
		var nextPage = currentPage - 1;
		document.getElementById("arrRight").innerHTML = '<a href="#textTop" onclick="browseText(\'next\')" title="' + next + '"> &gt;</a>';
		if (nextPage <= 0) {
			document.getElementById("arrLeft").innerHTML = "&lt; ";
		}
		currentPage--;
	}
	else {
		var nextPage = currentPage + 1;
		document.getElementById("arrLeft").innerHTML = '<a href="#textTop" onclick="browseText(\'prev\')" title="' + prev + '">&lt; </a>';
		if ((nextPage+1) == nTextParts) {
			document.getElementById("arrRight").innerHTML = " &gt;";
		}
		currentPage++;
	}

	document.getElementById("textPart").innerHTML = aTextParts[nextPage];
	document.getElementById("pageCount").innerHTML = (nextPage + 1);
}


/********************************************************************/
// images
/********************************************************************/
function rotateImages ()
{
	var img1 = document.getElementById("image1");
	var img2 = document.getElementById("image2");
	var img3 = document.getElementById("image3");
	var caption1 = document.getElementById("caption1");
	var caption2 = document.getElementById("caption2");
	var caption3 = document.getElementById("caption3");

	if ( nextImg == aSlides.length )
	{
		nextImg = 0;
	}

	img1.src = img2.src;
	caption1.innerHTML = caption2.innerHTML;
	img2.src = img3.src;
	caption2.innerHTML = caption3.innerHTML;
	img3.src = aSlides[nextImg];
	caption3.innerHTML = aSlideTxt[nextImg];

	nextImg++;
}


/********************************************************************/
// slidable
/********************************************************************/

var initSlidables = (function() {
	var POS_SEPARATOR = "/";
	var marginSide = "marginLeft";

	var slideButtons = document.createElement("div");

	$(slideButtons).
		addClass("slidable-controls").
		append("<a href='#' rel='prev'/>").
		append(" ").
		append("<span>0</span>").
		append(" ").
		append("<a href='#' rel='next'/>");

	$(slideButtons).children(":first").
		text("Previous item").
		bind("click", function(event) {
			this.parentNode.slide(-1);
			event.preventDefault();

		});

	$(slideButtons).children(":last").
		text("Next item").
		bind("click", function(event) {
			this.parentNode.slide(1);
			event.preventDefault();
		});

	var initSlidables = function(slideElms) {
		slideElms.each(function() {
			var ul = $("> ul:first", this);
			var ulElm = ul.get(0);
			ulElm.currentPos = 0;

			var controls = $(slideButtons).clone(true);
			ul.after(controls);

			var controlDiv = controls.get(0);

			controlDiv.slide = function(direction /*: Number*/) {
				var max = (ul.children().length - 1);

				if (direction > 0 && ulElm.currentPos < max) {
					ulElm.currentPos += 1;
				}
				else if (direction < 0 && ulElm.currentPos > 0) {
					ulElm.currentPos -= 1;
				}

				var animParams = {};
				animParams[marginSide] = ulElm.currentPos * -100 + "%";
				ul.stop().animate(animParams);
				if (ulElm.currentPos >= max) {
					controls.find("[rel=next]").addClass("disabled");
				}
				else {
					controls.find("[rel=next]").removeClass("disabled");
				}

				if (ulElm.currentPos <= 0) {
					controls.find("[rel=prev]").addClass("disabled");
				}
				else {
					controls.find("[rel=prev]").removeClass("disabled");
				}

				var pos = controls.find("span:first").text([
					ulElm.currentPos + 1,
					ul.children().length
				].join(POS_SEPARATOR));

				if (pos.text() === [1, 1].join(POS_SEPARATOR)) {
					pos.addClass("disabled");
				}
			}
			controlDiv.slide();
		});
	}

	return initSlidables;
});


// address flash movie for external interface in action script
function thisMovie( movieName )
{
    if ( navigator.appName.indexOf("Microsoft") != -1 )
    {
        return window[movieName];
    }
    else
    {
        return document[movieName];
    }
}

var lightwinLink = null;

function SWFDelegate ( url, caption )
{
	if ( lightwinLink != null )
	{
		document.body.removeChild( lightwinLink );
	}

	var objLink = document.createElement( 'a' );
	objLink.setAttribute( 'href', url );
	objLink.setAttribute( 'params', 'lightwindow_width=694,lightwindow_height=565' );
	objLink.setAttribute( 'class', 'lightwindow page-options' );
	objLink.setAttribute( 'title', caption );

	document.body.appendChild( objLink );
	lightwinLink = objLink;

	myLightWindow._setupLinks();
	myLightWindow.activate( "", objLink );
}


function deselectGallery ()
{
	if ( document.getElementById( "flashVidGallery" ) )
	{
		thisMovie( "flashVidGallery" ).deselectGallery();
	}
}


/********************************************************************/
// general functions slideshow flash
/********************************************************************/
function writeFlashSlideshowBtns(slideshowDiv) {
	if (aSlidesThumb) {
		for (i=0; i<aSlidesThumb.length; i++) {
			newSrc = aSlidesThumb[i];
			if (i == 0) {
				document.write("<a href=\"javascript:flashShowImg(" + i + ", '" + slideshowDiv + "');\" onfocus=\"this.blur()\"><img src=\"" + dummyThumb + "\" id=\"slideBtn" + i + "\" alt=\"\" width=\"10\" height=\"10\" /></a>\n");
				activeBtn = eval("document.getElementById('slideBtn" + i + "')");
				activeSrc = newSrc;
			}
			else {
				document.write("<a href=\"javascript:flashShowImg(" + i + ", '" + slideshowDiv + "');\" onfocus=\"this.blur()\"><img src=\"" + newSrc + "\" id=\"slideBtn" + i + "\" alt=\"\" width=\"10\" height=\"10\" /></a>\n");
			}
		}
	}
}

function flashShowImg(imgIndex, slideshowDiv) {
	if (displayMode == "text") { swapDescription(false); }

	//oTag = '<object data="pix/slideshow_large.swf?sPix=' + aSlides[imgIndex] + '&amp;sTxt=' + aSlideTxt[imgIndex] + '&amp;btnId=' + imgIndex + '" type="application/x-shockwave-flash" width="100%" height="100%" id="slideshow_flash">';
	oTag = '<object data="pix/slideshow_products.swf?sPix=' + aSlides[imgIndex] + '&amp;btnId=' + imgIndex + '" type="application/x-shockwave-flash" width="100%" height="100%" id="slideshow_flash">';
	oTag += '<param name="allowscriptaccess" value="samedomain" />';
	//oTag += '<param name="movie" value="pix/slideshow_large.swf?sPix=' + aSlides[imgIndex] + '&amp;sTxt=' + aSlideTxt[imgIndex] + '&amp;btnId=' + imgIndex + '" />';
	oTag += '<param name="movie" value="pix/slideshow_products.swf?sPix=' + aSlides[imgIndex] + '&amp;btnId=' + imgIndex + '" />';
	oTag += '<param name="quality" value="high" />';
	oTag += '<param name="bgcolor" value="#323232" />';
	oTag += '<param name="scale" value="showall" />';
	oTag += '<param name="salign" value="tl" />';
	oTag += '<param name="menu" value="false" />';
	oTag += '<param name="wmode" value="opaque" />';
	oTag += '</object>';

	flashDiv = document.getElementById(slideshowDiv);
	flashDiv.innerHTML = oTag;
}

function swapBtnHighlight(linkId) {
	imgBtn = document.getElementById('slideBtn' + linkId);
	if (activeBtn) {
		activeBtn.src = activeSrc;
	}
	if (imgBtn) {
		activeBtn = imgBtn;
		activeSrc = imgBtn.src;
		imgBtn.src = dummyThumb;
	}
	//writeCaption(aSlideTxt[linkId]);
}


// Flash-Embed for IE
function embedFlash(oTag) { document.write(oTag); }
