// JavaScript Document

var homeplatform;
if (document.location.href.indexOf('/xbox360')>0) {
	homeplatform='xbox360';
	document.getElementById('topplatform').innerHTML='<img src="/images/structure/top_xbox360.png">';
	} else if (document.location.href.indexOf('/ps3')>0) {
	homeplatform='ps3';
	document.getElementById('topplatform').innerHTML='<img src="/images/structure/top_ps3.png">';
	} else if (document.location.href.indexOf('/wii')>0) {
	homeplatform='wii';
	document.getElementById('topplatform').innerHTML='<img src="/images/structure/top_wii.png">';
	} else if (document.location.href.indexOf('/ds')>0) {
	homeplatform='ds';
	document.getElementById('topplatform').innerHTML='<img src="/images/structure/top_ds.png">';
	} else if (document.location.href.indexOf('/psp')>0) {
	homeplatform='psp';
	document.getElementById('topplatform').innerHTML='<img src="/images/structure/top_psp.png">';
	} else if (document.location.href.indexOf('/pc')>0) {
	homeplatform='pc';
	document.getElementById('topplatform').innerHTML='<img src="/images/structure/top_pc.png">';
	}
	
	
	

var ImageScroller = function(e, f)
{
   e = getElem(e);
   f = getElem(f);
   var g = new Array();
   var h = new Array();
   var j = new Array();
   var k = new Array();
   var l = new Array();
   var m = 1;
   var n = 0;
   var o = 0;
   var p;
   var q = 0;
   var r = 0;
   var s = 0;
   var t = 0;
   var u = true;
   var v = 0;
   var w = 2000;
   var x = 1;
   var y = 1;
   var z = 1;
   var A = 0;
   var B = 0;
   var C = 0;
   var D = 0;
   var E = 1;
   var F = false;
   var G = "";
   var H = "";
   var I = 3;
   var J = 7;
   var K;
   this.THUMB_HEIGHT = 80;
   this.THUMB_WIDTH = 80;
   this.THUMB_PADDING = 4;
   this.AutoLoop = false;
   var L = 1;
   var M = 0;
   var N = 0;
   var O = 0;
   var P = false;
      
   this.enableMultiSizeThumbnails = function()
   {
      F = true
   }
   ;
   this.setNumOfImageToScroll = function(a)
   {
      E = parseInt(a)
   }
   ;
   this.enableThumbnailDescription = function(a)
   {
      C = 1;
      H = a
   }
   ;
   this.setScrollType = function(a)
   {
      if(a == 0)
      {
         z = 0
      }
      else
      {
         z = 1
      }
   }
   ;
   this.getScrollType = function()
   {
      return z
   }
   ;
   this.setScrollSpeed = function(a)
   {
      if(a > 0 || a < 1000)
      {
         I = a
      }
      else
      {
         I = 7
      }
   }
   ;
   this.setScrollAmount = function(a)
   {
      if(a > 0 || a < 1000)
      {
         J = a
      }
      else
      {
         J = 7
      }
   }
   ;
   this.setAutoLoop = function(a)
   {
      u = a;
      this.AutoLoop = u
   }
   ;
   this.getAutoLoop = function()
   {
      return this.AutoLoop
   }
   ;
   this.setClickOpenType = function(a)
   {
      if(a == 0 || a == 1)
      {
         D = a
      }
   }
   ;
   this.enableCurrentCount = function(a)
   {
      B = 1;
      G = a
   }
   ;
   this.enableThumbBorder = function(a)
   {
      A = a
   }
   ;
   this.setThumbsShown = function(a)
   {
      m = parseInt(a)
   }
   ;
   this.getThumbsShown = function()
   {
      return m
   }
   ;
   this.addThumbnail = function(plat, a, b, c, d)
   {
	  if (h.length==4) { return; }			// uzimamo 4 samo

	  if (!homeplatform || homeplatform==plat) {
	  
	    if (!homeplatform) {
			for ( var i=0; i<k.length; i++ ) {
			if (k[i].match(/\/[^\/]+$/g)[0]==b.match(/\/[^\/]+$/g)[0]) { return; }		// na glavnoj necemo da dupliramo iste article za razlicite platforme
			}
		}
	  
		h[h.length] = a;
		k[k.length] = b;
		j[j.length] = c;
		l[l.length] = d
		}
   }
   ;
   this.setThumbnailHeight = function(a)
   {
      this.THUMB_HEIGHT = a
   }
   ;
   this.getThumbnailHeight = function()
   {
      return this.THUMB_HEIGHT
   }
   ;
   this.setThumbnailWidth = function(a)
   {
      this.THUMB_WIDTH = a
   }
   ;
   this.getThumbnailWidth = function()
   {
      return this.THUMB_WIDTH
   }
   ;
   this.setThumbnailPadding = function(a)
   {
      this.THUMB_PADDING = a
   }
   ;
   this.getThumbnailPadding = function()
   {
      return THUMB_PADDING
   }
   ;
   this.getCurrentThumbIndex = function()
   {
      return L
   }
   ;
   this.getThumbnailCount = function()
   {
      return p
   }
   ;
   this.getScrollerHeight = function()
   {
      return this.iNumOfThumbsShownHeightTotal_
   }
   ;
   this.getScrollerWidth = function()
   {
      return n
   }
   ;
   this.iNumOfThumbsShownHeightTotal_ = 0;
   this.renderScroller = function()
   {
      p = h.length;											// p: broj slika
      if (m > p) { m = p }									// m: broj slika za pokazati
	  
	  var tmp;												// move the first feature to the last place
	  tmp = h.shift(); h.push(tmp);
	  tmp = k.shift(); k.push(tmp);
	  tmp = j.shift(); j.push(tmp);
	  tmp = l.shift(); l.push(tmp);
	  
      var a;
      var b;
      a = document.createElement("a");
      b = document.createElement("img");

      for(i = 0; i < p; i ++ )
      {
         a = document.createElement("a");
         a.title = j[i];
         b = document.createElement("img");
         b.src = h[i];
         b.alt = j[i];
         b.border = 0;
         b.width = this.THUMB_WIDTH;
         b.height = this.THUMB_HEIGHT;
         if(k[i].indexOf("javascript:") > - 1)
         {
            a.href = k[i]
         }
         else if(k[i] == "")
         {
         }
         else
         {
            a.href = k[i];
            if(D == 1)
            {
               a.target = "_blank"
            }
         }
         if(document.all){
            // b.style.padding = this.THUMB_PADDING
			b.style.marginTop =  this.THUMB_PADDING
			b.style.marginBottom =  this.THUMB_PADDING
			} else {
            // b.style.padding = this.THUMB_PADDING + "px"
			b.style.marginTop =  this.THUMB_PADDING + "px"
			b.style.marginBottom =  this.THUMB_PADDING + "px"
			}
         if(b.height > q) {
            q = b.height
			}
         if(b.width > r) {
            r = b.width
			}
         s = s + (0 + b.width);
         if(i < m)
         {
            n = n + (0 + b.width)
         }
         t = t + (0 + b.height);
         if(i < m)
         {
            o = o + (0 + b.height)
         }
         a.appendChild(b);
         b.style.verticalAlign = "middle";
         b.style.align = "center";
         if(F == true)
         {
            _tbl = document.createElement("table");
            _body = document.createElement("tbody");
            _row = document.createElement("tr");
            _cell = document.createElement("td");
            _div = document.createElement("div");
            f.appendChild(a)
         }
         else
            f.appendChild(a)
         {
         }
      }
	  f.innerHTML+=f.innerHTML;								// dupliramo posto pravimo loop
	     showBig(-1);
		 document.getElementById('imgBigScreen').style.display = 'block';
		 
      var c = 2;
      if(document.all)
      {
         c = 4
      }
      ;
      p = h.length;
      if(m > p)
      {
         m = p
      }
      s = s + ((this.THUMB_PADDING * 2) * p);
      n = n + ((this.THUMB_PADDING * 2) * m);
      t = t + ((this.THUMB_PADDING * 2) * p);
      o = o + ((this.THUMB_PADDING * 2) * m);
      this.iNumOfThumbsShownHeightTotal_ = o;
      if(z == 0)
      {																		// horizontalni scroll
		 N = (n*2 - s);														// idemo do duplo vece vrednosti
         if(document.all)
         {
         }
         e.style.width = n + "px";
         if(A == 1)
         {
            e.style.width = (parseInt(e.style.width) + (p * 4)) + "px"
         }
         e.style.height = (q + (this.THUMB_PADDING * 2)) + "px";
         if(A == 1)
         {
            e.style.height = (parseInt(e.style.height) + 4) + "px"
         }
         f.style.width = s + "px";
         if(A == 1)
         {
            f.style.width = (parseInt(f.style.width) + (p * 4)) + "px"
         }
      }
      else if(z == 1)
      {																		// vertikalni scroll
         N = 0 - ((t*2 - o));												// idemo do duplo vece vrednosti
         e.style.width = (r + (this.THUMB_PADDING * 2)) + "px";
         if(A == 1)
         {
            e.style.width = (parseInt(e.style.width) + (4)) + "px"
         }
         e.style.height = o + "px";
         if(A == 1)
         {
            e.style.height = (parseInt(e.style.height) + (m * 4)) + "px"
         }
         f.style.width = (r + (this.THUMB_PADDING * 2)) + "px";
         if(A == 1)
         {
            f.style.width = (parseInt(f.style.width) + 4) + "px"
         }
      }

      if(B == 1)
      {
         addAnEvent(window, "load", this.updateCurrentCount)
      }
      if(C == 1)
      {
         addAnEvent(window, "load", this.updateCurrentDescription)
      }
   }
   ;
   this.smoothScrollUp = function()
   {
      _origOffset = parseInt(f.style.top);
      _currentOffset = parseInt(f.style.top);
      _newOffset = _currentOffset - J;
      if(this.THUMB_PADDING > 0)
      {
         _newOffset = _newOffset - (2 * this.THUMB_PADDING)
      }
      if(A == 1)
      {
         _newOffset = _newOffset - 4
      }
      if(P == false && _newOffset >= N)
      {
         O = _newOffset;
         smoothMoveScrollerUp()
      }
   }
   ;
   this.scrollUp = function()
   {
      _origOffset = parseInt(f.style.top);
      _currentOffset = parseInt(f.style.top);
      _newOffset = _currentOffset - (this.THUMB_HEIGHT * E);
      if(this.THUMB_PADDING > 0)
      {
         _newOffset = _newOffset - (2 * this.THUMB_PADDING)
      }
      if(A == 1)
      {
         _newOffset = _newOffset - 4
      }
      if(P == false && _newOffset >= N)
      {
         O = _newOffset;
         moveScrollerUp()
      }
   }
   ;
   this.smoothScrollDown = function()
   {
      _origOffset = parseInt(f.style.top);
      _currentOffset = parseInt(f.style.top);
      _newOffset = _currentOffset + J;
      if(this.THUMB_PADDING > 0)
      {
         _newOffset = _newOffset + (2 * this.THUMB_PADDING)
      }
      if(A == 1)
      {
         _newOffset = _newOffset + 4
      }
      if(_newOffset <= 0)
      {
         if(_currentOffset > (_origOffset - this.THUMB_HEIGHT))
         {
            if(P == false && _newOffset >= N)
            {
               M = _newOffset;
               smoothMoveScrollerDown()
            }
         }
      }
   }
   ;
   this.scrollDown = function()
   {
      _origOffset = parseInt(f.style.top);
      _currentOffset = parseInt(f.style.top);
      _newOffset = _currentOffset + (this.THUMB_HEIGHT * E);
      if(this.THUMB_PADDING > 0)
      {
         _newOffset = _newOffset + (2 * this.THUMB_PADDING)
      }
      if(A == 1)
      {
         _newOffset = _newOffset + 4
      }
      if(_newOffset <= 0)
      {
         if(_currentOffset > (_origOffset - this.THUMB_HEIGHT))
         {
            if(P == false && _newOffset >= N)
            {
               M = _newOffset;
               moveScrollerDown()
            }
         }
      }
   }
   ;
   this.scrollTop = function()
   {
      if(P == false)
      {
         O = (N);
         L = p - m;
         moveScrollerUp()
      }
   }
   ;
   this.scrollBottom = function()
   {
      if(P == false)
      {
         M = 0;
         L = p - m;
         moveScrollerDown()
      }
   }
   ;
   this.smoothScrollReverse = function()
   {
      _origOffset = parseInt(f.style.left);
      _currentOffset = parseInt(f.style.left);
      _newOffset = _currentOffset + J;
      if(this.THUMB_PADDING > 0)
      {
         _newOffset = _newOffset + (this.THUMB_PADDING * (2 * E))
      }
      if(A == 1)
      {
         _newOffset = _newOffset + 4
      }
      if(_newOffset <= 0)
      {
         if(_currentOffset > (_origOffset - (this.THUMB_WIDTH * E)))
         {
            if(P == false)
            {
               M = _newOffset;
               smoothMoveScrollerRight()
            }
         }
      }
   }
   ;
   this.scrollReverse = function()
   {
      if(z == 0)
      {
         _origOffset = parseInt(f.style.left);
         _currentOffset = parseInt(f.style.left);
         _newOffset = _currentOffset + (this.THUMB_WIDTH * E);
         if(this.THUMB_PADDING > 0)
         {
            _newOffset = _newOffset + (this.THUMB_PADDING * (2 * E))
         }
         if(A == 1)
         {
            _newOffset = _newOffset + 4
         }
         if(_newOffset <= 0)
         {
            if(_currentOffset > (_origOffset - (this.THUMB_WIDTH * E)))
            {
               if(P == false)
               {
                  M = _newOffset;
                  moveScrollerRight()
               }
            }
         }
      }
      else
      {
         this.scrollDown()
      }
   }
   ;
   this.smoothScrollForward = function()
   {
      _origOffset = parseInt(f.style.left);
      _currentOffset = parseInt(f.style.left);
      _newOffset = _currentOffset - J;
      if(this.THUMB_PADDING > 0)
      {
         _newOffset = _newOffset - ((2 * E) * this.THUMB_PADDING)
      }
      if(A == 1)
      {
         _newOffset = _newOffset - 4
      }
      if(P == false && _newOffset >= N)
      {
         O = _newOffset;
         smoothMoveScrollerLeft()
      }
   }
   ;
   this.scrollForward = function()
   {
      if(z == 0)
      {
         _origOffset = parseInt(f.style.left);
         _currentOffset = parseInt(f.style.left);
         _newOffset = _currentOffset - (this.THUMB_WIDTH * E);
         if(this.THUMB_PADDING > 0)
         {
            _newOffset = _newOffset - ((2 * E) * this.THUMB_PADDING)
         }
         if(A == 1)
         {
            _newOffset = _newOffset - 4
         }
         if(P == false && _newOffset >= N)
         {
            O = _newOffset;
            moveScrollerLeft()
         }
      }
      else
      {
         this.scrollUp()
      }
   }
   ;
   this.scrollEnd = function()
   {
      if(z == 0)
      {
         if(P == false)
         {
            O = N;
            L = p - m;
            moveScrollerLeft()
         }
      }
      else
      {
         this.scrollTop()
      }
   }
   ;
   this.scrollBegin = function()
   {
      if(z == 0)
      {
         if(P == false)
         {
            M = 0;
            L = 2;
            moveScrollerRight()
         }
      }
      else
      {
         this.scrollBottom()
      }
   }
   ;
   this.stopSmoothScroll = function()
   {
      P = false;
      window.clearTimeout(K)
   }
   ;
   this.updateCurrentDescription = function()
   {
      getElem(H).innerHTML = l[L - 1]
   }
   ;
   this.updateCurrentCount = function()
   {
      getElem(G).innerHTML = L + "/" + p
   }
   ;
   function smoothMoveScrollerUp()
   {
      _ElementObj = f;
      _currentOffset = parseInt(_ElementObj.style.top);
      if(_currentOffset > N && (_currentOffset - J) >= N)
      {
         _ElementObj.style.top = _currentOffset - J + "px";
         P = true;
         K = window.setTimeout(smoothMoveScrollerUp, I)
      }
      else if(_currentOffset > N)
      {
         _ElementObj.style.top = _currentOffset - 1 + "px";
         P = true;
         K = window.setTimeout(smoothMoveScrollerUp, I)
      }
      else
      {
         P = false;
         window.clearTimeout(K)
      }
   }
   ;
   function moveScrollerUp()
   {
      _ElementObj = f;
      _currentOffset = parseInt(_ElementObj.style.top);
      if(_currentOffset > O && (_currentOffset - J) >= O)
      {
         _ElementObj.style.top = _currentOffset - J + "px";
         P = true;
         K = window.setTimeout(moveScrollerUp, I)
      }
      else if(_currentOffset > O)
      {
         _ElementObj.style.top = _currentOffset - 1 + "px";
         P = true;
         K = window.setTimeout(moveScrollerUp, I)
      }
      else
      {
         P = false;
         L ++ ;
		 if (L == (m+1)*2-3) {											// valjda radi
			_ElementObj.style.top = 0 + "px";
			L=1;
			}
		showBig(L-2);													// ovu prikazujemo levo
		 
         window.clearTimeout(K);
         if(C == 1)
         {
            getElem(H).innerHTML = l[L - 1]
         }
         if(B == 1)
         {
            getElem(G).innerHTML = L + "/" + p
         }
      }
   }
   ;
   
   
    function showBig(a) {
		if (a<0) { a=a+h.length; }
		document.getElementById("imgBigScreen").src = h[a];
		document.getElementById("dvBigScreenTitle").innerHTML = '<b>' + j[a] + '</b>' + l[a];
		document.getElementById("dvBigScreen").onclick = function() { location.href=k[a]; }
	}
	;
   
   
   
   function smoothMoveScrollerDown()
   {
      _ElementObj = f;
      _currentOffset = parseInt(_ElementObj.style.top);
      if(_currentOffset < 0 && (_currentOffset + J) <= 0)
      {
         _ElementObj.style.top = _currentOffset + J + "px";
         P = true;
         K = window.setTimeout(smoothMoveScrollerDown, I)
      }
      else if(_currentOffset < 0)
      {
         _ElementObj.style.top = _currentOffset + 1 + "px";
         P = true;
         K = window.setTimeout(smoothMoveScrollerDown, I)
      }
      else
      {
         P = false;
         window.clearTimeout(K)
      }
   }
   ;
   function moveScrollerDown()
   {
      _ElementObj = f;
      _currentOffset = parseInt(_ElementObj.style.top);
      if(_currentOffset < M && (_currentOffset + J) <= M)
      {
         _ElementObj.style.top = _currentOffset + J + "px";
         P = true;
         K = window.setTimeout(moveScrollerDown, I)
      }
      else if(_currentOffset < M)
      {
         _ElementObj.style.top = _currentOffset + 1 + "px";
         P = true;
         K = window.setTimeout(moveScrollerDown, I)
      }
      else
      {
         P = false;
         L -- ;
         window.clearTimeout(K);
         if(C == 1)
         {
            getElem(H).innerHTML = l[L - 1]
         }
         if(B == 1)
         {
            getElem(G).innerHTML = L + "/" + p
         }
      }
   }
   ;
   function smoothMoveScrollerRight()
   {
      _ElementObj = f;
      _currentOffset = parseInt(_ElementObj.style.left);
      if(_currentOffset < 0 && (_currentOffset + J) <= 0)
      {
         _ElementObj.style.left = _currentOffset + J + "px";
         P = true;
         K = window.setTimeout(smoothMoveScrollerRight, I)
      }
      else if(_currentOffset < 0)
      {
         _ElementObj.style.left = _currentOffset + 1 + "px";
         P = true;
         K = window.setTimeout(smoothMoveScrollerRight, I)
      }
      else
      {
         P = false;
         window.clearTimeout(K)
      }
   }
   ;
   function moveScrollerRight()
   {
      _ElementObj = f;
      _currentOffset = parseInt(_ElementObj.style.left);
      if(_currentOffset < M && (_currentOffset + J) <= M)
      {
         _ElementObj.style.left = _currentOffset + J + "px";
         P = true;
         K = window.setTimeout(moveScrollerRight, I)
      }
      else if(_currentOffset < M)
      {
         _ElementObj.style.left = _currentOffset + 1 + "px";
         P = true;
         K = window.setTimeout(moveScrollerRight, I)
      }
      else
      {
         P = false;
         L -- ;
         window.clearTimeout(K);
         if(C == 1)
         {
            getElem(H).innerHTML = l[L - 1]
         }
         if(B == 1)
         {
            getElem(G).innerHTML = L + "/" + p
         }
      }
   }
   ;
   function smoothMoveScrollerLeft()
   {
      _ElementObj = f;
      _currentOffset = parseInt(_ElementObj.style.left);
      if(_currentOffset > N && (_currentOffset - J) >= N)
      {
         _ElementObj.style.left = _currentOffset - J + "px";
         P = true;
         K = window.setTimeout(smoothMoveScrollerLeft, I)
      }
      else if(_currentOffset > N)
      {
         _ElementObj.style.left = _currentOffset - 1 + "px";
         P = true;
         K = window.setTimeout(smoothMoveScrollerLeft, I)
      }
      else
      {
         P = false;
         window.clearTimeout(K)
      }
   }
   ;
   function moveScrollerLeft()
   {
      _ElementObj = f;
      _currentOffset = parseInt(_ElementObj.style.left);
      if(_currentOffset > O && (_currentOffset - J) >= O)
      {
         _ElementObj.style.left = _currentOffset - J + "px";
         P = true;
         K = window.setTimeout(moveScrollerLeft, I)
      }
      else if(_currentOffset > O)
      {
         _ElementObj.style.left = _currentOffset - 1 + "px";
         P = true;
         K = window.setTimeout(moveScrollerLeft, I)
      }
      else
      {
         P = false;
         L ++ ;
         window.clearTimeout(K);
         if(C == 1)
         {
            getElem(H).innerHTML = l[L - 1]
         }
         if(B == 1)
         {
            getElem(G).innerHTML = L + "/" + p
         }
      }
   }
}
;
var iRetryAttempt = 0;
var iMaxAttachRetry = 3;
function addAnEvent(a, b, c)
{
   if(a != null && a != "undefined")
   {
      if(window.addEventListener)
      {
         a.addEventListener(b, c, false)
      }
      else
      {
         a.attachEvent("on" + b, c)
      }
      iRetryAttempt = 0
   }
   else
   {
      if(iRetryAttempt < iMaxAttachRetry)
      {
         try
         {
            iRetryAttempt ++ ;
            window.setTimeout(addAnEvent(a, b, c), 1000)
         }
         catch(Exceptions)
         {
            return
         }
      }
   }
}
;
function getElem(a)
{
   return document.getElementById(a)
}
;


