$(document).ready(function() {

	/*
	 * Clear Buscar Input
	 */
	defaultValue = $("input#s").attr("value");		
	$("input#s").focus(function() {
		$(this).attr("value","");
	});
	$("input#s").blur(function() {
		if ($(this).attr('value') == "")
			$(this).attr("value", defaultValue);
	});
	

	// nav	
	// maintain selected
	$("div#nav ul li a.ne").mouseover(function(e) {
		$(this).parent("li").addClass('hover');	
	}).mouseout(function(e) {
		$(this).parent("li").removeClass('hover');
	});
	$("div#nav ul li ul").mouseover(function(e) {
		$(this).parent("li").addClass('hover');
	}).mouseout(function(e) {
		$(this).parent("li").removeClass('hover');
	})
	
	//hovers 
	$(".hvr").mouseover(function(e) {
		$(this).addClass('hover');
	}).mouseout(function(e) {
		$(this).removeClass('hover');
	}).mousedown(function(e) {
		
		var a = $(this).find("a");
		var firstA = a[0];
		// fix for not breaking lightbox behaviour
		var isLightbox = ($(firstA).attr('rel').indexOf('shadowbox') > -1);
		if (isLightbox)
			$(firstA).click();
		else
			document.location.href = firstA.href;
			
	});
	
	// share this
	$("div#sharethis ul").css('display','none');
	$("div#sharethis p a").click(function(e) {
		e.preventDefault();
		$(this).parents("div#sharethis").addClass('hover').children("ul").css('display','block');
	});
	
	// layout fix for ie 
	if ($.browser.msie) {
		$("#page").css('height','1%');
	}
	
	// intercept enter click
	//http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/
	/*$("input, select").live("keypress", function (e) {
        //var code = (e.keyCode ? e.keyCode : e.which);
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { // press ENTER
            //e.preventDefault()
            var search_ele = "button[type=submit].default, p.button a, input[type=submit].default";
            var a = $(this).parents("fieldset").find( search_ele );
            var val = (a.onclick)? eval(a.onclick.replace('return ','')) : true;
            console.log(a[0].href)
            alert(a[0].id);
            if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate()) __doPostBack(a[0].id,'';
            return false;
        } else {
            return true;
        }
    });*/
});



// importar js script dinamicamente
//http://betterexplained.com/articles/speed-up-your-javascript-load-time/
function $import(src){
  var scriptElem = document.createElement('script');
  scriptElem.setAttribute('src',src);
  scriptElem.setAttribute('type','text/javascript');
  document.getElementsByTagName('head')[0].appendChild(scriptElem);
}

// import with a random query parameter to avoid caching
function $importNoCache(src){
  var ms = new Date().getTime().toString();
  var seed = "?" + ms; 
  $import(src + seed);
}
