jQuery(function(){
	if(typeof(console) == "undefined") {
		console = function(){};
	}
	
	if (bannerOnHover) {
		ieSafeVersion = 8;
	} else {
		ieSafeVersion = 9;
	} 
	if ( jQuery.browser.msie &&  parseInt(jQuery.browser.version, 10) < ieSafeVersion) {
	  jQuery("#mask").remove();
	}
	
	jQuery("#mask").css('filter', 'alpha(opacity=60)');
	
	jQuery("#banner").mouseenter(function(e){
		jQuery("#mask").fadeIn();
	});
	
	jQuery("#banner").mouseleave(function(){
		jQuery("#mask").fadeOut();
		jQuery("a.tile, div.image", "#banner").removeAttr("style").find("*").removeAttr("style");
	});
	
	jQuery("body *:not(#banner, #banner *), body").bind("mousemove", function(){
		if(!jQuery(this).closest("#banner").length) {
			jQuery("#mask").fadeOut();
			jQuery("a.tile, div.image", "#banner").removeAttr("style").find("*").removeAttr("style");
			return false;
		} else {
			return false;
		}
	});
	
	jQuery("a.tile").bind("mouseenter hover", function(e){
		var id = jQuery(this).attr('id').split('-')[1];
		var tileImage = jQuery("#image-"+id);
		
		tileImage.css({
			'z-index' : '80'
		});
		
		jQuery("a.tile, div.image", "#banner").not(this).not(tileImage).removeAttr("style").find("*").removeAttr("style");
		
		if (bannerOnHover) {
			if (tileImage.children('img').attr('width') == '472') {
				return true;
			}
			else {
				tileImage.children('img').stop().animate({
					'height': '250',
					'width': '472'
				}, {
					duration: 400,
					complete: function(){
						jQuery("#caption-" + id).stop().slideDown(100);
						jQuery("#mask").fadeIn();
						//jQuery("a.tile, div.image", "#banner").not(this).not(tileImage).stop().removeAttr("style").find("*").stop().removeAttr("style");
					}
				});
				
				return false;
			}
		}
		
	});

	jQuery("a.tile").mouseleave(function(e){
		var id = jQuery(this).attr('id').split('-')[1];
		
		jQuery("#caption-"+id).slideUp(10);
		
		if (jQuery("#image-"+id).children('img').attr('width') == '236') {
			jQuery("#image-"+id).stop().css({
				zIndex: 10
				
			});
			jQuery("a.tile, div.image", "#banner").removeAttr("style").find("*").removeAttr("style");
		}
		else {
			jQuery("#image-"+id).children('img').stop().animate({
				'height' : '125',
				'width' : '236'
			}, {
				duration: 200,
				complete: function() {
					jQuery(this).parent().stop().css('z-index','10');
				}
			});
		}
	});
	
	jQuery("a.tile").click(function(){
		var id = jQuery(this).attr('id').split('-')[1];

		if (jQuery("#image-"+id).children('img').attr('width') == '472') {
			return true;
		}
		else {
			jQuery("#image-"+id).children('img').stop().animate({
				'height': '250',
				'width': '472'
			}, {
				duration: 400,
				complete: function() {
					jQuery("#caption-"+id).slideDown(100);
				}
			 });
			 
			 return bannerOnHover;	
		}
	});
}); 
