Array.prototype.sum = function(){for(var i=0,sum=0;i<this.length;sum+=this[i++]);return sum;}
pics=[];//Her proje icindeki resimler bu arraya konaca 'a.jpg,b.jpg', 'c.jpg,d.jpg'
prjid=[];//Her thumbnailin hangi projeye ait oldugunu saklar
musteriler=[];//Her thumbnailin hangi projeye ait oldugunu saklar
projesegment=[]; projeisim=[]; projeid=[]; projemusteri=[]; projemusteriisim=[]; projeurl=[]; projesira=[];
slidemax=0;slideson=0;

function picloaded(hangi){//Resimler yuklendiginde fade-in olsun
	//pics[hangi]=1
	//if (pics.sum()==pics.length) {
	yuklenecek=yuklenecek-1
	//$('dummy').innerHTML=yuklenecek
	if (!yuklenecek>0) {
		new Effect.Fade('loading', { duration:0} );
		$('gallerynavigation').appear()
		//$('loading').hide()	
	}
}

function proje (what){//Proje kapagi tiklaninca galerinin iteklenmesi, resimlerin ve navigasyonun hazirlanmasi.
	new Effect.Move($('kapaklar'), { x: -951, y: 0, mode: 'absolute', duration:0.4 })
	new Effect.Move($('resimler'), { x:0, y:0, mode: 'absolute', duration:0.4 });
	var d = $('resimler')
	var pl = $('picturelinks')
	piclist=pics[what]
	yuklenecek=piclist.length -1 //resim listesi arraylerinin sonunda bos bir "" var diye.
	if (yuklenecek>1) $('ileri').appear();
	d.innerHTML=""
	pl.innerHTML=""
	digerisler=otherprojects(what)
	for (z=0;z<yuklenecek;z++){
		zz=z+1
		d.innerHTML+='<div class="photo">' +digerisler+ '<img src="../urunler/' +piclist[z]+ '" onload="picloaded(0);"/></div>';
		pl.innerHTML+='<a href="#" id="link'+z+'"onclick="var gz=z;slide('+z+');return false;">' +zz+ '</a>';
		if (z<yuklenecek-1){pl.innerHTML+=' | ';}
		digerisler=''
	}
	slidemax=z-1
	slideson=0
	$('link0').style.color='#FF00CC';
	if (yuklenecek) new Effect.Appear('loading', {duration:0.1 });
	//alert (Prototype.Browser.Gecko)
	if (getScrollXY()>135) {window.scroll(0,135);}
}

function slide(hangi){//Portfoy resimleri arasinda gecisler (alttaki rakamlar ya da ileri-geri butonlariyla)
	if (hangi=='geri') hangi=slideson-1
	if (hangi=='ileri') hangi=slideson+1
	if (hangi<0) {hangi=0;}
	if (hangi>slidemax) {hangi=slidemax;}
	if (hangi==0) {$('geri').fade();} else {$('geri').appear();}
	if (hangi==slidemax) {$('ileri').fade();} else {$('ileri').appear();}
	yenix=-hangi*950
	new Effect.Move($('resimler'), { x: yenix, y: 0, duration:0.5, mode:'absolute' });
	slideson=hangi
	for (z=0;z<slidemax+1;z++){$('link'+z).style.color='#333333';}
	$('link'+hangi).style.color='#FF00CC';
}

function backtogallery(){//Portfoyde bir proje resimlerinden galeriye donmek
	$('geri').fade(); $('ileri').fade();
	new Effect.Move($('resimler'), { x:950, y:0, mode: 'absolute', duration:0.5})
	new Effect.Move($('kapaklar'), { x:0, y: 0, mode: 'absolute', duration:0.7 })
	$('gallerynavigation').hide()
	$('loading').hide()
	//pics=[]
	piclist=[]
	//$('resimler').parentNode.removeChild()

}

function otherprojects(what){//Portfoyde projeye bakarken o musteriye yapilan diger islerin listelenmesi
	musteri=musteriler[what]
	projeno=prjid[what]
	ektag=""; ektag2=""; ektagson="";
	for (m=0;m<projeid.length;m++){
		if (projemusteri[m]==musteri && projeid[m]!=projeno){
			xseg=projesegment[m]; xisim=projeisim[m]; xprjid=projeid[m];
			xmustid=projemusteri[m]; xmustisim=projemusteriisim[m];
			if (xseg==localsegment) {xurl="javascript:proje('"+projesira[xprjid]+"')";}
				else {xurl="portfoy.php?sid=" +xseg+ "&projeid=" +xprjid;}
			if (xseg==2) {xurl="portfoy-editorluk.php";}
			ektag +='<a href="' +xurl+ '">' +xisim+ '</a><br />'
		}
		if (projeid[m]==projeno && projeurl[m].length>10){
			if (projeurl[m].substr(0,7) !='http://') {projeurl[m]="http://"+projeurl[m];}
			if (lang=='tr') ektag2='<div id="projelink"><a href="'+projeurl[m]+'" target="_blank">Ürünü ziyaret etmek için</a></div>';
			if (lang=='en') ektag2='<div id="projelink"><a href="'+projeurl[m]+'" target="_blank">View the online product</a></div>';
		}
	}
	//alert(ektag);alert(ektag2);
	if (lang=="tr"){
		if (ektag){ektag="<div id='digerisler'>Diğer <b>"+xmustisim+"</b> işlerinden...<br />" +ektag+"<br /></div>";}
		//if (ektag || ektag2) {ektagson="<div id='digerisler'>" +ektag+ektag2+ "</div>"}
	}
	if (lang=="en"){
		if (ektag){ektag="<div id='digerisler'>Also for <b>"+xmustisim+": </b><br />" +ektag+"<br /></div>";}
		//if (ektag || ektag2) {ektagson="<div id='digerisler'>" +ektag+ektag2+ "</div>"}
	}
	ektagson=ektag2+ektag
	return (ektagson)
}





function menu(what){
	obj=document.getElementById('menu'+what)
	obj.className='pembelink'
}

function bodyLoaded(){
		yy=findPosY(document.getElementById('sayfasonu'))
		hh=getBrowserHeight()
		if (yy<hh) {
			fark=hh-yy-40
			document.getElementById('sayfasonu').style.height=fark+'px'
			//alert(hh+' '+yy+' ='+fark)
		}
}

function makeFlash(id,w,h,src,wmode,bg,fvar){
	document.writeln('<object id="'+id+'" width="'+w+'" height="'+h+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,29,0">');
	document.writeln('<param name="movie" value="'+src+'"><param name="wmode" value="'+wmode+'"><param name="bgcolor" value="'+bg+'"><param name="FlashVars" value="'+fvar+'">');
	document.writeln('<embed name="'+id+'" id="'+id+'" src="'+src+'" width="'+w+'" height="'+h+'" flashvars="'+fvar+'" wmode="'+wmode+'" bgcolor="'+bg+'" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"></embed>');
	document.writeln('</object>');
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL);");
}




function mailEkle(){
	loaderShow('inline')
	var url = 'mailekle.php'
	var pars = 'email=' + document.getElementById("mailbox").value
	var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: showMailResponse} )
}

function showMailResponse(originalRequest){
	loaderShow('none')
	alert(originalRequest.responseText)
}


function loaderShow(what){document.getElementById('loader').style.display=what;}






function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
	else if(obj.x) curleft += obj.x;

	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent)
		while(1) {
			curtop += obj.offsetTop;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
	else if(obj.y) curtop += obj.y;

	return curtop;
}


function getBrowserHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return myHeight;
}


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  //return [ scrOfX, scrOfY ];
  return (scrOfY);
}

