//Highslide's common properties
//hs.graphicsDir = '/common/scripts/highslide/graphics/';
IMF_hs.showCredits = false;
IMF_hs.align = 'center';
IMF_hs.dimmingOpacity = 0.2; 
IMF_hs.numberOfImagesToPreload=0;
IMF_hs.lang.restoreTitle="";
//*this three properties cannot use at in-line parameterss
IMF_hs.expandDuration=250;
IMF_hs.restoreDuration=250;
IMF_hs.dimmingDuration=50;
//Definition of control button for image popups
if (IMF_hs.addSlideshow) IMF_hs.addSlideshow({
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: false,
	overlayOptions: {
		opacity: 1,
		position:"below",
		hideOnMouseOut: false
	}
});
IMF_hs.skin.controls='<div class="IMF_highslide-controls"><ul>'+
			'<li class="highslide-print">'+
				'<a href="#" title="" onclick="return IMF_hs.printImage(this)">'+
				'<span></span></a>'+
			'</li>'+
			'<li class="highslide-previous">'+
				'<a href="#" title="{IMF_hs.lang.previousTitle}">'+
				'<span>{IMF_hs.lang.previousText}</span></a>'+
			'</li>'+
			'<li class="highslide-play">'+
				'<a href="#" title="{IMF_hs.lang.playTitle}">'+
				'<span>{IMF_hs.lang.playText}</span></a>'+
			'</li>'+
			'<li class="highslide-pause">'+
				'<a href="#" title="{IMF_hs.lang.pauseTitle}">'+
				'<span>{IMF_hs.lang.pauseText}</span></a>'+
			'</li>'+
			'<li class="highslide-next">'+
				'<a href="#" title="{IMF_hs.lang.nextTitle}">'+
				'<span>{IMF_hs.lang.nextText}</span></a>'+
			'</li>'+
			'<li class="highslide-move">'+
				'<a href="#" title="{IMF_hs.lang.moveTitle}">'+
				'<span>{IMF_hs.lang.moveText}</span></a>'+
			'</li>'+
			'<li class="highslide-full-expand">'+
				'<a href="#" title="{IMF_hs.lang.fullExpandTitle}">'+
				'<span>{IMF_hs.lang.fullExpandText}</span></a>'+
			'</li>'+
			'<li class="highslide-close">'+
				'<a href="#" title="{IMF_hs.lang.closeTitle}" >'+
				'<span>{IMF_hs.lang.closeText}</span></a>'+
			'</li>'+
		'</ul></div>';
//Definitions for pre working and post working process
IMF_hs.Expander.prototype.onBeforeExpand = function (sender, e) {
	if(sender.isImage){
		if(sender.slideshow.controls) {
			sender.slideshow.controls.style.marginTop="26px";
		}
		if(sender.wrapperClassName=="IMF_hs_image_wrapper_w_print"){
			//
		}
	} else {
			if(sender.slideshow.controls) {
				sender.slideshow.controls.style.display="none";
			}
		   var buttonsId=(sender.contentId=="IMF_hs_html_ajax_w_print") ? "IMF_hs_htmlbutton_print":"IMF_hs_htmlbutton_close";
		   
		   sender.createOverlay( { overlayId:buttonsId , position: "below" } );
	}
};
IMF_hs.Expander.prototype.onAfterExpand=function(sender, e){

  try{
  	if(!sender.isImage){
		if(sender.content){
			var atags=$A(sender.content.getElementsByTagName("a"));
			for (var i=0,L=atags.length;i<L;i++){
				if(atags[i].href) {
					atags[i].focus();
					break;
				}
			}
	   	}
		
	} else{
		if(sender.slideshowGroup){
			if(sender.slideshowGroup=="hssingle"){
				sender.slideshow.disable("play");
				sender.slideshow.disable("previous");
				sender.slideshow.disable("next");
			}
		}
	}
  }catch(e){}
};
IMF_hs.Expander.prototype.onBeforeClose=function(sender, e){
	try{
		//return focus to original link-element
		if(sender.a) sender.a.focus();
	}catch(e){}
};
//Defninition about keyboard interfaces
IMF_hs.onKeyDown = function (sender, e) {
	var expObj = IMF_hs.getExpander();
	if(expObj.isHtml){
		// cancel to close popup and jump to linked page
		if(e.keyCode==13) return false; 
	}
	if(expObj.slideshowGroup){
		// stop slideshow
		if(expObj.slideshowGroup=="hssingle"){
			if(e.keyCode==32 || e.keyCode==39) return false;
		}
	}
};

