var g=
{
	slideshow:null
	,url:null,page:""
	,updateDelay:20		//ms
	,debug:false
	,nextPhotoDelay:8	//s
	,checker:false
	,v2:""		//&v2=true
	,curHotel:null
	,popupSsh:null
	,nbshows:0
	,holId:0
	,maptip:0
	,AjaxTabs:false
	,scrollh: 107
	,dgx0:0,dgy0:0
	,scr0:0,scry0:8
	,scrCnt:1,scrLH:17
};

function myJsInit()
{

	RQDebug("myJsInit");

	// Modernize
	Modernizr.addTest('usecustomfont',function(){
		return Modernizr.fontface && !jQuery.browser.msie;
	});
	Modernizr.addTest('useBackgroundPng',function(){
		return !(jQuery.browser.msie && (parseInt(jQuery.browser.version)<7));
	});


	// Crossfading texts
	$(".slideMe").RSlideshow({delay:10000});

	$(".paragraphSlideshow").each(function(){
		var a=$(this).remove();
		$(".mainBlockTop").append(a);
	});


	// 
	$(".pgpheSlideshow").each(function(index){
		if( $(this).is(".hotelSlideshow"))	// on custom holidays only
		{	g.curHotel=$(this).parents('.hotel');
			if( g.curHotel.length)
				g.curHotel.data("sshow",new SlideshowWide(this) );			
			
		}
		else
			g.slideshow	= new SlideshowWide(this);
	});


	// Home trips in focus
	$(".tripFocus").each(function()
	{	$(this).data("imgid",0);
		$(this).data("imgnb",$(this).find("input").length);
		//$(this).children('.header').click(imgGoThere)
		$(this).children('img').click(imgGoThere).load(function(){$(this).animate({opacity:1})});
		$(this).find(".headerBg").css({opacity:0.6});
		$(this).find(".toolbar").each(function()
		{
			$(this).find(".icToolClose").click(onToolbarClose);
			$(this).find(".icToolR,.icToolL").click(onToolbarNextImg);
		});
	});
	// Home panes
	$(".pgphe3Columns .pane .button a").mouseover(function(){
		$(this).parents(".pane").addClass('paneover');
	}).click(function(){$(this).parents(".pane").removeClass('paneover'); });
	$(".pgphe3Columns .pane").mouseleave(function(e){
		$(this).removeClass('paneover')
	});

	
	$(".pgphe3Columns .pane").find(".countries").addScrollbar({top:0,left:5,cH:170,content:"ul",ctnTop:0});
	$(".pgphe3Panes .pane ").addScrollbar({top:85,left:5,content:"p",ctnTop:22});


	// Contact form
	if( $('#Form').length)
	{
		$('#Form input,#Form textarea').focus(function(){
			if( $(this).is(".empty"))
			{	$(this).data("default",$(this).val());
				$(this).val("");
				$(this).removeClass("empty");
			}	
			$(this).addClass('focused');
		} ).blur(function()
		{	var def=$(this).data("default");
			if( def.length && !$(this).val().length)
			{	$(this).val(def);
				$(this).addClass("empty");
			}
			$(this).removeClass('focused'); 
		} );
	}

	// Trip hotels
	if( $('#tripTabs').length)
	{	RQDebug('got tripTabs');
		// Ajax tabs
		if(g.AjaxTabs)
		$('#tripTabs li a').each(function(){
			$(this).removeAttr('href');
			
			$(this).click(function(){
				var li=$(this).parents('li');
				if(!li.is('.selected'))
				{	//alert($(this).parents('li').attr('id'));
					var h=$('#tripTabContent').height();
					RQJumpToAnchor('loading');

					$('#tripTabContent').css({minHeight:h}).fadeOut('fast',function()
					{	g.slideshow=0;  
						RQAjaxCallPlugin('ListHolidays',"action=getLocationTabV2"+g.v2+"&hcode="+li.attr('id'),function(m,e){
							if(!e)
							{	eval(m);
								//$('#tripTabContent').css({minHeight:0})
								$(".pgpheSlideshow").each(function(index){g.slideshow=new SlideshowWide(this);});
								g.installHotels();
								RQJumpToAnchor('trip');
							}
						
						});
						
					});
					li.siblings('.selected').removeClass('selected');
					li.addClass('selected');
				}
				
			});
		});
		// Unfold hotel, favorite hotel
		g.installHotels=function()
		{	$('#tripTabContent .hotelStrip').each(function(){
			
			// btn mark as favorite
			$(this).find("img.mini").click(imgSlideshowPopup);
			$(this).find(".btnHeart").attr('title',"Choose this hotel as your favourite").click(function(){
				var h=$(this).parents('.hotel');
				if( !h.is('.favorite'))
				{
					var code=$("#tripTabs li.selected").attr('id');
					var id=h.attr('id');
					RQAjaxCallPlugin('ListHolidays',"action=markFavoriteV2"+g.v2+"&favcode="+code+"&hotelId="+id,function(m,e){
						if(!e)eval(m);					
					});

				}
			});

			$(this).find('.btnExpand').click(function()
			{	RQDebug('clicked');
				var oHotel =$(this).parents('.hotel');
				oHotel.toggleClass('expanded');
				if( oHotel.is('.expanded'))
				{	if(g.curHotel)
						g.curHotel.removeHotel();
					g.curHotel=oHotel;
					oHotel.append("<div class=\"hotelContent\">&nbsp;</div>");
					//get hotel information with Ajax
					RQAjaxCallPlugin("ListHotels","action=getTripHotelDetails"+g.v2+"&hId="+oHotel.attr('id'),function(m,e)
						{	if(!e)
							{	eval(m);
								$(".hotel .pgpheSlideshow").each(function(index)
								{
									$(this).parents('.hotel').data("sshow",new SlideshowWide(this) );
								});
								$(".hotel .pgphe3PanesH .pane:not(.marginT) .B3").addScrollbar({top:85,left:5,content:"p",ctnTop:22});
							}	
						}
					);
					
					//oHotel.find('.hotelContent').remove();
					
				}
				else
				{	oHotel.removeHotel();
					g.curHotel=null;
			
				}
			});

		});
		};g.installHotels();

	}
	// testimonials
	if( $(".testimonials").length)
	{
		$(".testimonials .imgTestim").wrap("<span class=\"imgTestim\" />").after("<img class=\"vign\" src=\"Data/Css.v2/i/testimonialVignettage.png\" />");
	}

	// elite
	var elite=$(".pgpheElite");
	if( elite.length)
	{
		elite.find("a.contact").click(function(){
			$(this).parents(".level2Block").toggleClass("expanded");
		});
	}
	// resize
	$(window).resize(onResize);


	Update();
}


