/***********************************************
Copyright (C) 2008  Ugur HAMZADAYI
************************************************/
var ug_uslideshow_popup = null;
function ug_uslideshow_popup_load() {
   if( ug_uslideshow_popup != null )
	  return;
	  
    ug_uslideshow_popup = new USlideShowCtrl();
	
	//Attach messages
	if( ug_uslideshow_popup != null ) {
       AttachEventUSlideShow( window , "resize" , function(){ ug_uslideshow_popup.RefreshPosition();} );
	   AttachEventUSlideShow( window , "scroll" , function(){ ug_uslideshow_popup.RefreshPosition();} );
	}
}

//Bu Önemli
function AttachEventUSlideShow(obj, eventName, eventHandler) {
   
  if( obj ) {
     if(eventName.substring(0, 2) == 'on') {
 	    eventName = eventName.substring(2,eventName.length);
	 }
     if(obj.attachEvent){
        obj.attachEvent('on'+ eventName, eventHandler);
     } 
     else 
     if( obj.addEventListener){
        obj.addEventListener(eventName, eventHandler, false);  
     }
  }
}

AttachEventUSlideShow( window , 'onload' , ug_uslideshow_popup_load );

function USlideShowCtrl() {
   this.CreatePopup();
}

USlideShowCtrl.prototype.CreatePopup = function () {
   this.ShowIndex = 0;
   this.SlideTimerID == null;
   this.slidewin = document.createElement('div');
   this.slidewin.setAttribute('id','global_uslideshowpopupid_1');
   this.slidewin.style.position = 'absolute';
   this.slidewin.style.display = 'none';
   this.slidewin.style.backgroundColor = '#808080';
   innerText = '<iframe bgcolor="black" id="global_uslideshowpopupid_1frame" style="filter:alpha(opacity=0);-moz-opacity:.0;opacity:.0; position:absolute;display:none;" frameBorder="0" scrolling="no"></iframe>';
   innerText += '<div id="global_uslideshowpopupid_Shadow" style="BACKGROUND:#000000;BORDER:#000000 0px solid;filter:alpha(opacity=75);-moz-opacity:.75;opacity:.75; position:absolute;display:none;" ></div>';
   innerText += '<div style="margin:0px;BACKGROUND:#FFFFFF;BORDER:#000000 2px solid" onmousedown="return false;"  onconextmenu="return false;" onselectstart="return false;" onscroll="return false;">';
   innerText += '<img src="javascript/imageslide/wait.gif" style="position:absolute;display:block;"id="global_uslideshowpopupid_imageviewwait">';
   innerText += '<table height="505" cellpadding="0" cellspacing="0" border="0"><tr>';
   innerText += '<td align="left" valign="top" id="global_uslideshowpopupid_leftpaneid" style="display:none;padding:0px;BACKGROUND: url(javascript/imageslide/film.jpg) repeat-y;" width="130" height="100%"><br>';
   innerText += '<div onmousemove="ug_uslideshow_popup.smallpanelover(event);" style="overflow:hidden;height:470px;width:130px;" id="global_uslideshowpopupid_smallpane">';
   innerText += '</div>';
   innerText += '</td>';
   innerText += '<td>';
   innerText += '<table width="600" height="500" cellpadding="0" cellspacing="0" border="0" ><tr><td style="color:#000000;font-family:arial;FONT-WEIGHT:bold;font-size:11px;" height="30" valign="center" id="global_uslideshowpopupid_imageviewtitle"></td></tr><tr><td valign="middle" align="center" width="600" height="440">';
   innerText += '<center><img id="global_uslideshowpopupid_imageview1" style="display:none;" ></center>';
   innerText += '<div style="display:none;" id="global_uslideshowpopupid_imageviewdiv"><img id="global_uslideshowpopupid_imageview2" style="display:none;" ></div>';
   innerText += '</td></tr>';
   innerText += '<tr><td height="35" valign="bottom" style="BACKGROUND: url(javascript/imageslide/pattern.jpg) repeat-x;"><center>';
   innerText += '<div>';
   innerText += '<img vspace="0" hspace="0" align="absmiddle" border="0" style="filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" src="javascript/imageslide/left.gif">';
   innerText += '<img vspace="0" hspace="0" align="absmiddle" border="0" onclick="ug_uslideshow_popup.OnPrev();" onmouseover="this.src=\'javascript/imageslide/prevover.gif\';" onmouseout="this.src=\'javascript/imageslide/prev.gif\';"  id="global_uslideshowpopupid_btnprev" style="filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" src="javascript/imageslide/prev.gif"  alt="Bir önceki resim">';
   innerText += '<img vspace="0" hspace="0" align="absmiddle" border="0" onclick="ug_uslideshow_popup.OnPlayStop();" onmouseover="this.src=\'javascript/imageslide/playover.gif\';" onmouseout="this.src=\'javascript/imageslide/play.gif\';" id="global_uslideshowpopupid_btnplay" style="filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" src="javascript/imageslide/play.gif" alt="Slayt gösterisini baslat">';
   innerText += '<img vspace="0" hspace="0" align="absmiddle" border="0" onclick="ug_uslideshow_popup.OnPlayStop();" onmouseover="this.src=\'javascript/imageslide/pauseover.gif\';" onmouseout="this.src=\'javascript/imageslide/pause.gif\';" id="global_uslideshowpopupid_btnpause" style="display:none;filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" src="javascript/imageslide/pause.gif" alt="Slayt gösterisini bitir" >';   
   innerText += '<img vspace="0" hspace="0" align="absmiddle" border="0" onclick="ug_uslideshow_popup.OnNext();" onmouseover="this.src=\'javascript/imageslide/nextover.gif\';" onmouseout="this.src=\'javascript/imageslide/next.gif\';" id="global_uslideshowpopupid_btnnext" style="filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" src="javascript/imageslide/next.gif" alt="Bir sonraki resim">';
   innerText += '<img vspace="0" hspace="0" align="absmiddle" border="0" onclick="ug_uslideshow_popup.OnLeftPaneView();" onmouseover="this.src=\'javascript/imageslide/fullpanelover.gif\';" onmouseout="this.src=\'javascript/imageslide/fullpanel.gif\';" id="global_uslideshowpopupid_btnfullpanel" style="display:none;filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" src="javascript/imageslide/fullpanel.gif" alt="Tam görünüm">';   
   innerText += '<img vspace="0" hspace="0" align="absmiddle" border="0" onclick="ug_uslideshow_popup.OnLeftPaneView();" onmouseover="this.src=\'javascript/imageslide/largepanelover.gif\';" onmouseout="this.src=\'javascript/imageslide/largepanel.gif\';" id="global_uslideshowpopupid_btnlargepanel" style="filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" src="javascript/imageslide/largepanel.gif" alt="Liste görünümü">';
   innerText += '<img vspace="0" hspace="0" align="absmiddle" border="0" style="filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" src="javascript/imageslide/empty.gif">';   
   innerText += '<img vspace="0" hspace="0" align="absmiddle" border="0" onclick="ug_uslideshow_popup.HidePopup();" onmouseover="this.src=\'javascript/imageslide/closeover.gif\';" onmouseout="this.src=\'javascript/imageslide/close.gif\';" id="global_uslideshowpopupid_btnclose" style="filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" src="javascript/imageslide/close.gif" alt="Pencereyi Kapat" >';   
   innerText += '<img vspace="0" hspace="0" align="absmiddle" border="0" style="filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" src="javascript/imageslide/right.gif">';
   innerText += '</div>';
   innerText += '</center></td></tr></table>';   
   innerText += '</td></tr></table>';
   innerText += '</div>';
   
   this.slidewin.innerHTML = innerText;
   document.body.appendChild(this.slidewin);
};


