/**
 * Global Onload Method
 * 
 * currently this sets up the tell a friend popup in a lightbox as well as sets up the bookmark site link.
 */
$(function() {
	
	// attach fancybox to the send to friend link in the footer if both exist
	if ($.fancybox && $('#tellAFriend').length >= 1) {
		$('#tellAFriend').fancybox({
			'autoScale'			: false,
			'scrolling'			: 'no',
			'centerOnScroll'	: true,
			'overlayOpacity'	: 0.5,
			'overlayColor'		: '#000', 
			'showNavArrows'		: false,
			'width'				: 420,
			'height'			: 310,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'type'				: 'iframe'
		});
	}
	
	// attach fancybox to home page video
	if ($.fancybox && $('#youtube').length >= 1) {
		$('#youtube').fancybox({
			'autoScale'			: false,
			'scrolling'			: 'no',
			'centerOnScroll'	: true,
			'overlayOpacity'	: 0.5,
			'overlayColor'		: '#000', 
			'showNavArrows'		: false,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'type'				: 'iframe'
		});
	}
	
	// attach jquery bookmark plugin to the bookmark site link.
	if (document.getElementById('bookmarkSite') && $('#bookmarkSite').length >= 1) {
		$('#bookmarkSite').jFav();
	}
	
	// Login boxes

	$('#middle-bar-right input.username-fld').focus(function()
	{
		if (this.value=='Username')
			this.value='';
	});
	$('#middle-bar-right input.username-fld').blur(function()
	{
		if (this.value=='')
			this.value='Username';
	});

	$('#middle-bar-right input.password-fld').focus(function()
	{
		if (this.value=='Password')
		{
			this.value='';
			if (!document.all)
				this.type='password';
		}
	});
	$('#middle-bar-right input.password-fld').blur(function()
	{
		if (this.value=='')
		{
			this.value='Password';
			if (!document.all)
				this.type='text';
		}
	});

	if (!document.all)
	{
		$('#middle-bar-right input.password-fld').each(function()
		{
			if (this.value!='Password')
				this.type='password';
			else
				this.type='text';
		});
	}

	if ($('#act-spotlight-cell').length>0)
	{
		var tmp_y, tmp_h=0+$('td#leftbar-cell').height();

		tmp_y=tmp_h-468;
		if (tmp_y>0)
			$('#act-spotlight-cell').height( tmp_y );
	}

	$('#hdr-search-box input.search-fld').focus(function()
	{
		if (this.value=='Enter Search')
			this.value='';
	});
	$('#hdr-search-box input.search-fld').blur(function()
	{
		if (this.value=='')
			this.value='Enter Search';
	});
	
	if ($('#hdr-search-box input.search-fld').length>0 && $('#hdr-search-box input.search-fld').val()=='')
		$('#hdr-search-box input.search-fld').val('Enter Search');

});


/**
 * This is a jquery plugin that I use to preload a bunch of images, its easy to use, just call 
 * 
 * $.preLoadImages("image1.jpg", "image2.jpg")
 * 
 */
(function($) {
	var cache = [];
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);	
		}
	};
})(jQuery);




/* EMAIL FUNCTIONS NEED TO BE PUT INTO AN OVERLAY - REMOVE WHEN DONE */
function email_this_item(i) {
	var win, ht;
	ht=340;
	win=window.open('/pages/email_this_page.php?item='+escape(i), 'email_this_item','resizable,width=420,height='+ht+',left=200,top=120,status');
}


function changePerPage(osel) {

	var val = osel[osel.selectedIndex].value;
	url = new Url(location.href);
	url.setVar('perpage', val);
	url.go();

}

function changeOrder(osel) {
   var val = osel[osel.selectedIndex].value;
   url = new Url(location.href);
   url.setVar('order', val);
   url.go();
}

function toggleDirection(dir) {
   var set = (dir == 'ASC') ? 'DESC' : 'ASC';
   url = new Url(location.href);
   url.setVar('dir', set);
   url.go();
} 

function showHide(element) {
	if(jQuery(element).css('display') == "none"){
		jQuery(element).slideDown('fast');
	}else{
		jQuery(element).slideUp('fast');
	}
}

function over(obj) {
	// first lets see if the src of this image is blank.gif and if its IE6 - Based on these conditions
	// we know that its a png fix so we need to alter the method of changing the image background as oposed
	// to the image source.
	var filename = obj.src.substring(obj.src.lastIndexOf('/')+1);

	// first lets check to see if its IE6 and if the image in a png file
	if(filename == 'blank.gif' && $.browser.msie && $.browser.version == '6.0') {
		var newFilter = (obj.style.filter.replace('.png', '-over.png'));
		obj.style.filter = newFilter;
	} else {
		obj.src=obj.src.replace('.gif', '-over.gif');
		obj.src=obj.src.replace('.jpg', '-over.jpg');
		obj.src=obj.src.replace('.png', '-over.png');
	}
}
 
function out(obj) {
	var filename = obj.src.substring(obj.src.lastIndexOf('/')+1);
	if(filename == 'blank.gif' && $.browser.msie && $.browser.version == '6.0') {
		obj.style.filter = obj.style.filter.replace('-over', '');
	} else {
		obj.src=obj.src.replace('-over', '');
	}
}


function SelectAllCalEvents(chk)
{
	$('input.selected-calevents').attr('checked', chk);
}


