/**
 * @author Marcin
 */

$.fn.slowfade = function(default_options) 
{
	var defaults = 
	{  
		duration:400,
		opacity:1,
		add_inner_html:false, 	//set true for text links
		use_class:false, 		// set to classname
		use_span_class:false, 	// set to classname
		ie6comp:false 			//ie6 compatibility mode, used when ie6 is used and wrapping item has no fixed width, set to classname
	};  
	var default_options = $.extend(defaults, default_options); 
	
	return this.each(function()
	{	
		var my = $(this);
		var $pos = my.css("position") == "absolute" ? "absolute" : "relative";
		var $bg = my.css("background-position") === undefined ? my.css("background-position-x") + ' ' + my.css("background-position-y") : my.css("background-position");
		var $inner_html = default_options.add_inner_html ? my.text() : "";
		
		if(!default_options.use_class)
		{
			my.css({position:$pos, backgroundPosition:"right bottom"});
		}
		else
		{
			my.addClass(default_options.use_class);
		}
		
		if(!default_options.use_span_class)
		{
			$hover_replace = $('<span>'+$inner_html+'</span>').appendTo(my).css(
			{	
				height: my.height(), width: my.width(), backgroundImage: my.css("background-image"), backgroundPosition: $bg,
				cursor: "pointer", position:"absolute",top:"0",left:"0",display:"block"
			});
		}
		else
		{
			$hover_replace = $('<span class="'+default_options.use_span_class+'">'+$inner_html+'</span>').appendTo(my);
		}
		
		if(default_options.ie6comp && $.browser.msie && $.browser.version.substr(0,1)<7)
		{
			$hover_replace.css({height: my.height(), width: my.width()}).addClass(default_options.ie6comp);
		}
					
		
		$hover_replace.hover(
		function()
		{	
			$(this).stop().animate({opacity: 0},default_options.duration);	
			if(default_options.opacity != 1) my.stop().animate({opacity: default_options.opacity},default_options.duration);	
		},
		function()
		{
			$(this).stop().animate({opacity: 1},default_options.duration);
			if(default_options.opacity != 1) my.stop().animate({opacity: 1},default_options.duration);	

		});
	});	
}

$(document).ready(function() {
	jQuery(".post img").lazyload({
		effect : "fadeIn",
		placeholder : "img/grey.gif"
	});
	
	jQuery('.post a:has(img), .post img')
		.css('cursor', 'default')
		.click(function(){return false;})
		.bind('contextmenu', function(){return false;}
	);
	jQuery('#topmenu li a').wrap('<span></span>');
	
	jQuery('#topmenu li:last').addClass('last');
	
	jQuery('#topmenu a').each(function(){
		$thisHref = jQuery(this).attr('href');
		$thisHref = $thisHref + '/#flashcontent';
		jQuery(this).attr('href', $thisHref);
	});
	
	jQuery('#footertext ul li:last a').addClass('last');
	
	jQuery('#footertext a').each(function(){
		jQuery(this).css('color', '#c1d0d4')
	});
	
	jQuery("div#hp a").slowfade({use_span_class:"slowfade",use_class:"slowfade_mod", add_inner_html:true, ie6comp:"ie6fix"});
	
});

