
/************************************************************************************************
*****************                   INITIALIZATION & SETTINGS                   *****************
************************************************************************************************/

// check navigator type
ie4 = (document.all) ? true : false
ns4 = (document.layers) ? true : false
ns7 = ((document.getElementById) && (navigator.userAgent.indexOf("Netscape") != -1)) ? true : false
op7 = ((document.getElementById) && (navigator.userAgent.indexOf("Opera") != -1)) ? true : false
fx1 = ((document.getElementById) && (navigator.userAgent.indexOf("Firefox") != -1)) ? true : false
mz1 = ((document.getElementById) && (navigator.userAgent.indexOf("Gecko") != -1) && !ns7 && !op7 && !fx1) ? true : false

if (ns4) window.location.href = "error.htm"
if (fx1) ns7 = true
if (mz1) ns7 = true

// check correct frameset loading
//framesetURL = "content.htm"
framesetURL = ""
welcomeURL = "default.htm"
popupURL = "popup.htm"
selfURL = location.href.substr(location.href.lastIndexOf("/") + 1)

if ((selfURL) && (selfURL != framesetURL) && (selfURL != welcomeURL) && (selfURL != popupURL) && (self.name == top.name))
	location.href = welcomeURL

// release focus after clicking
function blurFocus() {
	if (window.event.srcElement.className != "field")
		document.activeElement.blur()
}

// allow context menu only for downloadable items
function checkContextMenu() {
	blurFocus()
	if (window.event.srcElement.className != "downloadable")
		return false
}

// check for item visibility in low resolution mode
if ((screen.availWidth < 1024) && (selfURL == welcomeURL || !selfURL)) alert("Best viewed in 1024x768!")

function checkLowRes(srcElement) {
	if (screen.availWidth < 1024 && srcElement.src.indexOf("_LoRe.jpg") == -1)
		srcElement.src = srcElement.src.substr(0, srcElement.src.length - 4) + "_LoRe.jpg"
}

// popup window handler
bPopDisabled = true
iPopWidth = 317
iPopHeight = 437

document.onclick = blurFocus
document.oncontextmenu = checkContextMenu


/************************************************************************************************
*****************                         FADER EFFECT                          *****************
************************************************************************************************/


/* object - source element that fired the event (implicit, not to be passed)
 * destOp - destination transparency level (ie 80, for mostly solid)
 * rate   - time in milliseconds between trasparency changes (best under 100)
 * delta  - amount of change each time (ie 5, for 5% change in transparency)
 */


nereidFadeObjects = new Object()
nereidFadeTimers = new Object()

function nereidFade(object, destOp, rate, delta) {
	if (ie4) {
		if (!object)
			object = event.srcElement
		clearTimeout(nereidFadeTimers[object.sourceIndex])
		diff = destOp - object.filters.alpha.opacity
		direction = 1
		if (object.filters.alpha.opacity > destOp)
			direction = -1
		delta = Math.min(direction * diff, delta)
		object.filters.alpha.opacity += direction * delta
		if (object.filters.alpha.opacity != destOp) {
			nereidFadeObjects[object.sourceIndex] = object
			nereidFadeTimers[object.sourceIndex] =  setTimeout("nereidFade(nereidFadeObjects[" + object.sourceIndex + "]," + destOp + "," + rate + "," + delta + ")", rate)
		}
	}
}


/************************************************************************************************
*****************                       LANGUAGE HANDLER                        *****************
************************************************************************************************/


function getLanguage() {
	LANG = (getCookie("LANG")) ? getCookie("LANG") : ENG
}

function setLanguage(langValue) {
	setCookie("LANG", langValue)
	parent.location.reload()
}


/************************************************************************************************
*****************                        COOKIES HANDLER                        *****************
************************************************************************************************/


function getCookieValue(endPos) {
	endStr = document.cookie.indexOf(";", endPos)
    if (endStr == -1)
   		endStr = document.cookie.length
	return unescape(document.cookie.substring(endPos, endStr))
}