function changeCurrency(o,url)
{
	//alert(RQGetVariableValue(o.name));
	self.location.href=url+"&currency="+RQGetVariableValue(o.name);//+"#currenciesSelector";
}

jQuery.fn.removeHotel=function()
{
	return $(this).each(function()
	{
		var sshow;
		if( sshow=$(this).data('sshow'))
			delete sshow;
		$(this).find('.hotelContent').remove();
		$(this).removeClass('expanded');

	});
}


function Update()
{
	if( g.popupSsh)
		g.popupSsh.M_animate(g.updateDelay/1000);
	else
	{
		if( g.slideshow && g.slideshow.animateOK)
		{	g.slideshow.M_animate(g.updateDelay/1000);
		}

		var sshow
		if( g.curHotel)
		{	if(sshow=g.curHotel.data('sshow'))
				sshow.M_animate(g.updateDelay/1000);
		}
	}
	var te = self.setTimeout("Update()",g.updateDelay);
}


// cb from ajax test call
function cbTestAjax(message,isErr)
{
	if( !isErr)
	{	//alert(message);
	}
}

function RQDebug(s)
{	if(g.debug)
	{	if( !$('#debug').is("div"))
		{	$('body').append("<div id=\"debug\" style=\"z-index:1000;position:absolute;top:0;left:0;background:#000;color:#fff;font-size:9px;\"></div>");
			$('#debug').css({opacity:0.8});
		}
	
		$('#debug').append("<div>"+s+"</div>");
	
	}
}

