﻿// TODOZA MAX STUDIO * 2007
// 2007.07.05
// TDZ @ http://www.todozacom/ 
// TDZ @ zafercul@hotmail.com

function todozacomswitch(obj) {
 TDZon[obj]=((TDZon[obj])?(0):(1));
 return TDZon[obj];
}

function todozacomif(obj,highres) {
 if(TDZon[obj]) {todozacom(obj,highres);}
}

function todozacom(obj,highres) {
 todozacomratio=todozacomheight/todozacomwidth;
 if(todozacomoffsetx > 1) {
  todozacomoffset='dumb';
  todozacomoffsetx=todozacomoffsetx/todozacomwidth;
  todozacomoffsety=todozacomoffsety/todozacomheight;
 }
 if(!obj.style.width) {
  if(obj.width > 0) {
   //educated guess
   obj.style.width=obj.width+'px';
   obj.style.height=obj.height+'px';
  }
 }
 if(typeof(highres) != typeof('')) {highres=obj.src}
 var TDZstage=document.createElement("div");
 TDZstage.style.width=obj.style.width;
 TDZstage.style.height=obj.style.height;
 TDZstage.style.overflow='hidden';
 TDZstage.style.position='absolute';
 if(typeof(TDZstage.style.filter) != typeof(nosuchthing)) {
  //hi IE
  if(navigator.appVersion.indexOf('Mac') == -1) { //hi Mac IE
   TDZstage.style.filter='alpha(opacity=0)';
   TDZstage.style.backgroundColor='#ffffff';
  }
 } else {
  //hi decent gentlemen
  TDZstage.style.backgroundImage='transparent';
 }
 TDZstage.setAttribute('onmousemove','TDZhandlemouse(event,this);');
 TDZstage.setAttribute('onmousedown','TDZhandlemouse(event,this);');
 TDZstage.setAttribute('onmouseup','TDZhandlemouse(event,this);');
 TDZstage.setAttribute('onmouseout','TDZhandlemouse(event,this);');
 if(navigator.userAgent.indexOf('MSIE')>-1) {
  TDZstage.onmousemove = function() {TDZhandlemouse(event,this);}
  TDZstage.onmousedown = function() {TDZhandlemouse(event,this);}
  TDZstage.onmouseup = function() {TDZhandlemouse(event,this);}
  TDZstage.onmouseout = function() {TDZhandlemouse(event,this);}
 }
 obj.parentNode.insertBefore(TDZstage,obj);
 
 TDZwin=document.createElement("div");
 TDZwin.style.width='0px';
 TDZwin.style.height='0px';
 TDZwin.style.overflow='hidden';
 TDZwin.style.position='absolute';
 TDZwin.style.display='none';
 tw1='<div style="position:absolute;overflow:hidden;margin:';
 TDZwin.innerHTML= 
 tw1+TDZshadowthick+'px 0 0 '+TDZshadowthick+'px; background-color:'+TDZbordercolor+'; width:'+(todozacomwidth-TDZshadowthick*2)+'px;height:'+(todozacomheight-TDZshadowthick*2)+'px"></div>' +
 tw1+(TDZshadowthick+TDZborderthick)+'px 0 0 '+(TDZshadowthick+TDZborderthick)+'px; width:'+(todozacomwidth-TDZshadowthick*2-TDZborderthick*2)+'px;height:'+(todozacomheight-TDZshadowthick*2-TDZborderthick*2)+'px;"><img src="'+obj.src+'" style="position:absolute;margin:0;padding:0;border:0; width:'+(todozacomamount*parseInt(obj.style.width))+'px;height:'+(todozacomamount*parseInt(obj.style.height))+'px;" />'+((obj.src!=highres)?('<img src="'+highres+'" style="position:absolute;margin:0;padding:0;border:0; width:'+(todozacomamount*parseInt(obj.style.width))+'px;height:'+(todozacomamount*parseInt(obj.style.height))+'px;" onload="if(this.parentNode) {this.parentNode.parentNode.getElementsByTagName(\'div\')[2].style.display=\'none\';}" />'):(''))+'</div>';
 if(highres != obj.src) {
  TDZwin.innerHTML+='<div style="position:absolute; margin:'+(TDZshadowthick+TDZborderthick)+'px 0 0 '+(TDZshadowthick+TDZborderthick)+'px;">'+TDZloading+'</div>';
 }
 if(TDZshadowthick>0) {
  st1='<span style="position:absolute; display:inline-block; margin: ';
  st2='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\'scale\',src='
  st3='filter:alpha(opacity=0);margin:0;padding:0;border:0;"/></span>';
  TDZwin.innerHTML+=
  st1+'0 0 0 0    ; width:'+TDZshadowthick*2+'px; height:'+TDZshadowthick*2+'px;'+st2+'\''+TDZshadow+'nw.png\')"><img src="'+TDZshadow+'nw.png" style="width:'+TDZshadowthick*2+'px; height:'+TDZshadowthick*2+'px;'+st3 +
  st1+'0 0 0 '+(todozacomwidth-TDZshadowthick*2)+'px; width:'+TDZshadowthick*2+'px; height:'+TDZshadowthick*2+'px;'+st2+'\''+TDZshadow+'ne.png\')"><img src="'+TDZshadow+'ne.png" style="width:'+TDZshadowthick*2+'px; height:'+TDZshadowthick*2+'px;'+st3 +
  st1+''+(todozacomheight-TDZshadowthick*2)+'px 0 0 0px; width:'+TDZshadowthick*2+'px; height:'+TDZshadowthick*2+'px;'+st2+'\''+TDZshadow+'sw.png\',sizingMethod=\'scale\')"><img src="'+TDZshadow+'sw.png" style="width:'+TDZshadowthick*2+'px; height:'+TDZshadowthick*2+'px;'+st3 +
  st1+''+(todozacomheight-TDZshadowthick*2)+'px 0 0 '+(todozacomwidth-TDZshadowthick*2)+'px; width:'+TDZshadowthick*2+'px; height:'+TDZshadowthick*2+'px;'+st2+'\''+TDZshadow+'se.png\',sizingMethod=\'scale\')"><img src="'+TDZshadow+'se.png" style="width:'+TDZshadowthick*2+'px; height:'+TDZshadowthick*2+'px;'+st3 +
  
  st1+'0 0 0 '+(TDZshadowthick*2)+'px; width:'+(todozacomwidth-TDZshadowthick*4)+'px; height:'+TDZshadowthick*2+'px;'+st2+'\''+TDZshadow+'n.png\',sizingMethod=\'scale\')"><img src="'+TDZshadow+'n.png" style="width:'+(todozacomwidth-TDZshadowthick*4)+'px; height:'+TDZshadowthick*2+'px;'+st3 +
  st1+''+(TDZshadowthick*2)+'px 0 0 0; width:'+(TDZshadowthick*2)+'px; height:'+(todozacomheight-TDZshadowthick*4)+'px;'+st2+'\''+TDZshadow+'w.png\',sizingMethod=\'scale\')"><img src="'+TDZshadow+'w.png" style="width:'+(TDZshadowthick*2)+'px; height:'+(todozacomheight-TDZshadowthick*4)+'px;'+st3 +
  st1+''+(TDZshadowthick*2)+'px 0 0 '+(todozacomwidth-TDZshadowthick*2)+'px; width:'+(TDZshadowthick*2)+'px; height:'+(todozacomheight-TDZshadowthick*4)+'px;'+st2+'\''+TDZshadow+'e.png\',sizingMethod=\'scale\')"><img src="'+TDZshadow+'e.png" style="width:'+(TDZshadowthick*2)+'px; height:'+(todozacomheight-TDZshadowthick*4)+'px;'+st3 +
  st1+''+(todozacomheight-TDZshadowthick*2)+'px 0 0 '+(TDZshadowthick*2)+'px; width:'+(todozacomwidth-TDZshadowthick*4)+'px; height:'+TDZshadowthick*2+'px;'+st2+'\''+TDZshadow+'s.png\',sizingMethod=\'scale\')"><img src="'+TDZshadow+'s.png" style="width:'+(todozacomwidth-TDZshadowthick*4)+'px; height:'+TDZshadowthick*2+'px;'+st3;
 }
 ;
 //marker - zoomer
 obj.parentNode.insertBefore(TDZwin,TDZstage);

 TDZresize(obj);
}

