var oldThumb="";
 var elem="";
 var tgs="";
 var state = 0;

 function slideShow(s)
 {

	if ( oldThumb && !state ) {
		for ( var i = 0; i < thumbs.length; i++ ) {
			 
			if ( thumbs[i] == oldThumb ) {
				state = 1;
				thumbIndex = i;
			}
		}
		
	}
   	if(intervalId==null)
 	{
 		intervalId=setInterval('slideShow("1")',3000);
 		  thumbs[thumbIndex].parentNode.parentNode.className="";
 		thumbIndex=(thumbIndex+1)%thumbsCount
 	 disableThumbBorder(thumbs[thumbIndex])
 	  
 		 slideAdveritesiItem(thumbs[thumbIndex],'thumbBig')
 		  
 		 thumbs[thumbIndex].parentNode.parentNode.className="red";
 		 return
 	}
 	if(s=="1")
 	{
 		 
 		  thumbs[thumbIndex].parentNode.parentNode.className=""
 		thumbIndex=(thumbIndex+1)%thumbsCount
 	 
 		 slideAdveritesiItem(thumbs[thumbIndex],'thumbBig')
 		 
 		  
 		 thumbs[thumbIndex].parentNode.parentNode.className="red";
 	}
 	else
 	{
 		document.getElementById(slideShowCheckBox).checked=false
 		   thumbs[thumbIndex].parentNode.parentNode.className=""
 		window.clearInterval(intervalId)
 		intervalId=null
 	}
 	//alert(thumbIndex);
 }
function slideAdveritesiItem(tg,targetID,isThumbControll,thumbItem,pidIndex)
{
	if (isset('tempThumb')) {
		if (tempThumb != '') {
			document.getElementById(targetID).innerHTML = tempThumb;
			tempThumb = false;
		}
	}	
	 elem=document.getElementById(targetID).childNodes[0].childNodes[0];
	 tgs=tg;
	
	setTimeout('elem.src=tgs.src.replace("_th_1","_th_3")',10)
 
	if(isThumbControll)
	{
		 
		state = 0;
		 
		thumbItem.parentNode.parentNode.className="red"
		disableThumbBorder(thumbItem)
		oldThumb=thumbItem
		if(intervalId!=null)
			
			slideShow(0)
	}
	
	 if(pidIndex){
		devPhotoIndex=pidIndex;		
	 }else{
		 devPhotoIndex=-1;		
	 }
	 
}
function goTodevPhoto(ad_id,index){

		if(index>-1){
		window.open('devphoto.php?ad_id='+ad_id,'devPhoto','width=1000,height=830')
		}

}


function disableThumbBorder(thumbItem)
{
	if(oldThumb!=""&&oldThumb!=thumbItem)
		{
			oldThumb.parentNode.parentNode.className="";
		}
}

function playAddvideo() {

	var myFrame = window.document.createElement('IFRAME');
	if(document.getElementById("slideShowCheckBox").checked==true){
		document.getElementById("slideShowCheckBox").checked=false
		slideShow(0);
	
	}	
	
	myFrame.id = 'myFrame_';
	myFrame.name = 'myFrame_';
	myFrame.frameBorder = 0;
	myFrame.scrolling = "no";

	myFrame.width = 400;
	myFrame.height = 330;
	
	
	
	myFrame.style.margin = "0";
	myFrame.style.marginwidth = "0px";
	myFrame.style.marginheight = "0px";
	myFrame.style.padding = "0px";
	tempThumb = window.document.getElementById('thumbBig');
	tempThumb = tempThumb.innerHTML;
	window.document.getElementById("thumbBig").innerHTML = '';

	qs = 'videoTypeIndex='+videoTypeIndex+'&mediaPath0='+mediaPath+'&duration0='+duration+'&mediaID0='+mediaID+'&media_ad_id0='+media_ad_id;

	myFrame.src = 'http://www.hurriyetemlak.com/real_estate/flvPlayer.php?' + qs;
	//myFrame.src='http://dev13.hurriyetemlak.com/real_estate/flvPlayer.php?videoTypeIndex=2&mediaPath0=201006/7e6f64663cb637e451ccb4b70503c195.flv&duration0=35&mediaID0=927481&media_ad_id0=131922';
	
	window.document.getElementById("thumbBig").appendChild(myFrame);
	
}
function slideImgs() {
	if (doSlide == false || imgArr.length == 0) {
		return false;
	}

	$('#imgThumb_' + (imgArr.length - 1)).css("border", "1px solid #CCCCCC");
	$('#imgThumb_' + (arrayInd - 1)).css("border", "1px solid #CCCCCC");
	$('#imgThumb_' + arrayInd).css("border", "1px solid red");
	
	switchBigImg(imgArr[arrayInd].src);

	if (arrayInd < 5)
		scrollImages(-1);
	else
		scrollImages(1);

	if (arrayInd < imgArr.length - 1) {
		arrayInd++;
	} else {
		arrayInd = 0;
	}
	
	setTimeout("slideImgs()", slideTimeOut);
}

function initiateSlide(checked) {
	if (checked == true) {
		$('#slideBox').attr('checked', true);
		doSlide = true;
		slideImgs();
	} else {
		doSlide = false;
		arrayInd = 0;
		$('#slideBox').attr('checked', false);
		if(typeof(imgArr)!="undefined") {
		for ( var i = 0; i < imgArr.length; i++)
			$('#imgThumb_' + i).css("border", "1px solid #CCCCCC");
		}
	}
}

function switchBigImg(src) {

	// video açıldıysa
	if (typeof tempThumb != 'undefined' && tempThumb != null) {
		document.getElementById('thumbBig').innerHTML = tempThumb;
		tempThumb = null;
	}
	var imgSrc = src.split("/");
	$('#bigThumb').attr(
			'src',
			bigImgUlr + "/" + imgSrc[imgSrc.length - 2] + "/"
					+ imgSrc[imgSrc.length - 1]);
}

function isset(varname) {
 if(typeof( window[ varname ] ) != "undefined") 
	 return true;
 else 
	 return false;
} 


var bigImgUlr = 'http://devimages.hurriyetemlak.com/_thumbnail/_th_3';
