//generic visible win function
function windowHeight(){
	var de = document.documentElement;
	return self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
}

//position tooltip previews
function positionTT(mousex, mousey){
	var offsetX = 12;
	var offsetY = 10;
	var ttHeight = $('#previewDiv').height();
	var topPos;
	var winHeight = windowHeight();
	var ttStat = mousey + ttHeight + offsetY;
	
	if (ttStat > winHeight) topPos = mousey - ttHeight - offsetY;
	else topPos = mousey + offsetY;

	 $('#previewDiv').css({
		        		left: mousex + offsetX, 
		        		top: topPos,
		        		visibility: 'visible'
	 });	    
}
//call tooltip previews function
function quickPreview(){
	$('a.articleLink').hover(
		function(a){//mouseover
		var mx = a.pageX;
		var my = a.pageY;
			$('#previewDiv').remove(); //kill tooltip fallback
			$(this).parent('li').append('<div id="previewDiv" style="visibility: hidden;"><p class="loading">Loading Preview...</p></div>');
			//set preview div location
			$(this).mousemove(function(e){positionTT(e.pageX, e.pageY);});
			//positionTT(mx, my);
          //call preview content
		 $.get(
		 	'/calendar/index.php/event/preview/'+$(this).attr('id'),
		 	function(data){
		 		$('#previewDiv').html(data);
		 		positionTT(mx, my);
                                //if($.browser.msie) { $( function() { $('select').css({visibility: 'hidden'});});}
		 	});
		},
		function(){//mouseout
			$('#previewDiv').remove(); //kill tooltip
                        //if($.browser.msie) { $( function() { $('select').css({visibility: 'visible'});});}
		});
}




//stretch calendar height to fit function
function setHeight(){
	$('#calendarArea').removeAttr('style');
	$('#calendarContent').removeAttr('style');
	$('#entry').removeAttr('style');
	var winHeight = windowHeight();
	var bodyHeight = $('body').height();
	var space = winHeight - bodyHeight - 25;
	if(space > 0){
		$('#calendarArea').css({height: $('#calendarArea').height() + space});
		$('#calendarContent').css({height: $('#calendarContent').height() + space});
		$('#entry').css({height: $('#entry').height() + space});
	}

}






/*------------------------------------
	Title: Cross-Browser Text Drop Shadows
	Author: Scott Jehl, www.scottjehl.com, scott@scottjehl.com
	Date: 7/19/06
http://creativecommons.org/licenses/by-nc-sa/2.5/
--------------------------------------*/


/*
createDropShadows function 
*/

function createDropShadows(){
//get the elements with the classname highContrast
var highContrast = $('.highContrast');

	for(i = 0; i < highContrast.length; i++){
		//current element
		var currentElement = highContrast[i];
		//current element's text
		var hcContent = currentElement.firstChild.data;
		//create a new span to replace the content text
		var contentSpan = document.createElement('span');
		var contentSpanText = document.createTextNode(hcContent);
		contentSpan.appendChild(contentSpanText);
		//create another span for the shadow text and give it the class "shadow"
		var shadowSpan = document.createElement('span');
		var shadowSpanText = document.createTextNode(hcContent);
		shadowSpan.appendChild(shadowSpanText);
		shadowSpan.className = "shadow";
		
		//kill the original text and toss the spans in there with the content on top
		currentElement.firstChild.data = '';
		currentElement.appendChild(shadowSpan);
		currentElement.appendChild(contentSpan);
	}
}



function ulEntries(){
	var sizeof = $('div.entryBlock').size();
	
	$('div.entryBlock').lt(sizeof-1).each(function(){$(this).addClass('multiEntry');});

}





//domready
$(function(){
	quickPreview();
	//setHeight();
	//window.onresize = function(){setHeight();}
	createDropShadows();
	ulEntries();
});