function TDZresize(obj) {
 sbr=0; sbl=0;
 if(todozacomwidth-2*TDZborderthick-3*TDZshadowthick < 22) {sbr=1}
 if(todozacomheight-2*TDZborderthick-3*TDZshadowthick < 22) {sbr=1}
 if(todozacomwidth > parseFloat(obj.style.width)) {sbl=1;}
 if(todozacomheight > parseFloat(obj.style.height)) {sbl=1}
 
 if(sbr==1 && sbl == 1) {
  todozacomwidth=parseFloat(obj.style.width)/2;
  todozacomheight=parseFloat(obj.style.height)/2;
  todozacomratio=todozacomheight/todozacomwidth;
 }

 if(sbr==1) {
  if(todozacomwidth<todozacomheight) {
   todozacomheight=todozacomheight/todozacomwidth*(22+2*TDZborderthick+3*TDZshadowthick); todozacomwidth=22+2*TDZborderthick+3*TDZshadowthick;
  } else {
   todozacomwidth=todozacomwidth/todozacomheight*(22+2*TDZborderthick+3*TDZshadowthick); todozacomheight=22+2*TDZborderthick+3*TDZshadowthick;
  }
 }
 

 if(sbl==1) {
  if(parseFloat(obj.style.width)/parseFloat(obj.style.height) > todozacomwidth/todozacomheight) {
   todozacomheight=parseFloat(obj.style.height);
   todozacomwidth=todozacomheight/todozacomratio;
  } else {
   todozacomwidth=parseFloat(obj.style.width);
   todozacomheight=todozacomratio*todozacomwidth;
  }
 }

 todozacomwidth=Math.floor(todozacomwidth/2)*2;
 todozacomheight=Math.floor(todozacomheight/2)*2;

 ww=obj.parentNode.getElementsByTagName('div')[0];
 ww.style.width=todozacomwidth+'px';
 ww.style.height=todozacomheight+'px';
 w=ww.getElementsByTagName('div')[0];
 w.style.width=todozacomwidth-TDZshadowthick*2+'px';
 w.style.height=todozacomheight-TDZshadowthick*2+'px';
 w=ww.getElementsByTagName('div')[1];
 w.style.width=todozacomwidth-TDZshadowthick*2-TDZborderthick*2+'px';
 w.style.height=todozacomheight-TDZshadowthick*2-TDZborderthick*2+'px';
 if(TDZshadowthick > 0) {
  w=ww.getElementsByTagName('span')[1]; w.style.margin='0 0 0 '+(todozacomwidth-TDZshadowthick*2)+'px';
  w=ww.getElementsByTagName('span')[2]; w.style.margin=(todozacomheight-TDZshadowthick*2)+'px 0 0 0px';
  w=ww.getElementsByTagName('span')[3]; w.style.margin=(todozacomheight-TDZshadowthick*2)+'px 0 0 '+(todozacomwidth-TDZshadowthick*2)+'px';

  w=ww.getElementsByTagName('span')[6]; w.style.margin=(TDZshadowthick*2)+'px 0 0 '+(todozacomwidth-TDZshadowthick*2)+'px';
  w=ww.getElementsByTagName('span')[7]; w.style.margin=(todozacomheight-TDZshadowthick*2)+'px 0 0 '+(TDZshadowthick*2)+'px';

  www=(todozacomwidth-TDZshadowthick*4)+'px';
  w=ww.getElementsByTagName('span')[4]; w.style.width=www;
  w=w.getElementsByTagName('img')[0]; w.style.width=www;
  w=ww.getElementsByTagName('span')[7]; w.style.width=www;
  w=w.getElementsByTagName('img')[0]; w.style.width=www;
  
  www=(todozacomheight-TDZshadowthick*4)+'px';
  w=ww.getElementsByTagName('span')[5]; w.style.height=www;
  w=w.getElementsByTagName('img')[0]; w.style.height=www;
  w=ww.getElementsByTagName('span')[6]; w.style.height=www;
  w=w.getElementsByTagName('img')[0]; w.style.height=www;
 }
}

