// JavaScript Document
function z$(){eS=new Array();for (i=0;i<arguments.length;i++) {el=arguments[i]; if (typeof el == 'string')
  el=document.getElementById(el);if (arguments.length==1) return el; es.push(el);} return es;}
var gO= {addEvent: function(obj,evt, fn) {if (obj.addEventListener) {obj.addEventListener(evt, fn, false);
  } else if (obj.attachEvent) {obj.attachEvent('on'+evt, fn);} else {obj['on'+evt]=fn;}},
  fTarget: function(e) {var T;if (window.event && window.event.srcElement) {
  T=window.event.srcElement;}	else if (e && e.target) {T=e.target}if (!T) return null;return T;}}
	
	
var numdegrees=0;
var lastmove=0
var lastdeg=0
var number=0.9;
var isDone=1;
var lastArr=[4,1,2,3,4,1,2,3]
var lastdir=1
function spinit(id,angle,lr) {
	var prodimg=z$(id);	
	sinvalue=lr*Math.sin((numdegrees+angle)*(Math.PI/180))
	cosvalue=Math.cos((numdegrees+angle)*(Math.PI/180))
	/*
	hmod=Math.floor([XX]*cosvalue)/2
	Replace [XX] with the variation in the hieght between the main center image and the side images
	wmod==Math.floor([XX]*cosvalue)/2
	Replace [XX] with the variation in the width between the main center image and the size images
	*/
	hmod=Math.floor(32*cosvalue)/2 
	wmod=Math.floor(32*cosvalue)/2
	/*
	prodimg.style.top=Math.floor(-hmod+[XX]*cosvalue)+"px";
	[XX]=pixels from top of spin section - half of the height variation (hmod's [XX] value)
	prodimg.style.left=Math.floor([XX]-wmod+[XX]*sinvalue)+"px";
	[XX]=2 times the pixels spread between left side of left and right images
	*/
	prodimg.style.top=Math.floor(-hmod+64*cosvalue)+"px";
	prodimg.style.left=Math.floor(60-wmod+60*sinvalue)+"px";
	/*
	prodimg.style.height=Math.floor([XX]+[YY]*cosvalue)+"px";
	[XX]=height of the left/right images scaled down to final value
	[YY]=Full image size-[XX]
	prodimg.style.width=Math.floor([XX]+[YY]*cosvalue)+"px";
	[XX]=width of the left/right images scaled down to final value
	[YY]=Full image size-[XX]	
	*/
	prodimg.style.height=Math.floor(45+32*cosvalue)+"px";
	prodimg.style.width=Math.floor(40+32*cosvalue)+"px";
	
	/*
	After changing the numbers above, the CSS needs to be changed, I use Firefox's developer toolkit extension and then
	select the option Information -> Display element information, click on the image and get their top/left positions
	And then plug that in to the CSS for #image1, #image2 and #image4. (or you could use math to calculate it out, if you like)
	When changing the opacity, change the opacity in the CSS for the images as well.
	Don't forget to change the width and height of the IMG in the HTML for the left/right/center images.
	*/
	
	if (angle==0) {
		// Changes the opacity from the main image to the side image
		/*
		z$(id).style.opacity=(100-(numdegrees/90)*[XX])/100;
		z$(id).style.filter="alpha(opacity="+(100-(numdegrees/90)*[XX])+");";
		[XX]=change in opacity from 100. So to go to 60, 100 - 60 = 40.
		*/
		z$(id).style.opacity=(100-(numdegrees/90)*40)/100;
		z$(id).style.filter="alpha(opacity="+(100-(numdegrees/90)*40)+");";
	} else if (angle==90) {
/*		This is code to fade out the image going "off screen" which is disabled.
		If needed to be used, replace the 60's with the desired left/right opacity.
		$(id).style.opacity=(60-(numdegrees/90)*60)/100
		$(id).style.filter="alpha(opacity="+(60-(numdegrees/90)*60)+");";*/
		
		// Changes opacity of the image going off screen to 0 immediately so it disappears.
		z$(id).style.opacity=0
		z$(id).style.filter="alpha(opacity=0);";
	} else if (angle==180) {
		// Changes opacity of offscreen image to left/right
		/*
		z$(id).style.opacity=((numdegrees/90)*[XX])/100
		z$(id).style.filter="alpha(opacity="+((numdegrees/90)*[XX])+");";
		[XX]=desired end opacity for the left/right image
		*/
		z$(id).style.opacity=((numdegrees/90)*60)/100
		z$(id).style.filter="alpha(opacity="+((numdegrees/90)*60)+");";
	} else {
		// changes the opacity for the left/right image to the center image
		/*
		z$(id).style.opacity=([XX]+(numdegrees/90)*[YY])/100
		z$(id).style.filter="alpha(opacity="+([XX]+(numdegrees/90)*[YY])+");";
		[XX] = starting opacity of left/right image
		[YY] = 100 - [XX] value
		*/
		z$(id).style.opacity=(60+(numdegrees/90)*40)/100
		z$(id).style.filter="alpha(opacity="+(60+(numdegrees/90)*40)+");";
	}
}

