/*
* Url preview script 
* written by Alen Grakalic (http://cssglobe.com)
* for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
*
*/
this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 01;
		yOffset = 15;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.print-project").hover(function(e){
		this.t = this.title;
		this.title = "";	
		//var c = (this.t != "") ? "" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' /></p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.print-project").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


$(document).ready(function() {
   	
	// Load into dialog box
	$('#intro-window').jqm({modal: true, trigger: 'a.showDialog'});
	$('#intro-window').jqmAddClose('.hideDialog'); 
	$('#intro-window').jqmShow(); 
	
	// Call URL preview script 
	screenshotPreview();
	
	//1. Create a function to call, whenever you click a link.
	$('#content-screen a.print-project').click(function(){
		
		// 2. Hide any existing projects which are showing (if a link has been clicked before)
		$('#content-print .project img').hide();

		// 3. show div with same id as link in controller div
		// get the href that corresponds to the div you want to to show and use it to select and show it
        var projectid=$(this).attr("href");
		
		$('#content-print .project'+projectid+' img').css("display","block");
		
		// 4. Print only once the correct images are showing
		window.print();
		
		// 5. Show popup with time/date printed
		
		function popitup(url) {
			 var newwin; 
			 var width  = 302;
			 var height = 130;
			 var left   = (screen.width  - width)/2;
			 var top    = (screen.height - height)/2;
			 var params = 'width='+width+', height='+height;
			 params += ', top='+top+', left='+left;
			 params += ', directories=no';
			 params += ', location=no';
			 params += ', menubar=no';
			 params += ', resizable=no';
			 params += ', scrollbars=no';
			 params += ', status=no';
			 params += ', toolbar=no';
			
			 newwin=window.open(url,'name', params);
			 	if (window.focus) {newwin.focus()}
			 return false;
			
		}
		
		return popitup('./dialog.html');
		return false;
		
	});
	
});