function TDZfindposy(obj) {
 var curtop = 0;
 if(!obj) {return 0;}
 if (obj.offsetParent) {
  while (obj.offsetParent) {
   curtop += obj.offsetTop
   obj = obj.offsetParent;
  }
 } else if (obj.y) {
  curtop += obj.y;
 }
 return curtop;
}

function TDZfindposx(obj) {
 var curleft = 0;
 if(!obj) {return 0;}
 if (obj && obj.offsetParent) {
  while (obj.offsetParent) {
   curleft += obj.offsetLeft
   obj = obj.offsetParent;
  }
 } else if (obj.x) {
  curleft += obj.x;
 }
 return curleft;
}


function TDZhandlemouse(evt,obj) {
 var evt = evt?evt:window.event?window.event:null; if(!evt) { return false; }
 if(evt.pageX) {
  nowx=evt.pageX-TDZfindposx(obj)-TDZadjustx;
  nowy=evt.pageY-TDZfindposy(obj)-TDZadjusty;
 } else {
  if(document.documentElement && document.documentElement.scrollTop) {
   nowx=evt.clientX+document.documentElement.scrollLeft-TDZfindposx(obj)-TDZadjustx;
   nowy=evt.clientY+document.documentElement.scrollTop-TDZfindposy(obj)-TDZadjusty;
  } else {
   nowx=evt.x+document.body.scrollLeft-TDZfindposx(obj)-TDZadjustx;
   nowy=evt.y+document.body.scrollTop-TDZfindposy(obj)-TDZadjusty;
  }
 }
 if(evt.type == 'mousemove') {
  TDZsetwin(obj,nowx,nowy);
 } else if(evt.type == 'mousedown') {
  TDZmouse=1; //left: 1, middle: 2, right: 3
  TDZmousey=nowy;
  TDZmousex=nowx;
 } else if(evt.type =='mouseup') {
  TDZmouse=0;
 } else if(evt.type =='mouseout') {
  TDZmouse=0;
  if(navigator.appVersion.indexOf('Mac') == -1 || navigator.appVersion.indexOf('MSIE') == -1) { //hi Mac IE
   x=obj.parentNode;
   x.removeChild(x.getElementsByTagName('div')[0]);
   x.removeChild(x.getElementsByTagName('div')[0]);
  }
 }
}


