$(document).ready(function() {
	$(window).trigger("resize");  
	
	$('a[rel=_blank]').attr('target','_blank');
	$('a[rel=_parent]').attr('target','_parent');
	$('a[rel=_self]').attr('target','_self');
	$('a[rel=_top]').attr('target','_top');
	
	var DefaultWidth = "140px";	
	$("#navigation li a.level1").hover( function() {
		var SlideUl = $(this).next();
		SlideUl.css({
			"width"    : "0px",
			"overflow" : "hidden"
		});
						
		SlideUl.animate({
			width 		: DefaultWidth
		}, "slow", function() {
			$(this).css({
				"overflow" : "visible"
			});
			// Animation complete.
		});	
	},
	function() {});

	$("#navigation ul li ul.sub a").hover( function() {
		var SlideUl = $(this).next();
		SlideUl.css({
			"width"    : "0px",
			"height"   : "auto",
			"overflow" : "hidden"
		});
						
		SlideUl.animate({
			width 	 : DefaultWidth
		}, "slow", function() {
			// Animation complete.
		});	
	},
	function() {});
	
	$("#footer .ticker ul").cycle({
		fx: 'fade',
		cleartype: 1 
	});
});

$(window).resize(function() {
	var BodyHeight 		= parseInt($("body").innerHeight());
	var SiteHeight 		= parseInt($("#site").innerHeight());
	
	var HeaderHeight = parseInt($("#header").outerHeight());
	var NavHeight		 = parseInt($("#navigation").outerHeight());
	var TextHeight	 = parseInt($("#content .column_middle").outerHeight());
	var FooterHeight = parseInt($("#footer").outerHeight());
	
	var TopOffset 	 = HeaderHeight + NavHeight + TextHeight;
	var NewScrollHeight = TopOffset + FooterHeight;
  
  var TextFooterHeight = TextHeight + FooterHeight;
	
	if(BodyHeight > NewScrollHeight) {
		$("body").css("overflow", "hidden");
		$("#container").css("height", "auto");
		$("#container").css("overflow", "visible");
	} else {
		$("body").css("overflow", "visible");
		$("#container").css("cssText", "height: " + TextFooterHeight + "px !important");
		$("#container").css("overflow", "hidden");
	}
	
	if($.browser.msie && $.browser.version < 7.0) {
	 // do not fix for ie6
	} else {
	//	if(BodyHeight < TopOffset) {
	
		if(((SiteHeight < BodyHeight) || (BodyHeight < 600)) && ($("#content .column_left").height < 600) || $("#site #homeblocks").length > 0) {
			$("#footer").css("position", "absolute");  
			$("#footer").css("bottom", "-1px");  
			$("#content .column_middle").css("padding-bottom","125px");		
		} else {
      $("#footer").css("display", "none");
      $("#footer").css("display", "block");
      
			$("#footer").css("position", "fixed");  
			$("#footer").css("bottom", "-1px");  
		}
	}
});
