var secs = 1;
	var timerID = null;
	var timerRunning = false;
	var delay = 500;

	var theImages = new Array();

	var currentImage = -1;
	var maxImages = -1;
	//var trailimage = [theImages[currentImage], 208, 320];

	var trailimage = ["", 208, 320];
	var offsetfrommouse = [10,10];
	var currentimagewidth = 208;
	var currentimageheight = 320;
	var firstFlag = false;
	var userAgent = "0";


	if (document.getElementById || document.all) {
		userAgent = navigator.userAgent;
		if(userAgent.indexOf("MSIE") > 0) {
			userAgent = parseInt(userAgent.substring(userAgent.indexOf("MSIE") + 5, userAgent.indexOf("MSIE") + 8));
		} else {
			userAgent = "0";
		}
		if(userAgent == "5" || userAgent == "6") {
//			document.write('<div id="trail_image" style="background-color: #b9b9b9; position:absolute;visibility:hidden;left:-386px;top:0px;width:210px;height:386px"><img id="imageid" src="'+trailimage[0]+'" border="0" width="'+trailimage[1]+'px" height="'+trailimage[2]+'px" style="position: absolute; left: 5px; top: 5px;z-index:9999"></div>');
			document.write('<div id="trail_image" style="background-color: #b9b9b9; position:absolute;visibility:hidden;left:-386px;top:0px;width:210px;height:323px"><img id="imageid" src="'+trailimage[0]+'" border="0" style="position: absolute; left: 5px; top: 5px;z-index:9999"></div>');
			document.write('<div id="trail_video" style="position: absolute; visibility: hidden; left: -391px; top: 0px; width: 391px; height: 227px" style="z-index: 999">');
			document.write('</div>');
		} else {
			document.write('<div id="trail_image" style="background-image: url(http://arkitip.com/docs/images/shadow.png); position: absolute; visibility: hidden; left: -386px; top: 0px; width: 208px; height: 320px">');
//			document.write('<img id="imageid" src="' + trailimage[0] + '" border="0" width="' + trailimage[1] + 'px" height="' + trailimage[2] + 'px">');
			document.write('<img id="imageid" src="' + trailimage[0] + '" border="0" >');
			document.write('</div>');
			
			document.write('<div id="trail_video" style="position: absolute; visibility: hidden; left: -391px; top: 0px; width: 391px; height: 227px">');
			document.write('</div>');
			
		}
	}
	
	function gettrailobj() {
		if (document.getElementById) {
			if(theImages.length > 0) {
				return document.getElementById("trail_image").style;
			} else {
				return document.getElementById("trail_video").style;
			}
		} else if (document.all) {
			if(theImages.length > 0) {
				return document.all.trail_image.style;
			} else {
				return document.all.trail_video.style;
			}
		}
	}

	function truebody() {
		return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
	}

	function showtrail(sURLs) {
		theImages = sURLs.split(",");
		currentImage = -1;
		maxImages = theImages.length - 1;
		if(maxImages > 4) {
			maxImages = 4;
		}
		for(i = 0; i <= maxImages; i++) {
			x = "/magazines/images/" + theImages[i];
			theImages[i] = new Image(208, 320);
			theImages[i].src = x;
		}
        document.getElementById("imageid").src = theImages[0].src;
		document.onmousemove = followmouse;
		InitializeTimer();
		//gettrailobj().visibility = "visible";
	}

	function showtrail2(sSku) {
		userAgent = navigator.userAgent;
		if(userAgent.indexOf("MSIE") > 0) {
			userAgent = parseInt(userAgent.substring(userAgent.indexOf("MSIE") + 5, userAgent.indexOf("MSIE") + 8));
		} else {
			userAgent = "0";
		}
		if(userAgent != "5" && userAgent != "6") {
			document.getElementById("trail_video").innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="376" height="211" id="ywft" style="position: absolute; left: 5px; top: 5px; z-index: 1">';
			document.getElementById("trail_video").innerHTML += '<param name="movie" value="ywft2.swf" />';
			document.getElementById("trail_video").innerHTML += '<param name="quality" value="high" />';
			document.getElementById("trail_video").innerHTML += '<param name="flashvars" value="&MM_ComponentVersion=1&onlineFLV=flv/' + sSku + '.flv&autoPlay=true&autoRewind=true" />';
			document.getElementById("trail_video").innerHTML += '<embed src="ywft2.swf" id="video_test" flashvars="&MM_ComponentVersion=1&onlineFLV=flv/' + sSku + '.flv&autoPlay=true&autoRewind=true" width="376" height="211" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" bgcolor="#b9b9b9" style="absolute: relative; left: 5px; top: 5px; z-index: 1" />';
			document.getElementById("trail_video").innerHTML += '</object>';
			document.getElementById("trail_video").style.visibility = "visible";
			document.onmousemove = followmouse;
		}
	}

	function hidetrail(){
		gettrailobj().visibility = "hidden";
		document.onmousemove = "";
        document.getElementById("imageid").src = "/images/blank_image.jpg";
		StopTheClock();	
	}

	function followmouse(e){
		var xcoord=offsetfrommouse[0]
		var ycoord=offsetfrommouse[1]
	
		var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
		var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
	
		//if (document.all){
		//	gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
		//} else {
		//	gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
		//}
	
		if (typeof e != "undefined"){
			if (docwidth - e.pageX < 380){
				xcoord = e.pageX - xcoord - 204; // Move to the left side of the cursor
			} else {
				xcoord += e.pageX;
			}
			if (docheight - e.pageY < (currentimageheight + 20)){
				ycoord += e.pageY - Math.max(0,(20 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
			} else {
				ycoord += e.pageY;
			}
	
		} else if (typeof window.event != "undefined"){
			if (docwidth - event.clientX < 380){
				xcoord = event.clientX + truebody().scrollLeft - xcoord - 204; // Move to the left side of the cursor
			} else {
				xcoord += truebody().scrollLeft+event.clientX
			}
			if (docheight - event.clientY < (currentimageheight + 20)){
				ycoord += event.clientY + truebody().scrollTop - Math.max(0,(20 + currentimageheight + event.clientY - docheight));
			} else {
				ycoord += truebody().scrollTop + event.clientY;
			}
		}
	
		var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
		var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
			if(ycoord < 0) { ycoord = ycoord*-1; }
		gettrailobj().left=xcoord+"px"
		gettrailobj().top=ycoord+"px"

/*
		var xcoord=offsetfrommouse[0]
		var ycoord=offsetfrommouse[1]
		if (typeof e != "undefined") {
			xcoord+=e.pageX
			ycoord+=e.pageY
		} else if (typeof window.event !="undefined") {
			xcoord+=truebody().scrollLeft+event.clientX
			ycoord+=truebody().scrollTop+event.clientY
		}
		var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
		var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if (xcoord+trailimage[1]+3>docwidth || ycoord+trailimage[2]> docheight) {
			gettrailobj().display="none"
		} else {
			gettrailobj().display=""
			gettrailobj().left=xcoord+"px"
			gettrailobj().top=ycoord+"px"
		}
*/

	}

	
	function InitializeTimer() {
	    StopTheClock();
	    StartTheTimer();
	}
	
	function StopTheClock() {
	    if(timerRunning) {
	        clearTimeout(timerID);
		}
    	timerRunning = false;
	}
	
	function StartTheTimer() {
	    if (secs == 0) {
	    	if(timerRunning == false){
	    		firstFlag = true;
	    	}
	        StopTheClock();
	        currentImage++;
	        if(currentImage > maxImages) {
	        	currentImage = 0;
	        }
	        //document.getElementById("imageid").src = "/images/" + theImages[currentImage];
	        document.getElementById("imageid").src = theImages[currentImage].src;
			gettrailobj().visibility = "visible";
			
			if(firstFlag) {
				secs = 2;
			} else {
				secs = 1.5;
			}
	        StartTheTimer();
	    } else {
	        self.status = secs;
	        secs = secs - 0.5;
	        timerRunning = true;
	        timerID = self.setTimeout("StartTheTimer()", delay);
	    }
	}
