// roovers
$(document).ready(function () {
	
	$(".mo").mouseover(function(){
		if(!this.src.match(/-over/)){
			var dot = (this.src.lastIndexOf('.'));
			this.src = this.src.substr(0, dot)+'-over.'+this.src.substr((dot+1));
		}
	})
	.mouseout(function(){
		this.src = this.src = this.src.replace("-over","");
	});
	
	// Override IE Google Toolbar Form stylings
	if(window.attachEvent) window.attachEvent("onload",setListeners);
	
	
	$('#nav a').mouseenter(function() {			
		menuId = $(this).parent().attr("id");
		navRO(menuId);
	}).mouseleave(function() {
		$(this).removeClass('a_over');
		$(this).next().removeClass('dropdown_active');
		this.src = this.src = this.src.replace("-over","");
	});
	$('#nav .dropdown').mouseenter(function() {
		menuId = $(this).parent().attr("id");
		navRO(menuId);
	}).mouseleave(function() {
		$(this).removeClass('dropdown_active');
		var src = $(this).parent().find('img').attr("src").replace("-over", "");
		$(this).parent().find('img').attr("src", src);
	});
	
});

var cache = [];
function preLoadImages() {
	// Arguments are image paths relative to the current page.
	var args_len = arguments.length;
	for (var i = args_len; i--;) {
//console.log('preoading '+arguments[i]);
		var cacheImage = document.createElement('img');
		cacheImage.src = arguments[i];
		cache.push(cacheImage);
	}
}

// pre fill form field with message
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
}
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
}

function setListeners(){
    inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
        inputList[i].attachEvent("onpropertychange",restoreStyles);
        inputList[i].style.backgroundColor = "";
    }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
        selectList[i].attachEvent("onpropertychange",restoreStyles);
        selectList[i].style.backgroundColor = "";
    }
}

function restoreStyles(){
    if(event.srcElement.style.backgroundColor != "")
        event.srcElement.style.backgroundColor = "";
}

function navRO(menuId) {
	/*$("#slideshow").css({'z-index' : '-100'});
	$(".jCarouselLite").css({'z-index' : '-100'});
	$(".jCarouselLite ul").css({'z-index' : '-100'});*/

	var current_a = $("#" + menuId + " a");
	current_a.addClass('a_over'); 
	
	if ($("#" + menuId + " a").hasClass('a_over')) {
		img = $('#'+menuId+' a img');
		if(!img.attr('src').match(/-over/)){
			var dot = img.attr('src').lastIndexOf('.');
			img.attr('src', img.attr('src').substr(0, dot)+'-over.'+img.attr('src').substr((dot+1)));
		}		
	};

	var $dropdown = $("#"+ menuId +"_drop");
	if ($dropdown.length) {
		if (!($dropdown.hasClass('dropdown_active'))) {
			$dropdown.addClass('dropdown_active');
		}
	}
};

//--------------------------------------------
