var menu = new Menu({
	elem:"#mainNav",
	lineElement: "#mainNav ul#secondNav",
	noMenuElem: "#nomenu"
});

$(document).ready(function() {
	$("a[rel*=external]").attr("target", "_blank");
	$("a[rel*=external]").click(function() {
		var sectionId = $(this).closest("section").attr("id");
		if(sectionId != "highlight" && sectionId != "downloadSection") {
			var _tracker = _gat._getTrackerByName();
			_tracker._trackPageview($(this).attr("href"));
		}
	});
	
	$("section#highlight a").click(function() {
		try {
			var _tracker = _gat._getTrackerByName();
			 _tracker._trackEvent('Highlights', "Click", $(this).attr("id"));
		} catch (e) {}
	});

	$("section#downloadSection a").click(function() {
		try {
			var _tracker = _gat._getTrackerByName();
			 _tracker._trackEvent('Catalogs', "Click", $(this).text());
		} catch (e) {}
	});

	if(!swfobject.hasFlashPlayerVersion("10.0.0")) {
		$("#mainNav ul li.flash-only").hide();
	}

	$("a#downloads").mouseenter(function() {
		$("section#downloadSection").css("visibility", "visible");
		$("section#downloadSection").show();
		$("section#downloadSection ul").mouseleave(function() {
            $("section#downloadSection").hide();
        });
    });

	$("#mainNav a, footer a").click(function() {
		try {
			var _tracker = _gat._getTrackerByName();
			 _tracker._trackEvent('Container', "Click", $(this).attr("href"));
		} catch (e) {}
	});


	$("section#downloadSection").css("visibility", "hidden");
	$("section#downloadSection").css("width",($("section#downloadSection ul").children().length * ($("section#downloadSection ul li:first-child").width() + parseInt($("section#downloadSection ul li:first-child").css("margin-left"))) + parseInt($("section#downloadSection ul li:last-child").css("margin-right")) + parseInt($("section#downloadSection .list").css("margin-left")) + parseInt($("section#downloadSection .list").css("margin-right")) ));

	var originalHtml = $(".copyright").html();
	var newHtml = "<small><img title='TOUS' alt='TOUS' src='/media/img/web/logos/logo-bear.gif' class='logo-bear'></small>";
	var windowWidth = 0;
	
	if($.browser.msie && $.browser.version <= 8){
		windowWidth = document.documentElement.clientWidth;

	}else {
		windowWidth = window.innerWidth;
	}
	
	
	if (windowWidth <= 1265) {			
		$(".copyright small").remove();
		$(".copyright").html(newHtml);
		
	} else if (windowWidth >= 1265) {
		$(".copyright small").remove();
		$(".copyright").html(originalHtml);
	}
	
	$(window).resize(function() {
		if($.browser.msie && $.browser.version <= 8){
			windowWidth = document.documentElement.clientWidth;

		}else {
			windowWidth = window.innerWidth;
		}
		
		if (windowWidth <= 1265) {			
			$(".copyright small").remove();
			$(".copyright").html(newHtml);
			
		} else if (windowWidth >= 1265) {
			$(".copyright small").remove();
			$(".copyright").html(originalHtml);
		}
	});
	
	$("#newsletterFooter").validate({
		rules: {
			"emailFooter": {
				required: true
			}
		},
		messages: {
			emailFooter: "Escribe tu email"
		}
	});
	
	
});