//---- Resize layout ----

function onResize()
{
	if(g.slideshow) g.slideshow.M_onResized();
}


//---- Toolbars ----
function onToolbarClose()
{
	var p=$(this).parents(".tripFocus");
	if( $(this).is(".icExpand"))
	{
		p.find(".headerBg").animate({height:129,width:"100%"});
		$(this).removeClass("icExpand");
		p.find(".toolbar").css({width:"auto"});
		p.find(".info").fadeIn();
		p.find(".flag").show();
	}
	else
	{
		p.find(".headerBg").animate({height:30,width:90});
		p.find(".toolbar").animate({width:50});
		$(this).addClass("icExpand");
		p.find(".info").fadeOut();
		p.find(".flag").fadeOut();
	}
}
function onToolbarNextImg()
{	
	// using js
	var t=$(this).parents(".tripFocus");
	var n=t.data('imgnb');
	if(n>1)
	{	var i=t.data('imgid');
		if($(this).is('.icToolL')) i=(i+n-1)%n; else i=(1+i)%n;
		var m=t.find("input:eq("+i+")").val();
		var img=t.children('img');
		t.css({background:"url("+img.attr("src")+") no-repeat top left"});
		img.stop().css({opacity:0.01}).attr("src",m);		
		t.data('imgid',i);

	}
	return true;
}

