$(document).ready(function(){
	$("#inst-bar-pesquisar").focus(function() {
		if($(this).val() == '' || $(this).val() == 'palavra-chave') {
			$(this).val('');
		}
	});
	$("#inst-bar-pesquisar").blur(function() {
		if($(this).val() == '') {
			$(this).val('palavra-chave')
		};
	});
	
	if($.cookie("instbar-contrast")) {setActiveStyleSheet($.cookie("instbar-contrast"));}
	
	$('#inst-bar-opt-contrast a').click(function(e) {
		e.preventDefault();
		if ( getActiveStyleSheet() == 'default') {
			setActiveStyleSheet('high-contrast-w-b');
		} else {
			setActiveStyleSheet('default');
		}
	});
	
	if($.cookie("instbar-text") == 'bFont') {
		$('body').addClass('bFont');
	} else {
		$('body').removeClass('bFont');
	}
	
	$('#inst-bar-opt-increase-text a').click(function(e) {
		$.cookie("instbar-text","bFont", {expires: 365, path: '/'});
		e.preventDefault();
		$('body').addClass('bFont');
	});
	$('#inst-bar-opt-normal-text a').click(function(e) {
		$.cookie("instbar-text","sFont", {expires: 365, path: '/'});
		e.preventDefault();
		$('body').removeClass('bFont');
	});	
});

function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
	$.cookie("instbar-contrast",title, {expires: 365, path: '/'});
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

function getPreferredStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")) return a.getAttribute("title");
	}
	return null;
}
