/* dana_menutree_anim  */


function init_menutree_anim()
{
$ml('.menutree_child .menutreetop li').hover(
	function(){
		var ul = $ml(this).find('ul:first');
		if (ul) {
			ul.stop();
			ul.css('opacity', 0);
			ul.css('display', 'block');
			ul.animate({
				opacity: 1
			}, 400);
		}
	},
	function(){ 
		var ul = $ml(this).find('ul:first');
		if (ul) {
			ul.stop();
			ul.animate({
				opacity: 0
			}, 400, 'linear', function(){
				$ml(this).css('display', 'none');
			});
		}
	});
$ml('.dropdownmenu .menutreetop li').hover(
	function(){
		var ul = $ml(this).find('ul:first');
		if (ul) {
			ul.stop();
			ul.css('opacity', 0);
			ul.css('display', 'block');
			ul.animate({
				opacity: 1
			}, 400);
		}
	},
	function(){ 
		var ul = $ml(this).find('ul:first');
		if (ul) {
			ul.stop();
			ul.animate({
				opacity: 0
			}, 400, 'linear', function(){
				$ml(this).css('display', 'none');
			});
		}
	});
}


// ----- EventListener

function attachEventListener(target, eventType, f, c)
{
  if(typeof target.addEventListener != "undefined") //w3c
  {
  	target.addEventListener(eventType, f, c);
  }
  else if (typeof target.attachEvent != "undefined") //IE
  {
  	target.attachEvent("on" + eventType, f);
  }
  else  //IE5Mac
  {
  	var eventName = "on" + eventType;
  	if(typeof target[eventName] == "function")
  	{
  		var prev = target[eventName];
  		target[eventName] = function()
  		                    {
  		                      prev();
  		                      return f();
  		                    };
     }
     else
     {
       target[eventName] = f;
     }
   }
}


// ----- Form 
function input_focus(obj)
{
   removeClass(obj, 'hinted');
   if(obj.value == obj.alt)
   {
     obj.value='';
   }
}
	
function input_blur(obj)
{
   if((obj.value == obj.alt)||(obj.value == ''))
   {
     addClass(obj, 'hinted');
     obj.value = obj.alt;
   }
}

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);


// ----- Misc 

function addClass(target, classValue)
{
   var pattern = new RegExp("(^| )" + classValue + "( |$)");
   if(!pattern.test(target.className))
   {
   	if(target.className == "")
   	{
   		target.className = classValue;
   	}
   	else
   	{
   		target.className += " " + classValue;
   	}
   }
}

function removeClass(target, classValue)
{
 var removedClass = target.className;

 var pattern = new RegExp("(^| )" + classValue + "( |$)");
 removedClass = removedClass.replace(pattern, "$1");
 removedClass = removedClass.replace(/ $/, "");
 
 target.className = removedClass;

}

function array_contains(arr, v)
{
  var len = arr.length;
  for (var i = 0; i < len; i++)
  {
      if(arr[i]===v){return true;}
  }
  return false;
}

function sub_array_contains(arr, v)
{
  var len = arr.length;
  for (var i = 0; i < len; i++)
  {
      if(arr[i][0]===v){return true;}
  }
  return false;
}


// ----- Resize

//call:  equalizeColumns('id1', 'id2', ....) where id1 and id2 are the div ids of the columns.
function equalizeColumns() 
{
	var bottom = 0; var stor;
	if(arguments.length > 1)
	{
		for(x=0; x < arguments.length; x++)
		{
			var column = document.getElementById(arguments[x]);
			if(column)
			{
				column.style.height = null;
				var colbottom = column.offsetTop + column.clientHeight; //column.offsetHeight;
				
				
				if(colbottom > bottom)
				{
					bottom = colbottom
				}
			}
		}				
		//height = height-2; /* border */
		if(bottom > 0)
		{
			for(x = 0; x < arguments.length; x++)
			{
				var column = document.getElementById(arguments[x]);
				if(column)
				{
					column.style.height = (bottom - column.offsetTop ) + 'px';
				}
			}
		}
	}
	
}

function sizePageInterior(fspace)
{
  var page = document.getElementById('page');
  if(page)
  {
    var contentFooter = document.getElementById('ridefooter');
    var footer = document.getElementById('footer');
    var fheight = footer ? footer.scrollHeight : fspace; //if footer is null, then we are probably in IE in a document that someone has broken. 
 
    var contentBottom = contentFooter ? contentFooter.offsetTop : 0; //ibid
    var windowBottom = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
    
   if (contentBottom + fspace < windowBottom)
   {
       page.style.height = (windowBottom-fheight)+ 'px';
   }
   else
   {
      page.style.height = (contentBottom + fspace) + 'px';
   }
  }
}