function imgGoThere()
{	var t=$(this).is('.header')? $(this):$(this).siblings('.header'); 
	var h=t.find(".info a").attr('href');
	if( h.length)
		self.location.href=g.url+h;
	else 
		imgSlideshowPopup.call(this);
}
function imgSlideshowPopup()
{
	if( g.popupSsh)
	{	closePopup();
	}
	RQAjaxCallPlugin("ListHolidays","action=popupSlideshow"+g.v2+"&img="+encodeURIComponent($(this).attr('src')),function(m,e)
	{	if(!e)
		{	var s=$("<div id=\"popupSlideshow\">"+m+"</div>");
			s.css({opacity:0}).children().addClass('noGloss');
			var docW=$(document).width();
			var scrollTop = $(window).scrollTop();
			var winH = $(window).height();
			var y=scrollTop+parseInt( (winH-404)/2);
			s.css({left:parseInt(docW-928)/2,top:y});
			showBg();


			$("body").append(s);
			g.popupSsh= new SlideshowWide(s.find('.pgpheSlideshow'));

			s.animate({opacity:1});


		}
	})
	

}
function showBg()
{	var o=$('#popupBg');
	if( !o.length)
	{	o= $("<div id=\"popupBg\" />");
		o.prependTo($(document.body));
	}
	o.click(closePopup);
	var bodyHeight = Math.max( Math.max($(document).height(),$("body").height()), $(window).height());	
	o.css({position:"absolute", display:"block",opacity:0.01,width:"100%",height:bodyHeight,background:"#000",zIndex:"99",top:"0",left:"0"});
	o.animate({opacity:0.7});
}
function closePopup()
{
	$('#popupBg').stop().fadeOut("fast",function(){$('#popupBg').remove()});
	if( g.popupSsh)
	{	delete g.popupSsh;
		g.popupSsh=0;
	}
	$('#popupSlideshow').remove();
}
//---- Slideshow wide ----
jQuery.fn.findMe = function()
{
	var p=$(this).parents('.pgpheSlideshow');
	RQDebug("findMe: "+p.data('index'));
	return p.data('me');
}
function SlideshowWide(o)
{
	var w=0;
	var me1=this;
	this.o= $(o);
	RQDebug("New slideshow index="+g.nbshows);
	this.o.data('me',this);
	this.o.data('index',g.nbshows++);
	this.animateOK=0;
	this.gloss=0;
	this.noGloss=0;
	this.glossMid=0;
	this.glossRight=0;
	this.glossMore=0;
	this.oSlider1=0;
	this.oSlider2=0;
	this.iPrev=0;
	this.iCurr=0;
	this.iNext=0;
	this.iOld=0;
	this.state=0;
	this.stateTime=0;
	this.panes=Array();
	this.nb=0;
	this.requestNext=0;
	this.requestPrev=0;
	this.docW=0;
	this.slideX=0;
	this.dTrans = 800;
	this.easing= "easeInOutQuad";//"easeInOutSine";
	this.dvoid=0;
	this.small = false;
	if( this.o.is(".pgpheSlideshowSmall"))
	{	this.small=true;
		this.dTrans=500;
	}
	if(this.o.is(".noGloss")) this.noGloss=true;
	this.wImg=this.small? 521:928;

	this.o.find(".pane").each(function(index){
		this.nbItems=index+1;		

		// store pane in pane list
		var me=$(this).findMe();
		me.panes[index]=$(this);
		me.nb++;

		// store index in pane
		$(this).data("index",index);

		// save img path in pane
		var img=$(this).find('img');
		$(this).data('img', img.attr('src'));
		img.remove();
		
		if(index==0)
		{	this.iCurr=-1;
		}
		$(this).find('.info').css({opacity:0.02});


	});
	
	if(this.nb>1) this.animateOK=1;
	self.setTimeout(function(){
		me1.M_onResized();
	},100);

	this.o.find(".cmdRight").click( function(){ var me=$(this).findMe(); me.requestPrev=0;me.requestNext++;return false;});
	this.o.find(".cmdLeft").click( function(){var me=$(this).findMe();me.requestNext=0;me.requestPrev++;return false;});
	this.o.find(".cmd").dblclick(function(){event.stopPropagation();return false;});
	this.oSlider1=this.o.find(".slider");
	this.oSlider2=this.o.find(".slider2");
	this.dvoid=new $("<span class=\"dvoid\"></span>");	
	//$("body").append(this.dvoid);

	// ----------------- methods --------------------------
	this.M_onResized = function()
	{
		var p=this.o.position();
		this.docW=$(document).width();
		this.slideX=parseInt(p.left);

		var isFirst=false;
		if( !this.gloss && !this.small && !this.noGloss)
		{	$("body").prepend("<div id=\"slideGloss\"><div class=\"mid\"><div class=\"right\"><div class=\"more\">"+(g.checker?"<div class=\"overlay\"></div>":"")+"</div></div></div></div>");
			
			this.gloss=$('#slideGloss');
			this.glossMid=this.gloss.find(".mid");
			this.glossRight=this.gloss.find(".right");
			this.glossMore=this.gloss.find(".more");
			this.gloss.css({opacity:0,zIndex:1,top:parseInt(p.top)+1});
			isFirst=true;
		}
		this.M_setGlossImages();
		if(isFirst)
		{	this.gloss.animate({opacity:g.checker?1.0:0.3});
		}

	}
	this.M_setGlossImages=function()
	{
		if( this.gloss)
		{
			var prev=this.panes[this.iPrev];
			var curr=this.panes[this.iCurr];
			var next=this.panes[this.iNext];
			if( prev&&curr)
			{	this.gloss.css({background:"url("+prev.data('img')+") no-repeat "+(this.slideX-this.wImg)+"px"});				
				this.gloss.find('.mid').css({background:"url("+curr.data('img')+") no-repeat "+(this.slideX)+"px"});
			
			}
			if( next)
			{	this.gloss.find('.right').css({background:"url("+next.data('img')+") no-repeat "+(this.slideX+this.wImg)+"px"});
			}
		}


	}

	this.M_setState=function(i)
	{
		RQDebug("M_setState("+this.o.data('index')+") - "+this.state+" --&gt; "+i);
		this.state=i;
		this.stateTime=0;
	}
	this.M_setIndexesForNext=function()
	{
		this.iPrev = (this.nb+this.iCurr-1)%this.nb;
		this.iNext = (this.iCurr+1)%this.nb;
	}
	this.M_animate=function(dt)
	{	this.stateTime+=dt
		if( this.state==0)
		{			
			this.M_setState(1);
		}
		else
		if( this.state==1)
		{
			var fn =RQDelegate(this,this.M_swapLayers);
			var fnStep =RQDelegate(this,this.M_stepAnimation);
			var param={duration:this.dTrans,easing:this.easing,queue:false,step:fnStep,complete:fn };
			if((this.stateTime>g.nextPhotoDelay) || (this.requestNext>0))			//start transition
			{	if(this.requestNext>0)this.requestNext--;

				if( this.gloss)
				{	var next2=this.panes[(this.iNext+1)%this.nb];
					if( next2)
						this.glossMore.css({background:"url("+next2.data('img')+") no-repeat "+(this.slideX+2*this.wImg)+"px"});
				}
				this.iOld=this.iCurr;
				this.iCurr = (this.iCurr+1)%this.nb;
				this.panes[this.iOld].find(".info").animate({opacity:0.01});
				this.M_setIndexesForNext();
				this.dvoid.animate({backgroundPosition:-this.wImg},param);
				//this.o.find(".slider").;
				this.M_setState(2);

			}
			else if( this.requestPrev>0)
			{	this.requestPrev--;
				if( this.gloss)
				{	var prev2=this.panes[(this.nb+this.iPrev-1)%this.nb];
					if( prev2)
						this.glossMore.css({background:"url("+prev2.data('img')+") no-repeat "+(this.slideX-2*this.wImg)+"px"});
				}
				this.iOld=this.iCurr;
				this.panes[this.iOld].find(".info").animate({opacity:0.01});
				this.iCurr = (this.nb+this.iCurr-1)%this.nb;
				this.M_setIndexesForNext();

				var curr=this.panes[this.iCurr];
				this.o.find(".slider2").css({background:"url("+curr.data('img')+") no-repeat -"+this.wImg+"px"});
				this.dvoid.animate({backgroundPosition:this.wImg},param);
				this.M_setState(2);
			}

		}
		else if( this.state==2)		// transition
		{
		}
	}
	this.M_stepAnimation=function()
	{	
		var x=parseFloat(this.dvoid.css('backgroundPosition'));
		var dir=x>=0?0:1;
		var xg=x+this.slideX;
		var w=this.wImg;
		if( this.oSlider1)this.oSlider1.css({backgroundPosition:x});
		if( this.oSlider2)this.oSlider2.css({backgroundPosition:dir?x+w:x-w});
		if( this.gloss)
		{
			this.gloss.css({backgroundPosition:xg-w});
			this.glossMid.css({backgroundPosition:xg});
			this.glossRight.css({backgroundPosition:xg+w});
			this.glossMore.css({backgroundPosition:dir?xg+2*w:xg-2*w});
		}

	}
	this.M_swapLayers=function()
	{	
		var curr=this.panes[this.iCurr];
		var next=this.panes[this.iNext];
		if( curr&&next)
		{
			this.o.find(".slider").stop().css({background:"url("+curr.data('img')+") repeat-x",backgroundPosition:0});
			this.dvoid.stop().css({backgroundPosition:0});
			this.o.find(".slider2").stop().css({background:"url("+next.data('img')+") no-repeat "+this.wImg+"px"});
		}
		this.M_setGlossImages(); //temp
		if(this.glossMore)this.glossMore.css({background:"transparent"});
		this.M_setState(1);
		this.M_showPane();

	}
	this.M_showPane=function()
	{	this.panes[this.iOld].hide();
		var curr=this.panes[this.iCurr];
		curr.show().find(".info").stop().show().css({opacity:1});		
	}

	// start 
	this.M_setIndexesForNext();
	this.M_swapLayers();

	//return this;
}

