/*
	Dependencies: jQuery 1.3.1
	We use jQuery() instead of $() due to a conflict with mootools, which the lightbox extension uses.
*/

var Alexir = {} 

Alexir.onLoad = function () {
	/* position the section rollovers and make them visible 	*/
	if (document.getElementById("ProductIndex") || document.getElementById("PartnershipIndex")) {
		var theIndex
		var InitFunction;
		var MouseOverFunction;
		var MouseOutFunction;
		
		function InitLayerFromTop (){
			InitFunction = function (theEl) {
				theEl.style.marginTop= "-" + jQuery(theEl).height() + 'px';
			}
			MouseOverFunction = function (){
				jQuery(this).find(".Inner").animate({marginTop: 0}, 300);
			}
			MouseOutFunction = function () {
				var theText = jQuery(this).find(".Inner");
				jQuery(theText).animate({marginTop: "-" + jQuery(theText).height()}, 300);
			}
		}
		
		function InitLayerFromBottom (){
			InitFunction = function (theEl) {
					theEl.style.marginBottom = - jQuery(theEl).height() + 'px'; 
			}
			MouseOverFunction = function (){
				jQuery(this).find(".Inner").animate({marginBottom: 0}, 300);
			}
			
			MouseOutFunction = function () {
				var theText = jQuery(this).find(".Inner");
				jQuery(theText).animate({marginBottom: "-" + jQuery(theText).height()}, 300);
			}
		}
		
		if (document.getElementById("ProductIndex")) { 
			theIndex = jQuery("#ProductIndex");
			InitLayerFromBottom ()
		}

		if (document.getElementById("PartnershipIndex")) {
			theIndex = jQuery("#PartnershipIndex");
			InitLayerFromTop ();
		}
		
		theIndex.find(".Inner").each (
			function(index, theEl){
				InitFunction (theEl);
				theEl.style.display = 'block';
			}	
		);
	
		/*section intro hover*/
	   jQuery(".IndexItem").hover(
			MouseOverFunction
			,
			MouseOutFunction
		);
	   
	   jQuery(".IndexItem").each ( /* Make the whole block clickable (if a link and only one link is found)*/
			function (){
				var theObj = jQuery(this);
				if (theObj.find("a").length == 1) {
					theObj.click(
						function () {window.location = theObj.find("a").get(0).href;}				   
					)
					theObj.addClass("WholeItemLinks");
				}
			} 
		);
	}
}

jQuery(document).ready(function(){Alexir.onLoad()});