function ShowUSlideShowImage( image , imagesarray , language ) {

    if( ug_uslideshow_popup != null ) {
	   ug_uslideshow_popup.ShowPopup( image , language  );
	   if( ug_uslideshow_popup.imageArray == null ) { 	
	      ug_uslideshow_popup.imageArray = imagesarray;
	   }
	   setTimeout( "ug_uslideshow_popup.on_imageload( "+image+")" , 100 );
	   setTimeout( "ug_uslideshow_popup.LoadSmallImages()" , 800 );
	}
}

USlideShowCtrl.prototype.OnImagePlayChange = function() {
  iPos = this.ShowIndex+ 1;
  if( iPos > (this.imageArray.length - 1 ) ) 
     iPos = 0;
  this.on_imageload( iPos );
  this.SlideTimerID = setTimeout( "ug_uslideshow_popup.OnImagePlayChange()" , 4000 );
}


USlideShowCtrl.prototype.OnPlayStop = function() {
  play = document.getElementById("global_uslideshowpopupid_btnplay");
  pause = document.getElementById("global_uslideshowpopupid_btnpause");
  if( play && pause ) {
	 if( this.SlideTimerID == null ) {
		pause.style.display = 'inline';
		play.style.display = 'none';
		this.SlideTimerID = setTimeout( "ug_uslideshow_popup.OnImagePlayChange()" , 4000 );
	 }
     else {		
	    clearTimeout( this.SlideTimerID );
		this.SlideTimerID = null;
		pause.style.display = 'none';
		play.style.display = 'inline';
	 }
  }
}