// RQGMAP


function testClick()
{	RQGMap.gmap.openInfoWindow(RQGMap.gmap.getCenter(),"hello");
}
function markerTipOut()
{
	if( g.maptip) { g.maptip.fadeOut('fast',function(){$(this).remove(); }); }
	g.maptip = 0;

}
function showMarkerTip(marker)
{
	var px = RQGMap.gmap.fromLatLngToContainerPixel(marker.getLatLng());
	g.maptip = $("<div class=\"gmapTip\"><div>"+marker.userData.name+"</div></div>");
	
	var posMap=$('#trip .tripMap').offset();
	g.maptip.css({"top": posMap.top+px.y,"left":posMap.left+px.x-94});
	$('body').append(g.maptip);
	g.maptip.fadeIn();
}

function myRQGMap_installMarkerClick()
{
	GEvent.addListener(RQGMap.gmap,"movestart",function(){markerTipOut();});

	var l
	for (var i=0;i<RQGMap.locations.length;i++)
	{	l=RQGMap.locations[i];
		if( l.marker)
		{
			l.marker.userData=l.where.userData
			GEvent.addListener(l.marker, "mouseover", function(overlay, latlng)
				{	
					markerTipOut();
					showMarkerTip(this);
					//for( var n in this) RQDebug(n+"=");
					//RQGMap.gmap.openInfoWindowHtml(this.getLatLng(),"<div class=\"gMapInfo\">"+marker.userData.name+"</div>");		// Ok
					
				}
			);
			GEvent.addListener(l.marker, "mouseout", function(){markerTipOut(); });
			GEvent.addListener(l.marker, "dblclick", function()
			{
				markerTipOut(); 
				RQGMap.gmap.setCenter(this.getLatLng() , this.userData.zoom); 
				showMarkerTip(this);				
			});

		}
	}
}