function handleOverflowX(minw)
{
  var windowWidth = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
  
  var top = document.body;
  if(windowWidth < minw)
  {
    
    top.style.overflowX = 'visible';
  }
  else
  {
    top.style.overflowX = 'hidden';
  }

}
 

// ----- textresizedetector

/** 
 *  @fileoverview TextResizeDetector
 * 
 *  Detects changes to font sizes when user changes browser settings
 *  <br>Fires a custom event with the following data:<br><br>
 * 	iBase  : base font size  	
 *	iDelta : difference in pixels from previous setting<br>
 *  	iSize  : size in pixel of text<br>
 *  
 *  * @author Lawrence Carvalho carvalho@uk.yahoo-inc.com
 * @version 1.0
 */

/**
 * @constructor
 */
TextResizeDetector = function() { 
    var el  = null;
	var iIntervalDelay  = 200;
	var iInterval = null;
	var iCurrSize = -1;
	var iBase = -1;
 	var aListeners = [];
 	var createControlElement = function() {
	 	el = document.createElement('span');
		el.id='textResizeControl';
		el.innerHTML='&nbsp;';
		el.style.position="absolute";
		el.style.left="-9999px";
		var elC = document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID);
		// insert before firstChild
		if (elC)
			elC.insertBefore(el,elC.firstChild);
		iBase = iCurrSize = TextResizeDetector.getSize();
 	};

 	function _stopDetector() {
		window.clearInterval(iInterval);
		iInterval=null;
	};
	function _startDetector() {
		if (!iInterval) {
			iInterval = window.setInterval('TextResizeDetector.detect()',iIntervalDelay);
		}
	};
 	
 	 function _detect() {
 		var iNewSize = TextResizeDetector.getSize();
		
 		if(iNewSize!== iCurrSize) {
			for (var 	i=0;i <aListeners.length;i++) {
				aListnr = aListeners[i];
				var oArgs = {  iBase: iBase,iDelta:((iCurrSize!=-1) ? iNewSize - iCurrSize + 'px' : "0px"),iSize:iCurrSize = iNewSize};
				if (!aListnr.obj) {
					aListnr.fn('textSizeChanged',[oArgs]);
				}
				else  {
					aListnr.fn.apply(aListnr.obj,['textSizeChanged',[oArgs]]);
				}
			}

 		}
 		return iCurrSize;
 	};
	var onAvailable = function() {
		
		if (!TextResizeDetector.onAvailableCount_i ) {
			TextResizeDetector.onAvailableCount_i =0;
		}

		if (document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID)) {
			TextResizeDetector.init();
			if (TextResizeDetector.USER_INIT_FUNC){
				TextResizeDetector.USER_INIT_FUNC();
			}
			TextResizeDetector.onAvailableCount_i = null;
		}
		else {
			if (TextResizeDetector.onAvailableCount_i<600) {
	  	 	    TextResizeDetector.onAvailableCount_i++;
				setTimeout(onAvailable,200)
			}
		}
	};
	setTimeout(onAvailable,500);

 	return {
		 	/*
		 	 * Initializes the detector
		 	 * 
		 	 * @param {String} sId The id of the element in which to create the control element
		 	 */
		 	init: function() {
		 		
		 		createControlElement();		
				_startDetector();
 			},
			/**
			 * Adds listeners to the ontextsizechange event. 
			 * Returns the base font size
			 * 
			 */
 			addEventListener:function(fn,obj,bScope) {
				aListeners[aListeners.length] = {
					fn: fn,
					obj: obj
				}
				return iBase;
			},
			/**
			 * performs the detection and fires textSizeChanged event
			 * @return the current font size
			 * @type {integer}
			 */
 			detect:function() {
 				return _detect();
 			},
 			/**
 			 * Returns the height of the control element
 			 * 
			 * @return the current height of control element
			 * @type {integer}
 			 */
 			getSize:function() {
	 				var iSize;
			 		return el.offsetHeight;
		 		
		 		
 			},
 			/**
 			 * Stops the detector
 			 */
 			stopDetector:function() {
				return _stopDetector();
			},
			/*
			 * Starts the detector
			 */
 			startDetector:function() {
				return _startDetector();
			}
 	}
 }();

TextResizeDetector.TARGET_ELEMENT_ID = 'doc';
TextResizeDetector.USER_INIT_FUNC = null;