USlideShowCtrl.prototype.OnLeftPaneView = function() {
  lefttd = document.getElementById("global_uslideshowpopupid_leftpaneid");
  if( lefttd != null ) {
	 fulbtn = document.getElementById("global_uslideshowpopupid_btnfullpanel");
	 largebtn = document.getElementById("global_uslideshowpopupid_btnlargepanel");
	  
	 if( lefttd.style.display != 'none' ) {
	    lefttd.style.display = 'none';
		fulbtn.style.display = 'none';
		largebtn.style.display = 'inline';
	 }
     else {		
	    lefttd.style.display = 'block';
		fulbtn.style.display = 'inline';
		largebtn.style.display = 'none';
		
	 }
	 this.RefreshPosition();
  }
}

USlideShowCtrl.prototype.OnPrev = function() {
  if( this.ShowIndex > 0 ) {
	 this.on_imageload( this.ShowIndex - 1 );
  }
}

USlideShowCtrl.prototype.OnNext = function() {
  if( this.ShowIndex < (this.imageArray.length - 1 ) ) {
	 this.on_imageload( this.ShowIndex + 1 );
  }
}

USlideShowCtrl.prototype.OnLoadedImage = function() {
  yuklemediv = document.getElementById("global_uslideshowpopupid_imageviewdiv");
  image1 = document.getElementById("global_uslideshowpopupid_imageview1");
  image2 = document.getElementById("global_uslideshowpopupid_imageview2");
  wait = document.getElementById("global_uslideshowpopupid_imageviewwait");
  title = document.getElementById("global_uslideshowpopupid_imageviewtitle");
  
  if( navigator.appName == "Opera" ) {
     if(typeof image2.naturalWidth != "undefined" && image2.naturalWidth == 0 ) {
        setTimeout( "ug_uslideshow_popup.OnLoadedImage()" , 40 );
        return;
     }
	 
  }
  else {
	if( !image2.complete ) {    
       setTimeout( "ug_uslideshow_popup.OnLoadedImage()" , 40 );
	   return;
	}
  }
  
  str = '<center><span>'+this.imageArray[this.ShowIndex][1]+'</span></center>';  
  title.innerHTML = str;
  image1.src = image2.src;
  image1.style.display='block';
  wait.style.display='none';
}