// Favorite Hotels
function MarkHotelAsFavorite(holidayId,locationId,locationIndex,hotelId)
{

//	$(".btnFavorite").removeClass('btnCurrentFavorite');
//	$("#btnMyFav"+hotelId).addClass('btnCurrentFavorite');
	
	RQAjaxCallPlugin('ListHolidays',"action=markFavorite&holidayId="+g.holId+"&locationId="+locationId+"&locationIndex="+locationIndex+"&hotelId="+hotelId,cbMarkHotelAsFavorite);

}
function cbMarkHotelAsFavorite(message,isErr)
{
	if( !isErr)
	{
		alert(message);
	}else alert("err");
}


function ButtonSendFormV2()
{
	if( holidayFormSubmittedV2())
	{
		pageTracker._trackPageview("/"+g.page+"/FormSubmittedOK");
		SubmitForm('formMakeYourHoliday');
	}
	else
	{	//RQDebug("/"+g.page+"/FormSubmittedInvalid");
		pageTracker._trackPageview("/"+g.page+"/FormSubmittedInvalid");
	}
}



function holidayFormSubmittedV2()
{
	var o
	var err = Array()
	if( o = getObj('formMakeYourHoliday'))
	{
		// remove all error messages 
		$(".invalidField").remove();

		var val,val2,val3;


		val = RQGetVariableValue('email');
		if( val.length < 4){	rqFormErrorMessage(err,"email","Please enter a valid e-mail address");}


		// name
		val = RQGetVariableValue('lastname');
		if( val.length < 2 ){	rqFormErrorMessage(err,"lastname","Please enter your last name");}


		val = RQGetVariableValue('dateTravel');
		if( val.length < 8 ){	rqFormErrorMessage(err,"dateTravel","Please enter your desired travel date, preferably in the format mm/dd/yyyy");}

		if( $('[name=dateTravel2]').length)
		{	val = RQGetVariableValue('dateTravel2');
		}

		val = RQGetVariableValue('phone');
		if( val.length < 8 ){	rqFormErrorMessage(err,"phone","Please provide us with a contact phone number");}

		val = RQGetVariableValue('numberTraveling');
		if( val.length < 1 ){	rqFormErrorMessage(err,"numberTraveling","Please tell us the number of people traveling");}
		
		if( $('#FormInput_destination').get(0))
		{
			val = RQGetVariableValue('destination');
			if( val.length < 3 ){	rqFormErrorMessage(err,"destination","Please indicate your desired destination");}
		}



		// submit if it's OK
		if( err.length == 0)
		{	SetVariable('action',"sendHolidayForm");
			return true;	
		}
		else
		{
			setSubmitMessage("<span class=\"submitErrorMessage\">The contact form seems incomplete. Please make the corrections and try again.</span>",true);
			return false;

		}
	}
	return false;
}
function setSubmitMessage(txt,allow)
{	
	//$('#holidaySubmitMessage').css({opacity:0.01}).html(txt).animate({opacity:1},1000);
}


