// JavaScript Document

$.fn.zoomMovie = function(config){

	config = jQuery.extend({
		offset_x:-500,
		offset_y:350,
		bg_color:"#F9C",
		id:"zoom",
		player_path:"movie/player.swf",
		flash_added_id:"flash"
	},config);
	duration=300;
	setWindow();
	makeBlackLayer();
	
	return this.each(function(){
		//$(this).html("test");
		$(this).bind("click",action);
		
	});
	
	function setWindow(){
		
		window_id=config.id;
		//alert(window_id);
		window_selector=$("#"+window_id);
		//flash_added_id="flash";
		window_width=window_selector.width();
		window_height=window_selector.height();
		window_css={"position":"absolute","z-index":13,"display":"none"};
		window_selector.css(window_css);
		$("#"+window_id+" #"+window_id+"_close").bind("click",hideAll);
	}
	
	function makeBlackLayer(){
		//alert("tst");
		black_layer_id="black_layer";
		$("body").append('<div id="'+black_layer_id+'"></div>');
		black_layer_selector=$("#"+black_layer_id);
		black_layer_ini_css={
			"background-color":config.bg_color,
			"position":"absolute",
			"top":"0px",
			"left":"0px",
			"display":"none",
			"opacity":"0.6",
			"z-index":"12"
		};
		black_layer_selector.css(black_layer_ini_css);
	}
	
	function action(event){
		black_active_ini={"width":$("body").outerWidth(true)+"px","height":$("body").outerHeight(true)+"px","z-index":"12"};
		//black_layer_selector.show().fadeTo(2,0.6).bind("click",$(this),hideAll);
		black_layer_selector.css(black_active_ini).show().bind("click",$(this),hideAll);
		var top=event.pageY-config.offset_y+"px";
		var left=event.pageX-config.offset_x+"px";
		window_css={"top":top,"left":left,"display":"block","z-index":20};
		window_selector.css(window_css);
		path=$(this).attr("href");
		addSwf(path);
		//alert(path);
		return false;
	}
	
	function addSwf(path){
		//alert("addSwf");
		var flashvars = {};
		flashvars.path=path;
		var params = {};
		var attributes = {};
		swfobject.embedSWF(config.player_path, config.flash_added_id, "480", "350", "9.0.14", false, flashvars, params, attributes);
	}
	
	function hideAll(){
		window_selector.hide();
		black_layer_selector.hide();
		return false;
	};



};
