// roovers
var j = jQuery.noConflict();
j(document).ready(function () {
	// Override IE Google Toolbar Form stylings
	if(window.attachEvent) window.attachEvent("onload",setListeners);
	
	
	j('#nav a').bind('mouseenter', function() {			
		menuId = j(this).parent().attr("id");
		navRO(menuId);
	}).bind('mouseleave', function() {
		j(this).parent().removeClass('a_over');
		j(this).next().removeClass('dropdown_active');
	});
	j('#nav .dropdown').bind('mouseenter', function() {
		menuId = j(this).parent().attr("id");
		navRO(menuId);
	}).bind('mouseleave', function() {
		j(this).removeClass('dropdown_active');
		j(this).prev().parent().removeClass('a_over');
	});
	
	//Input pre-fill
	var ptest = document.createElement('input');
	if ("placeholder" in ptest) {
		j('*[placeholder]').focusin( function() {
			j(this).removeClass("prefill");
		}).focusout(function() {
			value = j(this).attr('value');
			if (value == '') {
				j(this).addClass("prefill");
			}
		});	
	}
	else {
		j('*[placeholder]').each(function() {
			value = j(this).attr('placeholder');
			j(this).attr('value', value);
		});
		j('*[placeholder]').focusin( function() {
			placeholder = j(this).attr('placeholder');
			value = j(this).attr('value');
			if (value == placeholder) {
				j(this).attr('value', '');
			}
			j(this).removeClass("prefill");
		}).focusout(function() {
			placeholder = j(this).attr('placeholder');
			value = j(this).attr('value');
			if (value == '') {
				j(this).attr('value', placeholder);
				j(this).addClass("prefill");
			}
		});
	}
	
	// target="_blank"
	j('a[target="_blank"]').click(function() {
		var target = j(this).attr('target');
		var href = j(this).attr('href');
		window.open(href, target);
		return false;
	});

});

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) {
	var current_a = j("#" + menuId + " a");
	var jdropdown = j("#"+ menuId +"_drop");
	if (jdropdown.length) {
		current_a.parent().addClass('a_over'); 
		if (!(jdropdown.hasClass('dropdown_active'))) {
			jdropdown.addClass('dropdown_active');
		}
	}
};

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