// todozacom 3 * János Pál Tóth
// Docs @ http://valid.TDZ.hu/todozacom/ 
// News @ http://todozacom.blogspot.com/


function TDZsetwin(obj,nowx,nowy) {
 obj.parentNode.getElementsByTagName('div')[0].style.display='block';
 if(todozacomoffset=='smart') {
  todozacomoffsetx=.1+.8*nowx/parseFloat(obj.style.width);
  todozacomoffsety=.1+.8*nowy/parseFloat(obj.style.height);
 }

 stage=obj.parentNode.getElementsByTagName('div')[0];
 if(TDZmouse == 1) {
  if(Math.abs(nowy-TDZmousey) >= 1) {
   todozacomamount*=((nowy>TDZmousey)?(0.909):(1.1));
   TDZmousey=nowy;
   if(todozacomamount < todozacomamountmin) {todozacomamount=todozacomamountmin;}
   if(todozacomamount > todozacomamountmax) {todozacomamount=todozacomamountmax;}
   stage.getElementsByTagName('div')[1].getElementsByTagName('img')[0].style.width=  parseInt(obj.style.width)*todozacomamount+'px';
   stage.getElementsByTagName('div')[1].getElementsByTagName('img')[0].style.height=  parseInt(obj.style.height)*todozacomamount+'px';
   if(stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1]) {
    stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1].style.width= stage.getElementsByTagName('div')[1].getElementsByTagName('img')[0].style.width;
    stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1].style.height= stage.getElementsByTagName('div')[1].getElementsByTagName('img')[0].style.height;
   }
  }
  if(Math.abs(nowx-TDZmousex) >= 12 && todozacomwindowlock==0) {
   todozacomwidth*=((nowx>TDZmousex)?(1.1):(0.909));
   todozacomheight=todozacomwidth*todozacomratio;
   TDZresize(obj);
   TDZmousex=nowx;
  }
 }
 stage.style.marginLeft=nowx-(todozacomwidth -2*TDZborderthick-2*TDZshadowthick)*todozacomoffsetx-TDZborderthick-TDZshadowthick+'px';
 stage.style.marginTop= nowy-(todozacomheight-2*TDZborderthick-2*TDZshadowthick)*todozacomoffsety-TDZborderthick-TDZshadowthick+'px';
 clip1=0; clip2=todozacomwidth; clip3=todozacomheight; clip4=0;
 nwidth=todozacomwidth; nheight=todozacomheight;
 tmp=(1-2*todozacomoffsetx)*(TDZborderthick+TDZshadowthick);
 
 if(nowx-todozacomwidth*todozacomoffsetx < tmp) {
  clip4=todozacomwidth*todozacomoffsetx-nowx + tmp;
 } else if(parseFloat(nowx-todozacomwidth*todozacomoffsetx+todozacomwidth) > parseFloat(obj.style.width)+tmp) {
  clip2= todozacomwidth*todozacomoffsetx - nowx + parseFloat(obj.style.width)+tmp;
  nwidth=todozacomwidth*todozacomoffsetx-nowx+parseInt(obj.style.width)+TDZborderthick+TDZshadowthick;
 }
 
 tmp=(1-2*todozacomoffsety)*(TDZborderthick+TDZshadowthick);
 
 if(nowy-todozacomheight*todozacomoffsety < tmp) {
  clip1=todozacomheight*todozacomoffsety-nowy+tmp;
 } else if(parseFloat(nowy-todozacomheight*todozacomoffsety+todozacomheight) > parseFloat(obj.style.height)+tmp) {
  clip3= todozacomheight*todozacomoffsety - nowy + parseFloat(obj.style.height)+tmp;
  nheight=todozacomheight*todozacomoffsety - nowy + parseFloat(obj.style.height)+TDZborderthick+TDZshadowthick;
 }
 stage.style.width=nwidth+'px';
 stage.style.height=nheight+'px';

 stage.style.clip='rect('+clip1+'px,'+clip2+'px,'+clip3+'px,'+clip4+'px)';

 if(nowy-todozacomoffsety*(todozacomheight-2*TDZborderthick-2*TDZshadowthick) < 0) { t=-(nowy-todozacomoffsety*(todozacomheight-2*TDZborderthick-2*TDZshadowthick))} 
 else if(nowy-todozacomoffsety*(todozacomheight-2*TDZborderthick-2*TDZshadowthick) > parseFloat(obj.style.height)-todozacomheight+TDZborderthick*2+TDZshadowthick*2) { t=-todozacomamount*parseFloat(obj.style.height)+todozacomheight-TDZborderthick*2-TDZshadowthick*2-((nowy-todozacomoffsety*(todozacomheight-2*TDZborderthick-2*TDZshadowthick))-(parseFloat(obj.style.height)-todozacomheight+TDZborderthick*2+TDZshadowthick*2)); }
 else { t=(-todozacomamount*parseFloat(obj.style.height)+todozacomheight-TDZborderthick*2-TDZshadowthick*2)/(parseFloat(obj.style.height)-todozacomheight+TDZborderthick*2+TDZshadowthick*2)*(nowy-todozacomoffsety*(todozacomheight-2*TDZborderthick-2*TDZshadowthick)) }
 stage.getElementsByTagName('div')[1].getElementsByTagName('img')[0].style.marginTop=t+'px';

 if(stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1]) {
  stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1].style.marginTop=t+'px';
 }

 if(nowx-todozacomoffsetx*(todozacomwidth-2*TDZborderthick-2*TDZshadowthick) < 0) { t=-(nowx-todozacomoffsetx*(todozacomwidth-2*TDZborderthick-2*TDZshadowthick))} 
 else if(nowx-todozacomoffsetx*(todozacomwidth-2*TDZborderthick-2*TDZshadowthick) > parseFloat(obj.style.width)-todozacomwidth+TDZborderthick*2+TDZshadowthick*2) { t=-todozacomamount*parseFloat(obj.style.width)+todozacomwidth-TDZborderthick*2-TDZshadowthick*2-((nowx-todozacomoffsetx*(todozacomwidth-2*TDZborderthick-2*TDZshadowthick))-(parseFloat(obj.style.width)-todozacomwidth+TDZborderthick*2+TDZshadowthick*2)); }
 else { t=(-todozacomamount*parseFloat(obj.style.width)+todozacomwidth-TDZborderthick*2-TDZshadowthick*2)/(parseFloat(obj.style.width)-todozacomwidth+TDZborderthick*2+TDZshadowthick*2)*(nowx-todozacomoffsetx*(todozacomwidth-2*TDZborderthick-2*TDZshadowthick)) }
 stage.getElementsByTagName('div')[1].getElementsByTagName('img')[0].style.marginLeft=t+'px';

 if(stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1]) {
  stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1].style.marginLeft=t+'px';
 }
}

