var pagetoload = 2;
var pageloading = false;
showImgTimer=0;
imagesToDisplay=perLoad;
imagesDisplaied=0;
imagesToDisplayLimit=1008;
displayedAll=0;
function loadNextPage()
	{
	if(pageloading || displayedAll) return;
//	if(document.body.scrollTop < document.body.scrollHeight - 100)
//        return; 
	pageloading = true;
	//alert('http://www.dreamstime.com/ajaxsearch.php?'+getparams+'&pg='+pagetoload+'&dynpg='+dynpg+'&imagesToDisplayLimit='+imagesToDisplayLimit+'&imgDisplayed='+perLoad);
	requestAJAXadd('http://www.dreamstime.com/ajaxsearch.php?'+getparams+'&pagetype='+pagetype+'&pg='+pagetoload+'&dynpg='+dynpg+'&imagesToDisplayLimit='+imagesToDisplayLimit+'&imgDisplayed='+perLoad, 'contenthere');
	pagetoload++;
	imagesToDisplay+=perLoad;
	if(!showImgTimer)showImgTimer=window.setInterval(showImg,65);
	}
//$(window).scroll(function(){
$(window).scroll(function(){
	if($(window).scrollTop() > $(document).height() - $(window).height() - 300)
		{
		loadNextPage();
		}
});
mi=0;
function msg(str){
	if(mi<10){
		alert(str);
		mi++;
	}
}
function showImg(){
	obname='img_res_'+imagesDisplaied;
	ob=document.getElementById(obname);
	if(ob){
		if(ua.indexOf('msie') != -1){
			ob.style.display='inline';
		}else{
			ob.style.display='inline-table';
		}
		imagesDisplaied++; 
		if(imagesDisplaied>=imagesToDisplay || imagesDisplaied>=imagesToDisplayLimit){
			window.clearInterval(showImgTimer);
			showImgTimer=0
			if(imagesDisplaied>=imagesToDisplayLimit){
				displayedAll=1;
				document.getElementById('nextP').style.display='';
			}
		}
	}else{
		
	}
}
function checkHovering(){
	if(hoverId>-1 && !popupActive){
		d = new Date();
		if(d.getTime()-hoverTime>400){
			popupActive=1;
			//hoverId=oid;
			showImgPopup();
		}
	}
}
function animatePopup(){
	if(hoverId>-1){
		anim_i++;
		if(anim_i<anim_steps){
			obname='hov_res_'+hoverId; 
			ob=document.getElementById(obname);
			if(ob){
			ob.style.marginLeft=(-anim_i*anim_dx)+'px';
			ob.style.marginTop=(-anim_i*anim_dy)+'px';
			}else{
				
			}
			//
			obname='hov_img_'+hoverId;
			ob=document.getElementById(obname); //msg(ob);
			if(ob){
			nw=imgWidth+anim_i*anim_dxo*2;
			ob.style.width=nw+'px';
			nh=imgHeight+anim_i*anim_dyo*2;
			ob.style.height=nh+'px';
			}else{
				
			}
		}else{
			obname='hov_res_'+hoverId; 
			ob=document.getElementById(obname);
			if(ob){
			ob.style.marginLeft=(-anim_fx)+'px';
			ob.style.marginTop=(-anim_fy)+'px';
			}else{
				
			}
			//
			obname='hov_img_'+hoverId;
			ob=document.getElementById(obname); //msg(ob);
			if(ob){
			nw=thbWidth;
			ob.style.width=nw+'px';
			nh=thbHeight;
			ob.style.height=nh+'px';
			}else{
				
			}
			//
			window.clearInterval(animTimer);
			animTimer=0
			showImgPopupInfo()
		}
		obname2='hov_lod_'+hoverId;
		ob2=document.getElementById(obname2); //msg(ob);
		obname3='hov_big_'+hoverId;
		ob3=document.getElementById(obname3); //msg(ob);
		if(ob){
		ob2.style.marginLeft=nw/2-16+'px';
		ob2.style.marginTop=nh/2-16+'px';
		ob3.style.width=nw+'px';
		ob3.style.height=nh+'px';
		}else{
			
		}
	}else{
		
	}
}
function animatePopupInfo(){
	if(hoverId>-1){
		anim_i--;
		if(anim_i>0){
			obname='hov_info_'+hoverId; 
			ob=document.getElementById(obname);
			if(ob){
			ob.style.marginTop=(thbHeight-anim_i*anim_dy+2)+'px';
			}else{
				
			}
		}else{
			obname='hov_info_'+hoverId; 
			ob=document.getElementById(obname);
			if(ob){
			ob.style.marginTop=(thbHeight-0+2)+'px';
			}else{
				
			}
			//
			window.clearInterval(anim2Timer);
			anim2Timer=0
			animOn=0;
		}
	}else{
		
	}
}
infoHeight=70;
function showImgPopupInfo(){
	if(hoverId>-1){
		anim_steps=5;
		anim_i=anim_steps;
		anim_dy=infoHeight/anim_steps;
		obname='hov_info_'+hoverId; 
		ob=document.getElementById(obname);
		if(ob){
		ob.style.marginTop=(thbHeight-infoHeight+2)+'px';
		ob.style.display='';
		}else{
			
		}
		if(!anim2Timer)anim2Timer=window.setInterval(animatePopupInfo,1000/25);
	}else{
		
	}
}
function getElementPosition(elemID){
	var ob = document.getElementById(elemID);
	var offsetLeft = 0;
	var offsetTop = 0;
	while (ob){
		offsetLeft += ob.offsetLeft;
		offsetTop += ob.offsetTop;
		ob = ob.offsetParent;
	}
	if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){
		offsetLeft += document.body.leftMargin;
		offsetTop += document.body.topMargin;
	}
	return {left:offsetLeft,top:offsetTop};
}
function showImgPopup(){
	hoverId=oid;
	
	animOn=1;
	margin=1;
	anim_i=0;
	anim_steps=4;
	anim_fx=(thbWidth-imgWidth)/2;
	anim_fy=(thbHeight-imgHeight)/2;
	anim_fxo=anim_fx;
	anim_fyo=anim_fy;
	
	winW=document.body.clientWidth;
	winH=document.body.clientHeight;
	winT=document.body.scrollTop;
	absPos=getElementPosition('img_res_'+hoverId);
	if(absPos.left-anim_fx<margin-cenW)anim_fx=absPos.left-margin+cenW;
	if(absPos.top-winT-anim_fy<margin)anim_fy=absPos.top-margin-winT;
	if(winW-margin-absPos.left-imgWidth-anim_fx-10-12-cenW<0){
		anim_fx-=winW-margin-absPos.left-imgWidth-anim_fx-10-12-cenW;
	}
	if(winH-margin-absPos.top-imgHeight-anim_fy-10-infoHeight+winT<0){
		anim_fy-=winH-margin-absPos.top-imgHeight-anim_fy-10-infoHeight+winT;
	}
	
	anim_dx=anim_fx/anim_steps;
	anim_dy=anim_fy/anim_steps;
	anim_dxo=anim_fxo/anim_steps;
	anim_dyo=anim_fyo/anim_steps;
	obname='img_res_'+hoverId; 
	ob=document.getElementById(obname);
	
	if(ua.indexOf('MSIE') !== false){
		display='inline';
	}else{
		display='inline-table';
	}
	
	html='<div id="hov_res_'+hoverId+'" onMouseOut="mOutPopup('+hoverId+')" style="vertical-align:top; position:absolute; float:left; margin-left:0px; margin-top:0px; margin-right:10px; margin-bottom:10px">';
		html+='<a onMouseOver="preservePopup()"  href="'+imgLink+'" style="z-index:1; position:absolute; border:10px #4c4843 solid; border-bottom:0px; background-color:#E5E2DE; padding:1px;">';
			html+='<img onMouseOver="preservePopup()"  id="hov_img_'+hoverId+'" align="middle" border="0" style="width:'+imgWidth+'px; height:'+imgHeight+'px" src="'+hoverSrc+'" >';
		html+='</a>';
		html+='<div onMouseOver="preservePopup()"  style="z-index:2; position:absolute; margin:10px; border-bottom:0px; padding:1px; text-align:center; vertical-align:middle;">';
			html+='<img onMouseOver="preservePopup()"  id="hov_lod_'+hoverId+'" style="margin-left:'+(imgWidth/2-16)+'px; margin-top:'+(imgHeight/2-16)+'px; vertical-align:middle;" border="0" src="http://thumbs.dreamstime.com/img/loadingnew.gif" width="32" height="32" >';
		html+='</div>';
		html+='<a onMouseOver="preservePopup()"  href="'+imgLink+'" style="z-index:3; position:absolute; margin:10px; border-bottom:0px; padding:1px">';
			html+='<img onMouseOver="preservePopup()"  id="hov_big_'+hoverId+'" align="middle" border="0" style="width:'+imgWidth+'px; height:'+imgHeight+'px" src="http://thumbs.dreamstime.com/site-img/sep.gif" >';
		html+='</a>';
		html+='<div id="hov_info_'+hoverId+'" style="background-color:#4c4843; width:'+(thbWidth-0+2+(ua.indexOf('msie')!=-1?20:0))+'px; position:absolute; z-index:0; margin-top:0px; display:none; border:10px #4c4843 solid" onMouseOver="preservePopup()" >';
			html+='<div onMouseOver="preservePopup()"  style="text-align:right; padding:2px; background:#E5E2DE">';
				html+='<div onMouseOver="preservePopup()"  style="display:'+display+'; float:left; border-width:0px; margin:0px;"><nobr>'+(imgtitle.length>22?imgtitle.substr(0,20)+'...':imgtitle)+'</nobr></div>';
	if(memberid){
				html+='<div onMouseOver="preservePopup()"  style="width:15px; display:'+display+'; vertical-align:middle; margin-top:2px;" id="flag'+imgid+'" name="flag'+imgid+'"><a href="Javascript:if(getCookie(\'flagwarned\') == \'y\') requestAJAX(\'ajax/flagger.php?imageid='+imgid+'&words='+words+'&dtlanguage='+dtlanguage+'\', \'flag'+imgid+'\'); else { alert(\''+DTL_FUNCTIONS_PR_025+'\'); setCookie(\'flagwarned\',\'y\',\'Sun, 07-Feb-2010 00:00:01 GMT\');}"><img src="'+static_adr+'search-img/icon_flaggolf.gif" alt="'+DTL_FUNCTIONS_PR_044+'" title="'+DTL_FUNCTIONS_PR_044+'" width="10" height="11" border="0"></a></div>';
	}
	if(specialAddToCart){
				html+='<div onMouseOver="preservePopup()"  style="width:18px; display:'+display+'; vertical-align:middle; margin-right:4px;" id="flash'+imgid+'" name="flash'+imgid+'"><a href="#'+imgid+'" onClick="Javascript:if(ua.indexOf(\'opera\') == -1) document.location=\''+site_adr+'frameset.php?addimg='+imgid+'&url='+REQUEST_URI+'&addfirstimg=1\'; if (getObj(\'flash\'+imgid)) getObj(\'flash\'+imgid).innerHTML = \'Added\';return false;"><img src="'+static_adr+'site-img/icon_addlightbox.gif" width="11" height="13" border=0 alt="'+DTL_FUNCTIONS_PR_026+'" title="'+DTL_FUNCTIONS_PR_026+'"></a></div>';
	}else{
				html+='<div onMouseOver="preservePopup()"  style="width:100px; display:'+display+'; vertical-align:middle; margin-right:4px;" id="flash'+imgid+'" name="flash'+imgid+'"><a href="#'+imgid+'" onClick="Javascript:if(ua.indexOf(\'opera\') == -1) document.location=\''+site_adr+'frameset.php?addimg='+imgid+'&url='+REQUEST_URI+'&addfirstimg=1\'; if (getObj(\'flash\'+imgid)) getObj(\'flash\'+imgid).innerHTML = \'Added\';return false;">'+DTL_FUNCTIONS_PR_027+'</a></div>';
	}
				html+='<div onMouseOver="preservePopup()"  style="width:15px; display:'+display+'; vertical-align:middle"><a href="javascript:MM_openBrWindow(\'level.php?lvlimag='+level+'#'+level+'\',\'level_popup\',\'width=650,height=600,resizable,scrollbars=yes\');"><img src="'+static_adr+'site-img/icon_level'+level+'sm.gif" width="12" height="13" border="0" alt="This is a level '+level+' image" title="This is a level '+level+' image" ></a></div>';
	if(exclusive)html+='<div onMouseOver="preservePopup()"  style="width:15px; display:'+display+'; vertical-align:middle"><img src="'+static_adr+'site-img/exclusivity_star.gif" alt="This is an exclusive image" title="This is an exclusive image"></div>';
			html+='</div>';
			html+='<div onMouseOver="preservePopup()"  class="h2" style="z-index:53; layer-background-color: #4c4843; border: 1px none #808080; padding:10px;padding:1px;z-index:51;" id="div_3" >'+'<nobr>'+(isinstore == 0?'ID: '+imgid+' / Level: '+level:'')+'</nobr>'+'<br>'+imgsize+'Downloads: '+downloads+' / Views: '+views+' </div>';
		html+='</div>';
	html+='</div>';
	ob.innerHTML=html+ob.innerHTML;
	
	if(!animTimer)animTimer=window.setInterval(animatePopup,1000/25);
	obname='hov_big_'+hoverId;
	ob=document.getElementById(obname); //msg(ob);
	ob.src=hoverThbSrc;
	//obname='img_res_'+hoverId;
	//ob=document.getElementById(obname); //msg(ob);
	//ob.style.paddingBottom='0px';
}
animTimer=0
anim2Timer=0
closePopupTimer=0
hoverId=-1;
hoverTime=0;
hoverSrc='';
hoverThbSrc='';
hTimer=window.setInterval(checkHovering,100);//always on
popupActive=0;
imgWidth=0;
imgHeight=0;
thbWidth=0;
thbHeight=0;
imgLink='';
imgtitle='';
username='';
imgid='';
imgsize='';
credit='';
level='';
isinstore='';
downloads='';
views='';
cenW=0;
animOn=0;
oid=-1;
exclusive=0;
specialAddToCart=0;
function mOver(id,src,thb, width, height, img_link, _imgtitle, _username, _imgid, _imgsize, _credit, _level, _downloads, _views, _cenW, _exclusive, _specialAddToCart){ 
	
	d = new Date();
	hoverTime=d.getTime();
	if(src){
		imgLink=img_link;
		hoverSrc=src;
		hoverThbSrc=thb;
		imgWidth=width/2.5;
		imgHeight=height/2.5;
		thbWidth=width;
		thbHeight=height;
		imgtitle=_imgtitle;
		username=_username;
		imgid=_imgid;
		imgsize=_imgsize;
		credit=_credit;
		level=_level;
		exclusive=_exclusive;
		specialAddToCart=_specialAddToCart;
		isinstore=0
		if (hoverThbSrc.indexOf("storeimages/item") >= 0) {
			isinstore = 1;
		}
		downloads=_downloads;
		views=_views;
		cenW=_cenW;
		//
		oid=id;
	}else{
		id=oid;
	}
	if(hoverId>-1)closePopup();
	if(!(animOn && mouseFrozed)){
		mouseFrozed=1;
		if(hoverId!=id){
			hoverId=id;
		}
	}
}
function mOut(id){ 
	if(!(animOn && mouseFrozed)){
		/*if(hoverId>-1){
			obname='img_res_'+hoverId;
			ob=document.getElementById(obname); //msg(ob);
			ob.style.paddingBottom='2px';
		}*/
		closePopup();
	}
}
function closePopup(){ 
	if(!(animOn && mouseFrozed)){
		if(hoverId>-1){
			if(document.getElementById('hov_res_'+hoverId)){
				forceOpen=0;
				document.getElementById('img_res_'+hoverId).removeChild(document.getElementById('hov_res_'+hoverId));
			}else{
				forceOpen=1;
			}
			//obname='img_res_'+hoverId;
			//ob=document.getElementById(obname); //msg(ob);
			//ob.style.paddingBottom='2px';
		}
		if(animTimer){
			window.clearInterval(animTimer);
			animTimer=0;
		}
		if(anim2Timer){
			window.clearInterval(anim2Timer);
			anim2Timer=0;
		}
		hoverId=-1;
		popupActive=0;
		animOn=0;
		mouseFrozed=1;
		if(forceOpen){
			mOver();
		}
	}else{
		
	}
}
function mOutPopup(id){ 
	if(!closePopupTimer)closePopupTimer=window.setTimeout(closePopup,1);
}
function preservePopup(){ 
	if(closePopupTimer){
		window.clearTimeout(closePopupTimer);
		closePopupTimer=0;
	}
}
mouseFrozed=0;
function mMove(id){ 
	if(mouseFrozed && hoverId!=oid){
		mouseFrozed=0;
	}
}
