$(document).ready(function(){

	$("input[disabled]").addClass("disabled");
	//$("input").bind("focus", function() {$(this).addClass("focus")});
	$("input").focus(function () {
         $(this).addClass("focus");
    });
	 $("input").blur(function () {
         $(this).removeClass("focus");
    });
	
	$(".fotoprod").hover(function(){
		var rutaimg;
		rutaimg = $(this).attr("src");
	  $(this).after("<div class='fotodetail'><img src="+ rutaimg +" width='200' height='200'></div>");
	},function(){
	  $(".fotodetail").remove();
});

	$("input")	
	
   doMenu.init();
   sendLogin.init();
   if($('#app').length > 0){
		$('table tbody tr:odd').addClass('odd');		
		$(document).not($('#menu')).click(function(){doMenu._reset()});
   }
   if(jQuery.browser.msie) fixFirstChild('#menu','#menu ul');
});


window.fixFirstChild = function(){
	for (var i=0; i<arguments.length; i++){
		if($(arguments[i]).length > 0){
			$(arguments[i]).children(':first-child').addClass('first-child');
		}
	}
}


var doMenu = {
	_reset : function(except){
		if(!except) except = '';
		$('#menu ul').not(except).hide();
		$('#menu a').not(except).each(function(){
			if ($(this).hasClass('active')) $(this).removeClass('active');
		});
	},
	show : function(node){
		node.slideDown('fast');
	},
	hide : function(node){
		node.slideUp('fast');
	},
	init : function(){
		doMenu._reset();
		$('#menu a').click(function() {
			if($(this).siblings().length > 0){
				if($(this).hasClass('active')){
					$(this).removeClass('active');
					doMenu.hide($(this).siblings());
					return false;
				}
				else{
					$(this).addClass('active');
					doMenu._reset($(this));
					doMenu.show($(this).siblings());
					return false;
				}
			}
		});
	}
}

var sendLogin = {
	msg : function(items){
		alert('Debe introducir '+items);
	},
	check : function(){
		var errText = '';
		var iUser = jQuery.trim($("#login_form_user").val());
		var iPw = jQuery.trim($("#login_form_pw").val());
		if(iUser.length == 0){
			errText += 'Nombre de usuario';
		}
		if(iPw.length == 0){
			errText += (errText != '')? ' y Contraseņa' : 'Contraseņa';
		}
		if(errText == ''){
			$("#login_form").submit();			
		}
		else{
			sendLogin.msg(errText);
		}
	},
	init : function(){
		$("#login_form :submit").click(function(e){
			sendLogin.check();
			return false;
		});
	}		
}

//Para cargar la css
function cargaCss(){
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	if (browser=="Microsoft Internet Explorer")
	{
		var oLink = document.createElement("link")
		oLink.href = "pages/comun/estilos/ie6.css";
		oLink.rel = "stylesheet";
		oLink.type = "text/css";
		document.body.appendChild(oLink);
	}
}