//equalHeights by james padolsey
$(function(){	
	// activates the lightbox page
	my_lightbox("a[rel^='prettyPhoto'], a[rel^='lightbox'], a[rel^='iload'], area[rel^='iload']",true);
});

function showImg($link){
	//alert ($link);
	$.prettyPhoto.open($link);//$(this).attr('href')
	return false;
}


function my_lightbox($elements, autolink)
{	
	var theme_selected = 'light_rounded';
	
	if(autolink)
	{
		jQuery('a[href$="jpg"], a[href$="png"], a[href$="gif"], a[href$="jpeg"], a[href$="mov"] , a[href$="swf"] , a[href*="vimeo.com"] , a[href*="youtube.com"]').each(function()
		{
			if(!jQuery(this).attr('rel') != undefined && !jQuery(this).attr('rel') != '' && !jQuery(this).hasClass('noLightbox'))
			{
				jQuery(this).attr('rel','lightbox[auto_group]')
			}
		});
	}
	
	jQuery($elements).prettyPhoto({
			"theme": theme_selected /* light_rounded / dark_rounded / light_square / dark_square */});
	
	jQuery($elements).each(function()
	{	
		var $image = jQuery(this).contents("img");
		$newclass = 'lightbox_video';
		
		if(jQuery(this).attr('href').match(/(jpg|gif|jpeg|png|tif)/)) $newclass = 'lightbox_image';
			
		if ($image.length > 0)
		{	
			if(jQuery.browser.msie &&  jQuery.browser.version < 7) jQuery(this).addClass('ie6_lightbox');
			
			var $bg = jQuery("<span class='"+$newclass+" '></span>").appendTo(jQuery(this));
			
			jQuery(this).bind('mouseenter', function()
			{
				if ($image.css('opacity') >= 0.1) { jQuery(this).removeClass('preloading'); }
				
				var $height = $image.height(),
					$width = $image.width(),
					$pos =  $image.position(),
					$paddingX = parseInt($image.css('paddingTop')) + parseInt($image.css('paddingBottom')),
					$paddingY = parseInt($image.css('paddingLeft')) + parseInt($image.css('paddingRight'));					
				
				$bg.css({height:$height + $paddingY, width:$width + $paddingX, top:$pos.top, left:$pos.left});
			});
		}
	});	
	
	jQuery($elements).contents("img").hover(function()
	{
		jQuery(this).stop().animate({opacity:0.5},400);
	},
	function()
	{
		jQuery(this).stop().animate({opacity:1},400);
	});
}




