/*
 * 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
 *
 */

		var jDate = new Date();
		var jTime = jDate.getHours();
		var jDay = jDate.getDay();
		var jZone = jDate.getTimezoneOffset()/60;
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = -8;
		yOffset = 4;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.r = this.rev;
		//this.s = this.class;
		this.title = "";
		var airnum;
		var airtime;
		var c = (this.t != "") ? this.t : "";
		var v = (this.r != "") ? this.r : "";
		var jWeek = jTime + (jDay * 24);
		var dif = sdr_current_num - jWeek;
		var j = dif - v;
		if(j < 0 ) {
			j = -(j) -24 ;// - 22;
		};
		//document.writeln(j);
		//j = j - 18
		//document.writeln(j);
		if(j < 0) {
			j = j + 168;
		};
		if(j < 24 ) {
			airnum = j;
			airtime = "Monday " + airFunc(airnum, jZone);
		}else if(j >= 24 && j < 48 ) {
			airnum = j - 24;
			airtime = "Tuesday " + airFunc(airnum, jZone);
		}else if(j >= 48 && j < 72 ) {
			airnum = j - 48;
			airtime = "Wednesday " + airFunc(airnum, jZone);
		}else if(j >= 72 && j < 96 ) {
			airnum = j - 72;
			airtime = "Thursday " + airFunc(airnum, jZone);
		}else if(j >= 96 && j < 120 ) {
			airnum = j - 96;
			airtime = "Friday " + airFunc(airnum, jZone);
		}else if(j >= 120 && j < 144 ) {
			airnum = j - 120;
			airtime = "Saturday " + airFunc(airnum, jZone);
		}else if(j >= 144 && j < 168 ) {
			airnum = j - 144;
			airtime = "Sunday " + airFunc(airnum, jZone);
		};
		var temp;
		function airFunc(airnum, jZone) {
			if(jZone <= 8 && jZone >= 5) {
				if(airnum == '0') {
					return '12:00 AM';
				}else if(airnum > 0 && airnum <= 12) {
					return airnum + ':00 AM';
				}else if(airnum >= 13) {
					temp = airnum - 12;
					return temp + ':00 PM';
				};
			}else{
				return airnum + ':00';
			};
			//return airnum + ':00';
		};
		
		$("body").append("<p id='preview'><span class='previewheader'>"+ c +"</span><img src='"+ this.rel +"' alt='Image preview' /><span class='previewshow'>"+ airtime +"</span></p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});