(function($) {
	$.fn.replaceFlash = function(options){
		var options = $.extend({
			attr: "rel"
		}, options);
		var noFlashShown = false;
		var noFlashAlert = $("div#no-flash");
		
		this.each(function(){
			object = $(this);
			image = object.find("img");
			
			object.flash({
				wmode: 'transparent',
				name: 'swf-'+object.attr('id'),
				id: 'swf-'+object.attr('id'),
				background: 'transparent',
				src: object.attr(options.attr),
				width: image.width(),
				height: image.height()
			}, {
				update: false
			});
			
			if(object.hasClass("flash-replaced")) {
				object.find('div.alt').remove();
			} else {
				noFlashAlert.slideDown();
				noFlashShown = true;
				
				$(".no-flash-close", noFlashAlert).click(function(){
					noFlashAlert.slideUp();
				});
			}
		});
	};
	
	$.fn.buttonLayers = function(options) {
		this.each(function(){
			var $obj = $(this);
			var link = $obj.find('a:first').attr('href');
			
			$obj.find("div.ifblur, div.ifdown").hide();
			$obj.find("div.origin").show();
			
			$obj.find("a").click(function(e){
				e.preventDefault();
			});
			
			$(this).hover(function(){
				$obj.removeClass("button-click").addClass("button-blur");
				$obj.find("div.ifdown, div.origin").hide();
				$obj.find("div.ifblur").show();
			}, function(){
				$obj.removeClass("button-blur button-down");
				$obj.find("div.ifblur, div.ifdown").hide();
				$obj.find("div.origin").show();
			}).click(function(e){
				e.preventDefault();
				
				$obj.removeClass("button-blur").addClass("button-down");
				$obj.find("div.ifblur, div.origin").hide();
				$obj.find("div.ifdown").show();
				
				if(link.length != 0 || link != '#') {
					window.location.href = link;
				}
			});
		}); 
	};
})(jQuery);

/*
 * Как пользоваться: log('inside coolFunc',this,arguments);
 * paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
 */
window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments))}};

$(document).ready(function() {
	$('div.flash').replaceFlash();
	$('.button').buttonLayers();
});
