var imgHeight = 580;
var imgWidth = 855;
var imgRatio = imgWidth/imgHeight;
var heightPad = 104+86;
var widthPad = 188+111+3;
var widthOk = 25;
var cw;
var ch;
var frameSx = 0;
var timeOut = null;
$(document).ready(function(){
	resTable();
	$("#okNext").mousedown(function(){
		timeOut = setTimeout('scrollRight()',0);
	});
	$("#okNext").mouseup(function(){
		clearTimeout(timeOut);
	});	
	$("#okPrev").mousedown(function(){
		timeOut = setTimeout('scrollLeft()',0);
	});
	$("#okPrev").mouseup(function(){
		clearTimeout(timeOut);
	});
	$("#project-link").mousemove(function(e){
		var top = $(this).position().top;
		var margin = $(this).css("margin-top").replace("px","");
		var y = e.clientY - top - margin;
		//$("#mp").html(top + " " + margin + " " + y);
		$("#project-link").scrollTop(y-11);
	});
});
$(window).resize(function(){
	resTable();
});
function scrollRight() {
	var iFrame = document.getElementById("iframeGorsel");
	iFrame.contentWindow.scrollBy(112,0);
	//alert(iFrame.contentWindow.document.kResim.width);
	timeOut = setTimeout("scrollRight()", 50);
	}
function scrollLeft() {
	var iFrame = document.getElementById("iframeGorsel");
	iFrame.contentWindow.scrollBy(-112,0);
	timeOut = setTimeout("scrollLeft()", 50);
	}
function resTable(){
	imgRatio = $("#bimg").width() / $("#bimg").height();
	cw = document.body.clientWidth-10;
	ch = document.body.clientHeight-58;
	if (cw >= 1100) $("#tmain").width(1100);
	else $("#tmain").width(cw);
	nh = ch-heightPad;
	nw = Math.floor(nh*imgRatio);
	if (nw+widthPad > cw) {
		nw = cw-widthPad;
		nh = nw/imgRatio;
		}
	$("#bimg").width(nw);
	$("#bimg").height(nh);
	$("#div-bimg").height(nh);
	$("#div-bimg").width(nw);
	//$("#project-info").width(nw);
	$("#frameGorsel").width(nw-widthOk);
	$("#td-base").height(ch);
	$("#project-link").height(ch-90);
	$("#tmain td:eq(0)").height(ch+30);
	
	$("#project-link").scrollTop($("#project-link > a.active").position().top - $("#project-link").position().top - $("#project-link").css("margin-top").replace("px",""));
	//$("#tdmsg").html(cw+'x'+ch+':'+nh);
	}
function f_img_replace(resim) {
	var w = $("#bimg").width();
	var h = $("#bimg").height();
	
	if ($("#div-video").length) {
		$("#div-video").fadeOut("fast", function(){
			$("#div-video").html("");
		});
	}
	
	$("#bimg").fadeOut("fast", function(){
		if (resim.substr(-3) == 'flv') {
			$.get("../show_video.php", {flv : resim}, 
				function(data){
					$("#div-video").html(data).fadeIn("fast");
					}
				);
			}
		else {
			$(this).attr("src",'../img_upload/'+resim).load(function(){$(this).fadeIn("fast");});
			}
		});
	}