function getCookie(cookieName) {
	cookieName += "="
	cookieNameLen = cookieName.length
	cookieLen = document.cookie.length
	i = 0
	while (i < cookieLen) {
		j = i + cookieNameLen
		if (document.cookie.substring(i, j) == cookieName)
			return getCookieValue(j)
		i = document.cookie.indexOf(" ", i) + 1
		if (i == 0)
			break
	}
	return null
}

function setCookie(cookieName, cookieValue) {
	expireDate = new Date()
	expireDate.setTime(expireDate.getTime() + (24 * 60 * 60 * 1000 * 365))
	appPath = "/"
	document.cookie = cookieName + "=" + escape(cookieValue) + "; expires=" + expireDate.toGMTString() + "; path=" + appPath
}


/************************************************************************************************
*****************                        PIXELATE EFFECT                        *****************
************************************************************************************************/


function transStart() {
	if (ie4) {
		if (event.srcElement.filters[0]) {
			event.srcElement.filters[0].apply()
			event.srcElement.filters[0].play()
		}
	}
}


/************************************************************************************************
*****************                         SCROLL EFFECT                         *****************
************************************************************************************************/


/* scroller_width  - width of scroller box
 * scroller_height - height of scroller box
 * bgcolor         - background color of scroller box
 * border_color    - border color of scroller box
 * pause           - time between each news (in milliseconds)
 * degree          - speed of news rising
 * opacity         - amount of news fading (from 0 to 10)
 * padding         - distance between border of scroller box and text
 */
 
 
scroller_width = 120
scroller_height = 120
bgcolor = "#000000"
border_color = "#FFFFFF"
pause = 10000
degree = 10
opacity = 4
padding = 5

scrollercontentSx = scrollercontentDx = null
curcanvasSx = curcanvasDx = null
nextcanvasSx = nextcanvasDx = null
curindexSx = curindexDx = 0
nextindexSx = nextindexDx = 1
curposSx = curposDx = scroller_height * (1)
crossobjSx = crossobjDx = null
tempobjSx = tempobjDx = null
dropslideSx = dropslideDx = null

function moveSlide(side) {
	if (side == "Sx") {
		if (curposSx > 0) {
			curposSx = Math.max(curposSx - degree, 0)
			tempobjSx.style.top = curposSx
		}
		else {
			clearInterval(dropslideSx)
			if (crossobjSx.filters)
				crossobjSx.filters.alpha.opacity = 100
			else if (crossobjSx.style.MozOpacity)
				crossobjSx.style.MozOpacity = 1
			nextcanvasSx = (curcanvasSx == "canvas0Sx") ? "canvas0Sx" : "canvas1Sx"
			tempobjSx = ie4 ? eval("document.all." + nextcanvasSx) : document.getElementById(nextcanvasSx)
			tempobjSx.innerHTML = scrollercontentSx[curindexSx]
			nextindexSx = (nextindexSx < scrollercontentSx.length - 1) ? nextindexSx + 1 : 0
			setTimeout("rotateSlide('" + side + "')", pause)
		}
	}
	else {
		if (curposDx > 0) {
			curposDx = Math.max(curposDx - degree, 0)
			tempobjDx.style.top = curposDx
		}
		else {
			clearInterval(dropslideDx)
			if (crossobjDx.filters)
				crossobjDx.filters.alpha.opacity = 100
			else if (crossobjDx.style.MozOpacity)
				crossobjDx.style.MozOpacity = 1
			nextcanvasDx = (curcanvasDx == "canvas0Dx") ? "canvas0Dx" : "canvas1Dx"
			tempobjDx = ie4 ? eval("document.all." + nextcanvasDx) : document.getElementById(nextcanvasDx)
			tempobjDx.innerHTML = scrollercontentDx[curindexDx]
			nextindexDx = (nextindexDx < scrollercontentDx.length - 1) ? nextindexDx + 1 : 0
			setTimeout("rotateSlide('" + side + "')", pause)
		}	
	}
}

