function preloader_ontimer(obj){
	var child,top;
		
	child = obj.childNodes[0];
	s = child.style.top;
	top = 0;	
	if(s.length > 0)
		top = parseInt(s);
	top -= 40;
	if(top < -440)
		top = 0;
	child.style.top = top+"px";
}
//--------------------------------------------------------------------------------------------
function hide_preloader_div()
{
	ovr = document.getElementById('fancybox-overlay');	
	if(ovr != null){
		ovr.style.display='';
		if(typeof(ovr.backcolor) != 'undefined')
			ovr.style.background = ovr.backcolor;
	}
	ovr = document.getElementById('fancybox-loading');	
	if(ovr != null){
		ovr.style.display='none';
		if(typeof(ovr.timer) != 'undefined')
			clearInterval(ovr.timer);
	}
}
//--------------------------------------------------------------------------------------------
function show_preloader_div()
{
	var ovr;
	
	ovr = document.getElementById('fancybox-overlay');
	if(ovr == null)
		return false;
	var userAgent = navigator.userAgent.toLowerCase();
	if (/msie/.test(userAgent) && !/opera/.test(userAgent) && !window.XMLHttpRequest) {
		var os = ovr.style;
		os.position = 'absolute';
		var width = document.documentElement["scrollWidth"] + 'px';
		var height = document.documentElement["scrollHeight"] + 'px';
		os.width = width;
		os.height = height;			
		os.filter = "alpha(opacity=50)";
	}
	else{
		ovr.style.width='100%';
		ovr.style.height='100%';
		ovr.style.position='fixed';
		ovr.style.opacity = 0.5;
	}
	ovr.style.top = 0;
	ovr.style.left = 0;
	ovr.style.display = 'block';	
	ovr.backcolor = ovr.style.background;
	if(arguments.length > 0)
		backcolor = arguments[0];
	else
		backcolor = '#000000';
	ovr.style.background = backcolor;
	ovr = document.getElementById('fancybox-loading');	
	ovr.style.display='block';
	ovr.childNodes[0].style.top = '0';
	ovr.timer = setInterval(function () {preloader_ontimer(ovr)},100);
	return true;
}
//--------------------------------------------------------------------------------------------
function init_thumb_footer_div(selector)
{
	$(selector).each(function() {			
		if($(this).css('cursor').indexOf('pointer') != -1){
			$(this).bind('click',function(){
				var href;
										
				href = $(this).parent().find('a').attr('href');
				if(href.length > 0)
					window.location.href = href;
			});
		}
	});
}
//--------------------------------------------------------------------------------------------
function init_hover_div(div)
{
	$(div).each(function() {
		$(this).bind({
			mouseenter: function() {
				var obj;
								
				obj = $(this).find('.thumb_hover');						
				obj.stop(true, true).fadeIn();
				$(obj).bind({
					mouseleave: function() {
						obj.unbind();
						obj.stop(true, true).fadeOut();
					},
					click: function(){
						var href;
								
						href = obj.parent().find('a').attr('href');
						if(href.length > 0)
							window.location.href = href;
					}
				});													
			}
		});
	});
}
//--------------------------------------------------------------------------------------------
function resizeImage(img){
	var w,h,wd,hd;
					
	w = $(img).width();
	h = $(img).height();
	wd = $(img).parent().width();				
	hd = wd / (w/h);
	if(w > wd || h > hd){
		var d_r;
					
		if(h > w)
			i_r = wd / w;
		else
			i_r = hd / h;
		d_r = 1.0 / ((w*h) / (wd*hd) * i_r);										
		$(img).width(Math.floor(w * d_r));
		$(img).height(Math.floor(h * d_r));
	}
	$(img).show();
}
