/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */

$j = jQuery.noConflict();

this.initImagePreview = function(){	
	/* CONFIG */
		xOffset = 330;
		yOffset = -180;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$j("a.preview").hover(function(e){
		this.t = this.lang;
		this.t = this.t.replace(/\\/g, "");
		var c = (this.t != "") ? "<div class='preview_description'>" + this.t+'</div>': "";
		var iOut = "<img src='"+ this.rel +"' alt='Image preview' />";
		var head = (this.t != "") ? "<div id='preview' style='width:300px; text-align:center;'>" : "<div id='preview'>";
		$j("body").append(head + iOut + c +"</div>");	
		//alert(head + iOut + c +"</p>");
		$j("#preview")
			.css("top", (e.pageY-$j("#preview").height()-50)+"px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = "";
		$j("#preview").remove();
    });	
	$j("a.preview").mousemove(function(e){
		/*$j("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");*/
		$j("#preview")
			.css("top", (e.pageY-$j("#preview").height()-50)+"px")
			.css("left",(e.pageX - $j("#preview").width()/2) + "px");
	});	
	
	
	 $j('.video_preview_trigger').hover(function(e){
			this.t = this.title;
			this.title = "";
			
			var c = (this.t != "") ? "<br/>" + this.t : "";
			var myparams = {
			        quality: "high",
			        scale: "noscale",
			        align: "topLeft",
			        wmode: "transparent",
			        allowscriptaccess: "always",
			        allowfullscreen: "false",
			        bgcolor: "#FFFFFF"
			    };
			var myflashvars = {};
			var id = $j(this).attr('id').split('_')[1];
		    myflashvars.mediaURL = "/videos/view_file/" + id;
			$j("body").append("<p id='preview'><span id='video_preview'>"+ c +"</span></p>");		
			$j('#video_preview').flash({
                swf : '/swf/video_preview_player.swf',
                height: "240",
                width: "320",
                hasVersion: '9.0.12',
                expressInstaller: '/swf/expressInstall.swf',
                flashvars: myflashvars,
                params: myparams 
            });
			$j("#preview")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");						
	    },
		function(){
			this.title = this.t;	
			$j("#preview").remove();
	    });	
		$j("a.video_preview_trigger").mousemove(function(e){
			
			$j("#preview")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px");
		});			
		
};


// starting the script on page load
$j(document).ready(function(){
	initImagePreview();
});
