﻿function runPf(name, conf){
	try{
		if (document.getElementsByName(name).length>1){
			/* Give  params to embed for FF */
			document.getElementsByName(name)[1].init(conf);
		}else{
			/* Give  params to object for IE */
			document.getElementsByName(name)[0].init(conf);
		}
	}
	catch(e){
		setTimeout(function(){runPf(name, conf)}, 200);
	}
}

function openDialog(params)
{
	params = params||{};

	
	var dialog = window.showModalDialog('/dialogs/commonPopupWindow.html',
		params, 'center:yes; dialogHeight:550px;resizable:yes;dialogWidth:550px ')

	if(params.answer.resCode == 'OK')
	{
		return params.answer;
	}	
}

var isPfRuning = false;
function slideshow() {    
  	 // pictures array
	 $('[type=slideshow]').find("img").css({'opacity':0});
	 $('[type=slideshow]:first').find("img").css({'opacity':1});
	 var $pics = $('[type=slideshow]').find("img");	
	 pfSetting = {
		 pics :  $pics,
		 picsLength :$('[type=slideshow]').find("img").length,
		 curPic : 0
	};
	isPfRuning = true;
}



function showImgFunc(direction) {
	//debugger;
 if (isPfRuning && parseInt(pfSetting.picsLength) > 1){		
		if (direction){
			next_img = (parseInt(pfSetting.picsLength)-1 == pfSetting.curPic) ? 0 : parseInt(pfSetting.curPic) + 1;
		} else {
			next_img = (pfSetting.curPic == 0) ? parseInt(pfSetting.picsLength)-1 : parseInt(pfSetting.curPic) - 1;
		}
		try{  
			 $(pfSetting
				 .pics[pfSetting.curPic])
			 	 .css('display','block')
				 .animate({
						 opacity: 0
					},
					pfSet.Speed
			 );			
			 $(pfSetting
				 .pics[next_img])
			 	 .css('display','block')
				 .animate({
						 opacity: 1
					},
					pfSet.Speed
			 ).end();						
			pfSetting.curPic = next_img;
			//if (isStopHide && isStopShow)
			//setTimeout('showImgFunc()',pfSet.Delay);	
		}catch(e){}
	}
}	

function hideSlider(img){
	isPfRuning = false;
	$(img).parents('slideshow').remove();
	if ($('slideshow').length > 1){		
		slideshow();
	}else{
		$('slideshow:first').find("img").css({'opacity':1});
	}
}
