/*
 * Pharmatheke.com - initializing visual engine v.5
 *
 * Copyright (c) 2007 Rafi B.
 *
 * $Date: 2007-07-11$
 */

// Initialize the date pickers. If any.
Date.format = 'mm/dd/yyyy';
$(function() {
	//$('input.date-pick', $('#content')).datePicker({clickInput:true, startDate:'01/01/2000'});
	$('input.date-pick', $('#PAGE')).datePicker({clickInput:true, startDate:'01/01/1950'});
});

// Preload images
jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
};

$(document).ready(
	function()
	{
		// Bind the side bar tabs toggle button with the appropriate event for onclick
		$('#sidebar div.tab a.toggleme').bind('click', toggleSideBarTab);

		// Make the sidebar and content div the same hieght. Why? because of the small line the separates them both.
		if ($('#content').height() > $('#sidebar').height()) {
			$('#sidebar').height($('#content').height()-50);
		} else {
			// If sidebar is higher than content, then just make the height fixed.
			$('#sidebar').height($('#sidebar').height());
		}
		
		$('img[@src$=.png], #subfooter').pngfix();
	}
);

$(window).bind('load',
	function() {
		// Preload images
		var preload = [
			'/media/images/layout/sidetab_foot_closed.gif',
			'/media/images/layout/sidetab_foot.gif',
			'/media/images/layout/subnav_item.gif',
			'/media/images/layout/subnav_item_on.gif',
			'/media/images/layout/tab_head_close.gif',
			'/media/images/layout/tab_head_open.gif',
			'/media/images/loading.gif'
		];           
		$(document.createElement('img')).bind('load', function(){
			if(preload[0]) this.src = preload.shift();
		}).trigger('load');
	}
);

var toggleSideBarTab = function(e)
{
	$(this).siblings("div").slideToggle(300, function(){
			img = ($(this).css("display") == "none") ? "/media/images/layout/sidetab_foot_closed.gif" : "/media/images/layout/sidetab_foot.gif";
			$(this).next("a").children("img").attr("src", img);
	});
	this.blur();
	return false;
};