/*
Function for presetting
	this function sets options for Highslide's openning command.
	to add new pattern of popup, add new defination at the end of 'if' statements.
		
	function's first parameters defines type of popup
	 image
	 image_w_print
	 ajax
	 ajax_s
	 ajax_w_print
	
	and second does groupname for slideshow. Same groupname forms a slideshow group
	 * when no parameter is set, it stops making slideshopw group and prevents keyboard interface.
 
*/
function IMF_hsCustom(){
	if(arguments[0]==null) return null;
	var type=arguments[0];
	if(arguments[1]!=null){
		var groupname=arguments[1];
	} else {
		var groupname="hssingle";
	}

	if(type=="image") {
		return {
			slideshowGroup:groupname,
			wrapperClassName:"IMF_hs_image_wrapper",
			transitions : ['expand','crossfade'],
			captionEval : '"<div>"+this.a.title+"</div>"',
			allowSizeReduction : false
		};
	} else if(type=="image_w_print") {
		return {
			slideshowGroup:groupname,
			wrapperClassName:"IMF_hs_image_wrapper_w_print",
			transitions : ['expand','crossfade'],
			captionEval : '"<div>"+this.a.title+"</div>"',
			allowSizeReduction : false
		};
	} else if(type=="ajax") {
		return {
			contentId:"IMF_hs_html_ajax",
			objectType: 'ajax',
			wrapperClassName : 'borderless',
			transitions : [],
			fadeInOut : true,
			cacheAjax : false,
			width:600
		};
	} else if(type=="ajax_s") {
		return {
			contentId:"IMF_hs_html_ajax",
			objectType: 'ajax',
			wrapperClassName : 'borderless',
			transitions : [],
			fadeInOut : true,
			cacheAjax : false,
			width:400
		};
	} else if(type=="ajax_w_print") {
		return {
			contentId:"IMF_hs_html_ajax_w_print",
			objectType: 'ajax',
			wrapperClassName : 'borderless',
			transitions : [],
			fadeInOut : true,
			cacheAjax : false,
			width:600
		};
	} else if(type=="ajax_support_area") {
		return {
		contentId:"IMF_hs_html_ajax",
		objectType: 'ajax',
		wrapperClassName : "borderless",
		transitions : [],
		fadeInOut : true,
		cacheAjax : false,
		width:660
		};
	}else if(type=="flash") {
		return {
		contentId:"IMF_hs_html_ajax",
		objectType: 'swf',
		wrapperClassName : "borderless",
		transitions : [],
		fadeInOut : true,
		cacheAjax : false,
		width:660
		};
	}else if(type=="ajax_doclist") {
		return {
		contentId:"IMF_hs_html_ajax",
		objectType: 'ajax',
		wrapperClassName : "borderless",
		transitions : [],
		fadeInOut : true,
		cacheAjax : false,
		width: 900,
		height: 500
		};
	}else if(type=="ajax_IMF_help") {
		return {
		contentId:"IMF_hs_html_ajax",
		objectType: 'ajax',
		wrapperClassName : "borderless",
		transitions : [],
		fadeInOut : true,
		cacheAjax : false,
		width:700,
		height:500,
		allowSizeReduction : false
		};
	}else if(type=="ajax_solder") {
		return {
		contentId:"IMF_hs_html_ajax_w_print",
		objectType: 'ajax',
		wrapperClassName : "borderless",
		transitions : [],
		fadeInOut : true,
		cacheAjax : false,
		width : 644,
		height: 520
		};
	}else if(type=="ajax_solderList") {
		return {
		contentId:"IMF_hs_html_ajax_w_print",
		objectType: 'ajax',
		wrapperClassName : "borderless",
		transitions : [],
		fadeInOut : true,
		cacheAjax : false,
		width : 800,
		height: 520
		};
	};
}

//	Function for printing
//	when a print button clicked ,it loads linked contents in another window, and then tries to print the window.
//	the window is closed after printing ( or canceling ) it. 

IMF_hs.printImage = function (el) {
	var exp = IMF_hs.expanders[IMF_hs.getWrapperKey(el)];
	var pw =window.open(exp.a.href,"printwindow","width=600,height=450");
	setTimeout(function(){
		pw.print();
		pw.close();
	},1000);
	//pw.print();
};

/*
Function for preparing containers of HTML-popup
*/
Event.observe(window,"load",function(){
		var ar=[],c=0;
		ar[c++]='<div class="highslide-html-content IMF_hs_html_wrapper" id="IMF_hs_html_ajax">';
		ar[c++]=' <div class="highslide-body IMF_hs_html_body"></div>';
		ar[c++]='</div>';
		ar[c++]='<div class="highslide-html-content IMF_hs_html_wrapper" id="IMF_hs_html_ajax_w_print">';
		ar[c++]=' <div class="highslide-body IMF_hs_html_body"></div>';
		ar[c++]='</div>';
		ar[c++]='<div class="highslide-overlay IMF_hs_html_foot" id="IMF_hs_htmlbutton_close">';
		ar[c++]=' <a href="javascript:void(0)" class="IMF_hs_closebutton" onclick="return IMF_hs.close(this)" title="Close">&nbsp;</a>';
		ar[c++]='</div>';
		ar[c++]='<div class="highslide-overlay IMF_hs_html_foot" id="IMF_hs_htmlbutton_print">';
		ar[c++]=' <a href="javascript:void(0)" class="IMF_hs_closebutton" onclick="return IMF_hs.close(this)" title="Close">&nbsp;</a>';
		ar[c++]=' <a href="javascript:void(0)" class="IMF_hs_printbutton" onclick="return IMF_hs.printImage(this)" title="Print">&nbsp;</a>';
		ar[c++]='</div>';
		new Insertion.Bottom(document.body, ar.join(""));
},false);
