// JavaScript Document
var dI = 0;
var pCount = 1;
function g(id){
	return document.getElementById(id);
}
function fixSize() {
	var h = 0;
	var w = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		h = window.innerHeight;
		w = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		h = document.documentElement.clientHeight;
		w = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		h = document.body.clientHeight;
		w = document.body.clientWidth;
	}
	g("m").style.height = h+"px";
	g("t").style.height = h-183+"px";
	g("ii").style.height = h-120+"px";
	g("bnr").style.right = (w/2)-324+"px";
	g("loading").style.right = (w/2)-324+"px";
	if(g("bnr_s")){g("bnr_s").style.right = (w/2)-328+"px";}
}

function maxWindow(){
	window.moveTo(0,0);
	if (document.all)
	{
	  top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||g)
	{
	  if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
	  {
		top.window.outerHeight = screen.availHeight;
		top.window.outerWidth = screen.availWidth;
	  }
	}
}

function loadThumbs(){
	var issue = g("i");
	var pageCount = issue.options[issue.selectedIndex].value;
	var thumbsFolder = "issue_"+ (issue.selectedIndex + 1) +"/thumbs/";
	pCount = pageCount;
	var arrTable = [];
	var l;
	var n;
	arrTable.push("<table cellpadding='0' cellspacing='10' border='0'>");
	for(x=0;x<=pageCount;x++){
		l = String(x).length;
		if (l == 1){n="00"+x;}
		if (l == 2){n="0"+x;}
		arrTable.push("<tr><td class='borderGray' onmouseover='changeBorder(this);' onmouseout='changeBorder(this);'><img src='");
		arrTable.push(thumbsFolder);
		arrTable.push("t_");
		arrTable.push(n);
		arrTable.push(".jpg' width='80' height='113' class='thumb' alt='Sayfa ");
		arrTable.push(x);
		arrTable.push("' onclick='loadPageImage(\"");
		arrTable.push(n)
		arrTable.push("\")'></td></tr>");
	}
	arrTable.push("</table>");
	
	g("t").innerHTML = arrTable.join("");
}

function loadPageImage(id){
	var issue = g("i");
	var pagesFolder = "issue_"+ (issue.selectedIndex + 1) +"/pages/";
	var img = g("p");
	var loading = g("loading");
	var btnP = g("b");
	var btnN = g("bb");
	var imgDiv = g("ii");
	var l = String(id).length;
	if (l == 1){id="00"+id;}
	if (l == 2){id="0"+id;}
	img.style.display = "none";
	loading.innerHTML = "Yükleniyor ...";
	loading.style.display = "block";
	
	img.onload = function(){
		this.style.display = "block";
		loading.style.display = "none";
	}
	img.src = pagesFolder+"p_"+ id +".jpg";
	dI = id;
	btnP.firstChild.className = dI <= 0 ? "btn_dis" : "btni";
	btnN.firstChild.className = dI >= pCount ? "btn_dis" : "btni";
	
	
	img.onerror = function(){
		loading.innerHTML = "Resim Yüklenemedi";
	}
	g("cPage").firstChild.innerHTML = "Sayfa : "+ parseFloat(dI);
}

function npImg(s){
	if (s == 0){
		dI--;
	}else{
		dI++;
	}
	dI = (dI < 0)? 0 : (dI>pCount)?pCount:dI;
	loadPageImage(dI);
}

function init(){
	fixSize();
	loadThumbs();
	s();
	loadPageImage("000");
}
function fl(strUrl, intWidth, intHeight) {
	var tmp = '';
		tmp += ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ intWidth +'" height="'+ intHeight +'">'+
				'	<param name="movie" value="'+ strUrl +'" />'+
				'	<param name="quality" value="high" />'+
				'	<param name="wMode" value="transparent" />'+
				'	<embed src="'+ strUrl +'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ intWidth +'" height="'+ intHeight +'"></embed>'+
				'</object>');
	document.write(tmp);
}
function s(){
	var divs = document.getElementsByTagName('div');
	var l,r,t,w,h; 
	var sDiv = "";
	
	for(var i=0;i<divs.length;i++){
		if (divs[i].className.indexOf("shadowed") != -1){
			l=(divs[i].style.left)?"left:"+ parseInt(parseInt(divs[i].style.left)+4) +"px; ":"";
			r=(divs[i].style.right)?"right:"+ parseInt(parseInt(divs[i].style.right)-4) +"px; ":"";
			t=(divs[i].style.top)?"top:"+ parseInt(parseInt(divs[i].style.top)+4) +"px; ":"";
			w=(divs[i].style.width)?"width:"+divs[i].style.width+";":"";
			h=(divs[i].style.height)?"height:"+divs[i].style.height+";":"";
			z="z-index:"+parseInt(100-i);
			divs[i].style.zIndex = parseInt(200-i);
			sDiv += "<div style='"+ l + r + t + w + h + z +"' id='"+ divs[i].id +"_s' class='shadow'></div>";
		}
	}
	document.getElementById("mainTd").innerHTML += sDiv;
}

function changeBorder(td){
	td.className = td.className == "borderGray" ? "borderOver":"borderGray";
}
try{
	maxWindow();
	onload = init;
	onresize = fixSize;
}catch(e){
}	