USlideShowCtrl.prototype.on_imageload = function( iIndex ) {
  this.ShowIndex = iIndex;	
  yuklemediv = document.getElementById("global_uslideshowpopupid_imageviewdiv");
  wait = document.getElementById("global_uslideshowpopupid_imageviewwait");
  if( yuklemediv ) {
	 yuklemediv.innerHTML = '<img vspace="0" hspace="0" align="absmiddle" id="global_uslideshowpopupid_imageview2" completed="false" style="display:none;" alt="'+this.imageArray[this.ShowIndex][1]+'"src="std_pictureops.php?fl='+this.imageArray[this.ShowIndex][0]+'&xsize=570&ysize=440&sh=0&ln=0&pd=0" >';
	 wait.style.display='block';
	 setTimeout( "ug_uslideshow_popup.OnLoadedImage()" , 0 );
  }
}

USlideShowCtrl.prototype.LoadSmallImages = function() {
  panel = document.getElementById("global_uslideshowpopupid_smallpane");
  if( panel ) {
	 panel.innerHTML = '';
     for (var i=0; i < this.imageArray.length; i++) {
		 panel.innerHTML += '<center><img vspace="0" hspace="0" align="absmiddle" onclick="ug_uslideshow_popup.on_imageload( '+i+' );" style="padding-left:0px;cursor:pointer;" alt="'+this.imageArray[i][1]+'"src="std_pictureops.php?fl='+this.imageArray[i][0]+'&xsize=90&ysize=80&sh=2&ln=1&pd=0"></center><br>';
	 }
  }
}



USlideShowCtrl.prototype.ShowPopup = function ( image , language ) {
    inlineframe = document.getElementById('global_uslideshowpopupid_1frame');
	if( inlineframe )
	   inlineframe.style.display = 'block';
	   
    shadow = document.getElementById('global_uslideshowpopupid_Shadow');
	if( shadow )
	   shadow.style.display = 'block';

    this.slidewin.style.display = 'block';
	this.RefreshPosition();
};

USlideShowCtrl.prototype.RefreshPosition = function () {
	cxWin = window.innerWidth;
	scrollX = window.pageXOffset;
	if (navigator.appName == "Microsoft Internet Explorer") {
		if( document.documentElement.clientWidth ) {
    	   cxWin = document.documentElement.clientWidth;
		   scrollX = document.documentElement.scrollLeft;
		}
		else {
    	   cxWin = document.body.clientWidth;
		   scrollX = document.body.scrollLeft;
		}
		
	}
	

	cyWin = window.innerHeight;
	scrollY = window.pageYOffset;
	if (navigator.appName == "Microsoft Internet Explorer") {
		if( document.documentElement.clientWidth ) {		
    	   cyWin = document.documentElement.clientHeight;
		   scrollY = document.documentElement.scrollTop;
		}
		else {
    	   cyWin = document.body.clientHeight;
		   scrollY = document.body.scrollTop;
		}
		
	}


    //Range Belirleniyor...
	rx1 = scrollX;
	ry1 = scrollY;
	rx2 = rx1 + cxWin;
	ry2 = ry1 + cyWin;

	
    hCtrl = this.slidewin.offsetHeight;	
	wCtrl = this.slidewin.offsetWidth;	
	x1Pos = (cxWin - wCtrl ) / 2;
	y1Pos = (cyWin - hCtrl ) / 2;
	x1Pos += scrollX;
	y1Pos += scrollY;

	this.slidewin.style.left = x1Pos +'px'; 
    this.slidewin.style.top = y1Pos +'px'; 

    shadow = document.getElementById('global_uslideshowpopupid_Shadow');
    inlineframe = document.getElementById('global_uslideshowpopupid_1frame');
	
	waitimage = document.getElementById('global_uslideshowpopupid_imageviewwait');
	
	if( inlineframe && shadow ) {

	   inlineframe.style.left = 0 - x1Pos + scrollX +'px';
	   inlineframe.style.top = 0 - y1Pos + scrollY +'px';
	   inlineframe.style.width =  cxWin+'px';
	   inlineframe.style.height = cyWin +'px';
	   shadow.style.left = 0 - x1Pos + scrollX +'px';
	   shadow.style.top = 0 - y1Pos + scrollY +'px';
	   shadow.style.width =  cxWin+'px';
	   shadow.style.height = cyWin +'px';


       lefttd = document.getElementById("global_uslideshowpopupid_leftpaneid");
	   waitimage.style.top = 230 + 'px';
       if( lefttd != null && lefttd.style.display != 'none' ) 
	      waitimage.style.left = 420 + 'px';
	   else	  
	      waitimage.style.left = 290 + 'px';
	   
	   this.slidewin.style.zIndex = 1000;
	   shadow.style.zIndex = -1;
	   inlineframe.style.zIndex = -1; 
	}
}


