/* $Id: main.js 2077 2008-12-17 16:06:23Z salban01 $ */
$(window).load( function() {
	fixIEMenu();
	onFormLoad();
});


/*
 * Note: this function is called from the window.onload inside the validation.js
 */

function fixIEMenu() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("menu");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
				this.className+=" over";
	 		}
	  	node.onmouseout=function() {
	 		this.className=this.className.replace(" over", "");
	  	}
	   }
	  }
	 }
}

/* for image hover bahavior for MENU */
function menuOver(img){
	img.src = img.src.replace('_off', '_on');
	var childs = img.parentNode.parentNode.parentNode.getElementsByTagName("ul");
	if(childs != null && childs.length > 0)
	childs[0].onmouseover = function () { img.src = img.src.replace('_off', '_on') };
	
}

function menuOut(img){
	if(img.title == 'Selected') {
		return;
	}
	img.src = img.src.replace('_on', '_off');
	var childs = img.parentNode.parentNode.parentNode.getElementsByTagName("ul");
	if(childs != null && childs.length > 0)
	childs[0].onmouseout = function () { img.src = img.src.replace('_on', '_off') };
}

/* for image hover bahavior */
function onImgOver(img){
	img.src = img.src.replace('_off', '_on');
}

function onImgOut(img){
	if(img.title == 'Selected'){
		return;
	}
	img.src = img.src.replace('_on', '_off');
}

function setPageLimit( object ) {
	
	var search = window.location.search;
	var path = window.location.pathname;
	
	if (object.options)
	{
		pagesize = object.options[object.selectedIndex].value;
	}
	else
	{
		pagesize = object.value;
	}
	
	if (search.indexOf('pagesize') != -1)
	{
		search = search.replace( /pagesize=([0-9]{0,3})/gi, ('pagesize=' + pagesize));
	}
	else
	{
		search = ( (search) ? '&' : '?' ) + 'pagesize=' + pagesize;
	}
	
	window.location.href = path + search;
}

var user_login_form_touched = false;
function user_login_form_hint( field, what )
{
	if ( user_login_form_touched )
	{
		return;
	}
	
	user_login_form_touched = true;
	
	//Fun
	$( field.form['name'] ).eq(0).val('').css('color', '#45465B');
	$( field.form['pass'] ).val('').css('color', '#45465B');

	var text = field.form.elements['pass'];
	var pass = text.cloneNode( false );
	var base = text.parentNode;
	
	pass.type = 'password';
	base.replaceChild( pass, text );
	
	return true;
	
	//window.alert( pass.html );
	//.clone().attribute('type', 'password');
	//$( field.form.elements['pass'] ).replaceWith( $pass );
	
	//var input = 
	//var input2= 
	//input2.type = 'password';
	//input.parentNode.replaceChild( input2, input );
} 
		 
$(document).ready(function() {
	// hover event for link images
	$(".loginDiv a img, .topLinksDiv a img, #menu img, .arrowDownLink img, .arrowUpLink img").hover(
			function() {
				if($(this).attr("title")=="Selected") {return;}
				this.src=this.src.replace("_off", "_on");
			}, 
			function() {
				if($(this).attr("title")=="Selected") {return;}
				this.src=this.src.replace("_on", "_off");
			}
		);
		
	var loc = window.location.toString();
	var start = ( loc.indexOf('http://') == -1 ) ? 0 : 7;
	var end = ( loc.indexOf('?') != -1 ) ? loc.indexOf('?') : loc.length;
	
	loc = loc.substr( start, end - start );
	loc = loc.substr( loc.indexOf('/') );	
	
	if( loc == '/sutv')
	{
		var winl = window.location.toString();
		if( winl.indexOf ( 'sid=' ) != -1 )
		{
			var s = winl.charAt( winl.indexOf('sid=') + 4 );
			loc = loc + '?sid=' + s;
		}						
	}
	if (loc == '/') {
		// promo arrow rollover effect	
		$(".centerBottomLeftPromoDiv div a").after("<img src=\"/sites/all/themes/su2c/images/arrow_off.jpg\" width=\"9\" height=\"9\" id=\"arrow_icon_off\" class=\"arrow_off\"/>");
		$(".centerBottomLeftPromoDiv div").each(function(){
			$(this).hover(function(){
				$(".arrow_off", this).fadeTo(300, 0);
			}, function(){
				$(".arrow_off", this).fadeTo(300, 1);
			});
		});

		
		$(".centerTopLeftPromoDiv div a").after("<img src=\"/sites/all/themes/su2c/images/img_rollover_arrow_big.gif\" width=\"10\" height=\"10\" id=\"arrow_icon_off_big\" class=\"arrow_off_big\"/>");
		$(".centerTopLeftPromoDiv div").each(function(){
			$(this).hover(function(){
				$(".arrow_off_big", this).fadeTo(300, 0);
			}, function(){
				$(".arrow_off_big", this).fadeTo(300, 1);
			});
		});	
	}
	
	$('#menu li ul li a').each( function () {
		if( loc == $(this).attr('href') )
		{
			$(this).addClass('selectedNavLink');
		}
	});
	
	// hover state for input type button
		$(".loginDiv #user-login-form input.form-submit").hover(			
			function() {$(this).css('background-color', '#6c6c6c');}, 
			function() {$(this).css('background-color', '#000');}
		);
	
	
		
});