function rotateSlide(side) {
	if (side == "Sx") {
		if (ie4 || ns7) {
			resetIt(curcanvasSx, side)
			crossobjSx = tempobjSx = ie4 ? eval("document.all." + curcanvasSx) : document.getElementById(curcanvasSx)
			crossobjSx.style.zIndex ++
			if (crossobjSx.filters)
				document.all.canvas0Sx.filters.alpha.opacity = document.all.canvas1Sx.filters.alpha.opacity = eval(opacity + "0")
			else if (crossobjSx.style.MozOpacity)
				document.getElementById("canvas0Sx").style.MozOpacity = document.getElementById("canvas1Sx").style.MozOpacity = eval("0." + opacity)
			dropslideSx = setInterval("moveSlide('" + side + "')", 50)
			curcanvasSx = (curcanvasSx == "canvas0Sx") ? "canvas1Sx" : "canvas0Sx"
		}
		else {
			crossobjSx.document.write(scrollercontentSx[curindexSx])
			crossobjSx.document.close()
		}
		curindexSx = (curindexSx < scrollercontentSx.length - 1) ? curindexSx + 1 : 0
	}
	else {
		if (ie4 || ns7) {
			resetIt(curcanvasDx)
			crossobjDx = tempobjDx = ie4 ? eval("document.all." + curcanvasDx) : document.getElementById(curcanvasDx)
			crossobjDx.style.zIndex ++
			if (crossobjDx.filters)
				document.all.canvas0Dx.filters.alpha.opacity = document.all.canvas1Dx.filters.alpha.opacity = eval(opacity + "0")
			else if (crossobjDx.style.MozOpacity)
				document.getElementById("canvas0Dx").style.MozOpacity = document.getElementById("canvas1Dx").style.MozOpacity = eval("0." + opacity)
			dropslideDx = setInterval("moveSlide('" + side + "')", 50)
			curcanvasDx = (curcanvasDx == "canvas0Dx") ? "canvas1Dx" : "canvas0Dx"
		}
		else {
			crossobjDx.document.write(scrollercontentDx[curindexDx])
			crossobjDx.document.close()
		}
		curindexDx = (curindexDx < scrollercontentDx.length - 1) ? curindexDx + 1 : 0	
	}
}

function resetIt(curcanvas, side) {
	if (side == "Sx") {
		curposSx = parseInt(scroller_height) * (1)
		crossobjSx = ie4 ? eval("document.all." + curcanvas) : document.getElementById(curcanvas)
		crossobjSx.style.top = curposSx
		crossobjSx.style.display = "inline"
	}
	else {
		curposDx = parseInt(scroller_height) * (1)
		crossobjDx = ie4 ? eval("document.all." + curcanvas) : document.getElementById(curcanvas)
		crossobjDx.style.top = curposDx
		crossobjDx.style.display = "inline"
	}
}

function startScroller(side) {	
	if (side == "Sx") {
		curcanvasSx = "canvas0Sx"
		crossobjSx = ie4 ? document.all.canvas0Sx : ns7 ? document.getElementById("canvas0Sx") : ns4 ? document.canvas0Sx.document.canvas1Sx : null
		if (ie4 || ns7) {
			crossobjSx.innerHTML = scrollercontentSx[curindexSx]
			rotateSlide(side)
		}
		else if (ns4) {
			document.canvas0Sx.visibility = "show"
			curindexSx ++
			setInterval("rotateSlide('" + side + "')", pause)
		}
	}
	else {
		curcanvasDx = "canvas0Dx"
		crossobjDx = ie4 ? document.all.canvas0Dx : ns7 ? document.getElementById("canvas0Dx") : ns4 ? document.canvas0Dx.document.canvas1Dx : null
		if (ie4 || ns7) {
			crossobjDx.innerHTML = scrollercontentDx[curindexDx]
			rotateSlide(side)
		}
		else if (ns4) {
			document.canvas0Dx.visibility = "show"
			curindexDx ++
			setInterval("rotateSlide('" + side + "')", pause)
		}
	}
}


/***********************************************************************************************
*****************                      PRESENTATION EFFECT                         *************
************************************************************************************************/