USlideShowCtrl.prototype.HidePopup = function () {
  inlineframe = document.getElementById('global_uslideshowpopupid_1frame');
  if( inlineframe )
	 inlineframe.style.display = 'none';
	   
  shadow = document.getElementById('global_uslideshowpopupid_Shadow');
  if( shadow )
	 shadow.style.display = 'none';
  this.slidewin.style.display = 'none';
  
  if( this.SlideTimerID != null ) {
     clearTimeout(this.SlideTimerID);
     this.SlideTimerID = null;
  }
  
}

USlideShowCtrl.prototype.scrollsmallpanel = function() {
   panel.scrollTop += this.scrolAdim;	
   this.scrolTimeid = setTimeout( 'ug_uslideshow_popup.scrollsmallpanel()' , 40 );  
}

USlideShowCtrl.prototype.smallpanelover = function( event ) {
   
  panel = document.getElementById("global_uslideshowpopupid_smallpane");
  cyWin = window.innerHeight;
  scrollY = window.pageYOffset;
  if (navigator.appName == "Microsoft Internet Explorer") {
	 if( document.documentElement.clientWidth ) {		
   	    cyWin = document.documentElement.clientHeight;
	    scrollY = document.documentElement.scrollTop;
	 }
	 else {
   	    cyWin = document.body.clientHeight;
	    scrollY = document.body.scrollTop;
	 }
  }
  
  tempY = 0;
  if (navigator.appName == "Microsoft Internet Explorer") {
	tempY = event.clientY;
  } 
  else {
    tempY = event.pageY - scrollY;
  }  
  
  
  if( tempY > ( cyWin / 2 ) ) {
	 uzaklik = tempY - ( cyWin / 2 ); 
	 this.scrolAdim = 0;
	 if( uzaklik > 30 )
	    this.scrolAdim = 1;   
	 if( uzaklik > 60 )
	    this.scrolAdim = 2;   
	 if( uzaklik > 90 )
	    this.scrolAdim = 3;   
	 if( uzaklik > 120 )
	    this.scrolAdim = 5;   
	 if( uzaklik > 150 )
	    this.scrolAdim = 7;   
	 if( uzaklik > 180 )
	    this.scrolAdim = 10;   
  }
  else 
  if( tempY <= ( cyWin / 2 ) ) {
	 uzaklik = ( cyWin / 2 ) - tempY; 
	 this.scrolAdim = 0;
	 if( uzaklik > 30 )
	    this.scrolAdim = -1;   
	 if( uzaklik > 60 )
	    this.scrolAdim = -2;   
	 if( uzaklik > 90 )
	    this.scrolAdim = -3;   
	 if( uzaklik > 120 )
	    this.scrolAdim = -5;   
	 if( uzaklik > 150 )
	    this.scrolAdim = -7;   
	 if( uzaklik > 180 )
	    this.scrolAdim = -10;   
  }
  
  if( panel ) {
	 if( this.scrolTimeid == null )
	    this.scrolTimeid = setTimeout( 'ug_uslideshow_popup.scrollsmallpanel()' , 40 );  
  }
}
