//Highslide's common properties
hs.graphicsDir = '/common/scripts/highslide/graphics/';
hs.showCredits = false;
hs.align = 'center';
hs.dimmingOpacity = 0.2; 
hs.numberOfImagesToPreload=0;
hs.lang.restoreTitle="";
//*this three properties cannot use at in-line parameterss
hs.expandDuration=250;
hs.restoreDuration=250;
hs.dimmingDuration=50;
//Definition of control button for image popups
if (hs.addSlideshow) hs.addSlideshow({
	interval: 13000,
	repeat: false,
	useControls: true,
	fixedControls: false,
	overlayOptions: {
		opacity: 1,
		position:"below",
		hideOnMouseOut: false
	}
});
hs.skin.controls='<div class="highslide-controls"><ul>'+
			'<li class="highslide-print">'+
				'<a href="#" title="" onclick="return hs.printImage(this)">'+
				'<span></span></a>'+
			'</li>'+
			'<li class="highslide-previous">'+
				'<a href="#" title="{hs.lang.previousTitle}">'+
				'<span>{hs.lang.previousText}</span></a>'+
			'</li>'+
			'<li class="highslide-play">'+
				'<a href="#" title="{hs.lang.playTitle}">'+
				'<span>{hs.lang.playText}</span></a>'+
			'</li>'+
			'<li class="highslide-pause">'+
				'<a href="#" title="{hs.lang.pauseTitle}">'+
				'<span>{hs.lang.pauseText}</span></a>'+
			'</li>'+
			'<li class="highslide-next">'+
				'<a href="#" title="{hs.lang.nextTitle}">'+
				'<span>{hs.lang.nextText}</span></a>'+
			'</li>'+
			'<li class="highslide-move">'+
				'<a href="#" title="{hs.lang.moveTitle}">'+
				'<span>{hs.lang.moveText}</span></a>'+
			'</li>'+
			'<li class="highslide-full-expand">'+
				'<a href="#" title="{hs.lang.fullExpandTitle}">'+
				'<span>{hs.lang.fullExpandText}</span></a>'+
			'</li>'+
			'<li class="highslide-close">'+
				'<a href="#" title="{hs.lang.closeTitle}" >'+
				'<span>{hs.lang.closeText}</span></a>'+
			'</li>'+
		'</ul></div>';
//Definitions for pre working and post working process
hs.Expander.prototype.onBeforeExpand = function (sender, e) {
	if(sender.isImage){
		if(sender.slideshow.controls) {
			sender.slideshow.controls.style.marginTop="26px";
		}
		if(sender.wrapperClassName=="hs_image_wrapper_w_print"){
			//
		}
	} else {
			if(sender.slideshow.controls) {
				sender.slideshow.controls.style.display="none";
			}
		   var buttonsId=(sender.contentId=="hs_html_ajax_w_print") ? "hs_htmlbutton_print":"hs_htmlbutton_close";
		   
		   sender.createOverlay( { overlayId:buttonsId , position: "below" } );
	}
}
hs.Expander.prototype.onAfterExpand=function(sender, e){

  try{
  	if(!sender.isImage){
		//case region-popup : repair body-element 
		if(sender.contentId=="hs_html_region"){
			document.body.style.visibility="visible";
		//case html-popup : change focuse to first link-element in popup
		}
		if(sender.content){
			var atags=$A(sender.content.getElementsByTagName("a"));
			if(atags.length>0){
				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){}
}
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
hs.onKeyDown = function (sender, e) {
	var expObj = 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 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:"hs_image_wrapper",
			transitions : ['expand','crossfade'],
			captionEval : '"<div>"+this.a.title+"</div>"',
			allowSizeReduction : false
		}
	} else if(type=="image_w_print") {
		return {
			slideshowGroup:groupname,
			wrapperClassName:"hs_image_wrapper_w_print",
			transitions : ['expand','crossfade'],
			captionEval : '"<div>"+this.a.title+"</div>"',
			allowSizeReduction : false
		}
	} else if(type=="ajax") {
		return {
			contentId:"hs_html_ajax",
			objectType: 'ajax',
			wrapperClassName : 'borderless',
			transitions : [],
			fadeInOut : true,
			cacheAjax : false,
			width:600
		}
	} else if(type=="ajax_s") {
		return {
			contentId:"hs_html_ajax",
			objectType: 'ajax',
			wrapperClassName : 'borderless',
			transitions : [],
			fadeInOut : true,
			cacheAjax : false,
			width:400
		}
	} else if(type=="ajax_w_print") {
		return {
			contentId:"hs_html_ajax_w_print",
			objectType: 'ajax',
			wrapperClassName : 'borderless',
			transitions : [],
			fadeInOut : true,
			cacheAjax : false,
			width:600
		}
	} else if(type=="ajax_support_area") {
		return {
		contentId:"hs_html_ajax",
		objectType: 'ajax',
		wrapperClassName : "borderless",
		transitions : [],
		fadeInOut : true,
		cacheAjax : false,
		width:660
		}
	} else if(type=="flash") {
		return {
		contentId:"hs_html_ajax",
		objectType: 'swf',
		wrapperClassName : "borderless",
		transitions : [],
		fadeInOut : true,
		cacheAjax : false,
		width:660
		}
	}
}

/*
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. 
*/
hs.printImage = function (el) {
   var exp = hs.expanders[hs.getWrapperKey(el)];
   var pw =window.open(exp.a.href,"printwindow","width=600,height=450");
   setTimeout(function(){
   	pw.print();
	pw.close();
   },1000);
   return false;
};


/*
Function for preparing containers of HTML-popup
*/
Event.observe(window,"load",function(){
		var ar=[],c=0;
		ar[c++]='<div class="highslide-html-content hs_html_wrapper" id="hs_html_ajax">';
		ar[c++]=' <div class="highslide-body hs_html_body"></div>';
		ar[c++]='</div>';
		ar[c++]='<div class="highslide-html-content hs_html_wrapper" id="hs_html_ajax_w_print">';
		ar[c++]=' <div class="highslide-body hs_html_body"></div>';
		ar[c++]='</div>';
		ar[c++]='<div class="highslide-overlay hs_html_foot" id="hs_htmlbutton_close">';
		ar[c++]=' <a href="javascript:void(0)" class="hs_closebutton" onclick="return hs.close(this)" title="Close">&nbsp;</a>';
		ar[c++]='</div>';
		ar[c++]='<div class="highslide-overlay hs_html_foot" id="hs_htmlbutton_print">';
		ar[c++]=' <a href="javascript:void(0)" class="hs_closebutton" onclick="return hs.close(this)" title="Close">&nbsp;</a>';
		ar[c++]=' <a href="javascript:void(0)" class="hs_printbutton" onclick="return hs.printImage(this)" title="Print">&nbsp;</a>';
		ar[c++]='</div>';
		new Insertion.Bottom(document.body, ar.join(""));
		
},false);