/* splashNumber - number of swapping images
 * interval     - amount of time between each swap (in milliseconds)
 * lastImg      - final image to be rendered if passed
 */


i = 1
lastImgChk = false
lastImgObj = null

function displaySplashIMG(splashNumber, interval, lastImg) {
	if (lastImg && lastImg.src) {
		lastImgObj = lastImg
		lastImgChk = true
	}
	if (i <= splashNumber) {
		if (ie4 || ns7) {
			if (i > 1) {
				old_sc_ie = ie4 ? eval("document.all.splashContainerIE_" + (i - 1)) : document.getElementById("splashContainerIE_" + (i - 1))
				old_sc_ie.style.visibility = "hidden"
			}
			sc_ie = ie4 ? eval("document.all.splashContainerIE_" + i) : document.getElementById("splashContainerIE_" + i)
			sc_ie.style.left = document.body.scrollLeft + document.body.clientWidth / 2 - sc_ie.offsetWidth / 2
			sc_ie.style.top = document.body.scrollTop + document.body.clientHeight / 2 - sc_ie.offsetHeight / 2
			sc_ie.style.visibility = "visible"
			i++
		}
		else if (ns4) {
			if (i > 1) {
				old_sc_ns = eval("document.splashContainerNS_" + (i - 1))
				old_sc_ns.visibility = "hide"
			}			
			sc_ns = eval("document.splashContainerNS_" + i)
			sc_ns.left = pageXOffset + window.innerWidth / 2 - sc_ns.document.width / 2
			sc_ns.top = pageYOffset + window.innerHeight / 2 - sc_ns.document.height / 2
			sc_ns.visibility = "show"
			i++
		}
		else return
		setTimeout("displaySplashIMG(" + splashNumber + ", " + interval + ", " + lastImgChk + ")", interval)
	}
	else {
		if (ie4 || ns7) {
			sc_ie.style.visibility = "hidden"
			if (lastImgChk && ie4 && !op7) {
				lastImgObj.style.display = "inline"
				nereidFade(lastImgObj, 100, 75, 5)
			}
			else if (lastImgChk) lastImgObj.style.visibility = "visible"
		}
		else {
			sc_ns.visibility = "hide"
			if (lastImgChk) lastImgObj.visibility = "show"
		}
	}
}


/***********************************************************************************************
*****************                       OPEN IMAGE HANDLER                         *************
************************************************************************************************/


function getImgSrc() {
	searcStr = /\*/g
	imgSrc = window.location.search.replace(searcStr, "/")
	searcStr = /\/thumbnails/g
	imgSrc = imgSrc.replace(searcStr, "")
	if (imgSrc.indexOf("images") != - 1)
		imgSrc = imgSrc.substr(imgSrc.indexOf("images"))
	else if (imgSrc.indexOf("download") != - 1)
		imgSrc = imgSrc.substr(imgSrc.indexOf("download"))
	return imgSrc
}

function setImgSrc(imgObj) {
	searcStr = /\//g
	imgSrc = imgObj.src.replace(searcStr, "*")
	window.location = "enlarged.htm?imgSrc=" + imgSrc
}


/***********************************************************************************************
*****************                        ORDER FORM MAILER                         *************
************************************************************************************************/


function sendOrderForm(sItem, sUnitCost) {
	sRecipient = "merchandize@methedras.com"
	sSubject = "Order Form"
	sBody = "Item: " + sItem + "; "
	sBody += "Amount: 1; "
	sBody += "Unit Cost: " + sUnitCost + ",00 E; "
	sBody += "Postal Charge: 2,00 E (Italy) / 4,00 E (UE) / 6,00 E (World); "
	sBody += "Full Name: ; "
	sBody += "Address: ; "
	sBody += "Postal Code: ; "
	sBody += "City/Location: ; "
	sBody += "Province/State: ; "
	sBody += "Country: ; "
	sMailURL = "mailto:" + sRecipient + "?subject=" + sSubject + "&body=" + sBody
	window.location = sMailURL
}


/***********************************************************************************************
*****************                          POPUP HANDLER                           *************
************************************************************************************************/