function TDZinit() {
 TDZadjustx=0; TDZadjusty=0;
 if(navigator.userAgent.indexOf('MSIE')>-1) {TDZadjustx=2;TDZadjusty=2;}
 if(navigator.userAgent.indexOf('Opera')>-1) {TDZadjustx=0; TDZadjusty=0;}
 if(navigator.userAgent.indexOf('Safari')>-1) {TDZadjustx=1; TDZadjusty=2;}
}

// configuration - do not modify the following, instead read the behaviors.html file in the tutorial!
var TDZon=new Array();
var TDZadjustx,TDZadjusty;
var TDZmouse=0; var TDZmousey; var TDZmousex;
var TDZloading='<div style="background-color: #ffeb77; color: #333333; padding:2px; font-family: verdana,arial,helvetica; font-size: 10px;">Yükleniyor...</div>';

var todozacomwidth=175;
var todozacomheight=125;
var todozacomratio;
var todozacomwindowlock=0;

var todozacomoffsetx=.3;
var todozacomoffsety=.3;
var todozacomoffset;

var todozacomamount=4;
var todozacomamountmax=12;
var todozacomamountmin=1;

var TDZborderthick=1;
var TDZbordercolor='silver';

var TDZshadowthick=1;
var TDZshadow='dropshadow/';

TDZinit();