function init(lr,origin) {
	// z$('showicons').style.visibility="hidden";
	z$('buttonImg').style.visibility="hidden";
	if(!isDone && origin) return;
	isDone=0;
	lastmove=lastmove+lr*origin;
	if (lastdir!=lr) {lastmove=lastmove-lr*2;lastdir=lr;}
	if (lastmove<0)
		lastmove=3;
	if (lastmove>3)
		lastmove=0;

	spinit("image"+lastArr[lastmove],0,lr);
	spinit("image"+lastArr[lastmove+2+lr],90,lr);
	spinit("image"+lastArr[lastmove+2],180,lr);
	spinit("image"+lastArr[lastmove+2-lr],270,lr);
	if (numdegrees<90) {
		timer=setTimeout("init("+lr+",0);",10);
		numdegrees+=number;
	} else { 
		numdegrees=0;isDone=1;lastdir=lr;
		setText=lastmove;
		if (lr==-1) {
			setText=setText-2;
			if (setText==-1) setText=3;
			if (setText==-2) setText=2;
		}
		z$('setTitle').innerHTML=listObjs[setText].t;
		z$('buttonImg').style.visibility="visible";
	}

}
function newObj(t,pc,mac,spc,smac) { this.t=t;this.pc=pc;this.mac=mac;this.spc=spc;this.smac=smac}


function zshow(n) {
  /*
	if (n==-1) {z$('showicons').style.visibility="visible"; window.clearTimeout(document.timer1);return;}
	for (var i=0;i<4;i++)
		if(z$('setTitle').innerHTML==listObjs[i].t)
			if (n==i) {
				z$('showicons').style.visibility="visible";
			}
			
   */
}
function zremove() {
//	document.timer1=window.setTimeout("z$('showicons').style.visibility='hidden'",250);
}
function playpc() {
	for (var i=0;i<4;i++)
		if(z$('setTitle').innerHTML==listObjs[i].t)
			loadme(listObjs[i].pc);
	// z$('showicons').style.visibility='hidden'
}
function playmac() {
	for (var i=0;i<4;i++)
		if(z$('setTitle').innerHTML==listObjs[i].t)
			loadme(listObjs[i].mac);
	// z$('showicons').style.visibility='hidden'
}
function seriesmac() {
	for (var i=0;i<4;i++)
		if(z$('setTitle').innerHTML==listObjs[i].t)
                window.location = listObjs[i].smac;
	return false;
}
function seriespc() {
	for (var i=0;i<4;i++)
		if(z$('setTitle').innerHTML==listObjs[i].t)
                window.location = listObjs[i].spc;
	return false;
}
function hideseries() {
	window.setTimeout("z$('showserieslinks').style.visibility='hidden'",250)
}
       function runme(o){
            $('trail').toggle();
            togglePlusMinus(o);
            if($('trail').visible()){
              o.src = o.src.replace(/plus\.png$/, 'minus.png');
              // o.src='delete.png';
            } else {
              o.src = o.src.replace(/minus\.png$/, 'plus.png');
              // o.src='add.png';
            }
        }

        function togglePlusMinus(img) {
            if($('trail').visible()){
              img.src = img.src.replace(/plus\.png$/, 'minus.png');
            } else {
              img.src = img.src.replace(/minus\.png$/, 'plus.png');
            }
        }

        /*
		function loadme(vid) {
			kw_ajaxReq(1,'tutorialpopup','/movie/'+site_nick+'/'+vid+'/play_popup',1);z$('tutorialwrapper').style.display="block";
		}
        */

        function loadme(mid) {
          var req = new Ajax.Request(
            '/movie/'+mid+'/play',
            {
              onSuccess:  function(response) {
                $('tutorialpopup').update(response.responseText);
              }
            }
          );
          $('tutorialwrapper').setStyle({display:  'block'});
        }

function kw_ajaxResp() { //v1.0
	d=document;	if (d.ht && d.ht.readyState==4) {d.iW = false;				
	d.getElementById(d.pR).innerHTML=d.ht.responseText;}
}

function kw_ajaxObj() { //v1.0
	var rV;if (window.ActiveXObject){try {rV=new ActiveXObject("Msxml2.XMLHTTP"); 
	}catch (e){try {rV=new ActiveXObject("Microsoft.XMLHTTP");}catch (E){
	rV=false;}}}if (!rV&&typeof XMLHttpRequest!='undefined'){try{rV=new XMLHttpRequest(); 
	}catch (e){rV=false;}}return rV; 
}

function kw_ajaxReq(sO,pRv,url,tP) { //v1.0
	d=document;if (!d.ht) d.ht=kw_ajaxObj();if (!d.iW) d.iW=false;if (!d.iW && d.ht) 
	{d.ht.open("GET", url , true); d.pR=pRv; 
	if(tP==3) d.ht.setRequestHeader('Content-Type', "text/xml");
	 d.ht.onreadystatechange = (tP==1)?kw_ajaxResp:(tP==2)?kw_ajaxRespDD:kw_ajaxRespXML;
	 d.iW = true;d.ht.send(null);}
}	