function showPopup() {
	sPopFeatures = "top=0,left=0,height=" + iPopHeight + ",width=" + iPopWidth + ","
	sPopFeatures += "resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no"
	if (bPopDisabled) return
	else return window.open("popup.htm", "popup", sPopFeatures)
}


/***********************************************************************************************
*****************                        ROLLOVER HANDLER                           ************
************************************************************************************************/


function rollOver() {
	srcString = window.event.toElement.src
	srcString = srcString.substr(0, srcString.length - 4) + "_over.gif"
	window.event.toElement.src = srcString
}

function rollOut() {
	srcString = window.event.fromElement.src
	srcString = srcString.substr(0, srcString.length - 9) + ".gif"
	window.event.fromElement.src = srcString
}

function setInactive() {
//alert("1 > " + window.top.document.all.previousObj.value)
	if (window.top.document.all.previousObj.value.indexOf("_over.gif") > 0) {
		targetObj = window.top.document.all.previousObj.value.substr(window.top.document.all.previousObj.value.lastIndexOf("/") + 1)
//alert("2 > " + targetObj)
		targetObj = targetObj.substr(0, targetObj.length - 9)
//alert("3 > " + targetObj)
		targetObj = eval("window.top.document." + targetObj)
//alert("4 > " + targetObj.src)
		targetObj.src = targetObj.src.substr(0, targetObj.src.length - 9) + ".gif"
//alert("5 > " + targetObj.src)				
		window.top.document.all.previousObj.value = targetObj.src
//alert("6 > " + window.top.document.all.previousObj.value)
		targetObj.className = "link"
	}

}

function checkActive(activeObj) {
	setInterval("setActive('" + activeObj.location.href + "')", 100)
}
	
function setActive(activeLoc) {
//alert("1 > " + activeLoc)
	targetObj = activeLoc.substr(activeLoc.lastIndexOf("/") + 1)
//alert("2 > " + targetObj)	
	if (targetObj.indexOf("_") > 0)	targetObj = targetObj.substr(0, targetObj.indexOf("_"))
	else targetObj = targetObj.substr(0, targetObj.length - 4)
//alert("3 > " + targetObj)	
	targetObj = eval("window.top.document." + targetObj)
//alert("4 > " + targetObj.src)
	if (targetObj.src.indexOf("_over.gif") < 0) {
		targetObj.src = targetObj.src.substr(0, targetObj.src.length - 4) + "_over.gif"
//alert("5 > " + targetObj.src)
		window.top.document.all.previousObj.value = targetObj.src
//alert("6 > " + window.top.document.all.previousObj.value)
		targetObj.className = ""
	}
}


/***********************************************************************************************
*****************                           SWAP IMAGE                              ************
************************************************************************************************/


function SwapImage(pos, name, value) {

	objA = eval("document.getElementById('a" + pos + name + "')")
	objIMG = eval("document.getElementById('img" + pos + name + "')")
	objSPAN = eval("document.getElementById('sp" + pos + name + "')")
	
	if (value == "MTH002") {
		objIMG.name = "IMGRECURSIVE" + pos
		objIMG.src = "images/releases/thumbnails/2004%20Recursive.gif"
	}
	
	if (value == "MTH003") {
		objIMG.name = "IMGTHEWORSTWITHIN" + pos
		objIMG.src = "images/releases/thumbnails/2005%20The%20Worst%20Within.jpg"
	}
	
	if (value == "RECURSIVE") {
		objIMG.name = "IMGTSHIRTBACKRECURSIVE" + pos
		objIMG.src = "images/merch/thumbnails/T-Shirt%20Back%20Recursive.jpg"
	}
	
	if (value == "THRASH") {
		objIMG.name = "IMGTSHIRTBACKTHRASH" + pos
		objIMG.src = "images/merch/thumbnails/T-Shirt%20Back%20Thrash.jpg"	
	}
	
	objA.href = "javascript: setImgSrc(document." + objIMG.name + ")"
	if (objSPAN) objSPAN.innerHTML = "&lt;" + value + "&gt;"
}