function cbSourceSelect()
{
	if( $('#source').val() == 'other')
		$('#sourceOther').val("tell us?").focus(function(){if($(this).val()=='tell us?') $(this).val("");}).show('fast');
	else
		$('#sourceOther').hide();

}
	


function rqFormErrorMessage(err,varName,message)
{
	err[err.length] = varName;
	$("#FormInput_"+varName+" .inputContent").prepend("<span class=\"invalidField\">"+message+"</span>");
	$("#FormInput_"+varName).find("input,textarea").addClass("error").focus(function(){ $(this).removeClass("error");});

}



jQuery.fn.addScrollbar=function(opts)
{
	return $(this).each(function()
	{
		var t=opts.top?opts.top:0;
		var l=opts.left?opts.left:0;
		var c=$(this).find(opts.content);

		var s = $("<div class=\"scrollb\"><a class=\"aT\" /><a class=\"handle\" /><a class=\"aB\" /></div>");
		var ctn=$("<div class=\"scrllContainer\" />");
		var ctnH = g.scrollh+8*3;
		var cH=opts.cH?opts.cH:c.height();
		s.css({top:t,left:l});	
		ctn.css({height:ctnH,top:opts.ctnTop});
		var scrId="scr"+(g.scrCnt++);
		RQDebug("+ Adding scrollbar with c="+c.length+" cH="+cH+" ctnH="+ctnH);

		if( c.length && cH && (cH>ctnH))
		{	cH+=17;//??
			$(this).css({position:"relative",top:0,left:0});
			$(this).prepend(s);
			c.css("padding","0 0 0 0").wrap(ctn);
			var scH= g.scrollh * ctnH/cH;
			c.addClass(scrId).css({position:"relative",top:0,left:0});
			s.find("a.handle").data("scrId","."+scrId).data("maxY",g.scrollh-scH).data("cRat",cH/ctnH).css({height:scH}).mousedown(function(e){
				$(this).data("drg",1);
				g.dgy0=e.pageY;
				g.scr0=parseInt($(this).css("top"))-g.scry0;
				return 1;
			}).mousemove(function(e){
				if( $(this).data("drg")){
					var y=g.scr0+e.pageY-g.dgy0;if(y<0)y=0;var m=$(this).data("maxY");if(y>m)y=m;
					$(this).css({top:g.scry0+y});
					$($(this).data("scrId")).css({top:-$(this).data("cRat")*y});
				}
				return 0;
			}).bind("mouseup mouseleave",function(){
				$(this).removeData("drg");
			});
			s.find(".aT,.aB").click(scrollArrow);			
		}

	});
}
function scrollArrow()
{
	
	var t=$(this).siblings(".handle");
	var y = parseInt(t.css("top"))-g.scry0;
	y+=($(this).is(".aT")?-1:1)*g.scrLH/t.data("cRat"); if(y<0)y=0;var m=t.data("maxY");if(y>m)y=m;
	t.css({top:g.scry0+y});
	$(t.data("scrId")).css({top:-t.data("cRat")*y});				

}



// Printing
// ---------------------------------------------
function btnPrintCustomHoliday(id,hcode)
{
	popup('print'+id,g.url+'async.php?module=ListHolidays&action=print&id='+id+'&hcode='+hcode,800,600,"yes");
}

