$(function() {
	var cuantosEnMenu = parseInt($("#cuantosEnMenu").val());
	var visiblesEnMenu = parseInt($("#visiblesEnMenu").val());;
	if(cuantosEnMenu > visiblesEnMenu){
		//scrollpane parts
		var scrollPane = $('#section');
		var scrollContent = $('#submenu');

		//build slider
		var scrollbar = $("#slider").slider({
			value: (parseFloat($("#subseccSeleccionado").val())*100),
			widthForm: 'width',
			slide:function(e, ui){
				if(scrollContent.width() > scrollPane.width() ){
					scrollContent.css('margin-left', Math.round( ui.value / 100 * ( scrollPane.width() - scrollContent.width() )) + 'px');
					
				}
				else {
					scrollContent.css('margin-left', 0);
				}
			}
		});
		
		if($("#subseccSeleccionado").length>0){
			$("#submenu").css('margin-left', Math.round( parseFloat($("#subseccSeleccionado").val()) * ( $("#section").width() - $("#submenu").width() )) + 'px');
		}
		
		var handleHelper = scrollbar.find('.ui-slider-handle')
		.append('<span class="ui-icon ui-icon-grip-dotted-vertical"></span>')
		.wrap('<div class="ui-handle-helper-parent"></div>').parent();
		
		//change overflow to hidden now that slider handles the scrolling
		scrollPane.css('overflow','hidden');
		
		//size scrollbar and handle proportionally to scroll distance
		function sizeScrollbar(){
			var remainder = scrollContent.width() - scrollPane.width();
			var proportion = remainder / scrollContent.width();
			var handleSize = scrollPane.width() - (proportion * scrollPane.width());
			scrollbar.find('.ui-slider-handle').css({
				'margin-left': 0
			});
			handleHelper.width('').width("100%");
		}
		
		//reset slider value based on scroll content position
		function resetValue(){
			var remainder = scrollPane.width() - scrollContent.width();
			var leftVal = scrollContent.css('margin-left') == 'auto' ? 0 : parseInt(scrollContent.css('margin-left'));
			var percentage = Math.round(leftVal / remainder * 100);
			scrollbar.slider("value", percentage);
		}
		//if the slider is 100% and window gets larger, reveal content
		function reflowContent(){
				var showing = scrollContent.width() + parseInt( scrollContent.css('margin-left') );
				var gap = scrollPane.width() - showing;
				if(gap > 0){
					scrollContent.css('margin-left', parseInt( scrollContent.css('margin-left') ) + gap);
				}
		}
		
		//change handle position on window resize
		$(window).resize(function(){
				resetValue();
				sizeScrollbar();
				reflowContent();
		});
		//init scrollbar size
		setTimeout(sizeScrollbar,10);//safari wants a timeout
	}
	
	$("div.mod14txt").bind("mouseenter",function(){
		$(this).stop().animate(
				{top: "50px", height: "150px"}, 
				1000
		);
		return false;
	}).bind("mouseleave",function(){
		$(this).stop().animate(
				{top: "125px", height: "40px"}, 
				1000
		);
		return false;
	});

	
	
	/* Hack para IE6 */
	if (!$.browser.msie || ($.browser.msie && parseFloat(navigator.userAgent.toLowerCase().substr(navigator.userAgent.toLowerCase().indexOf('msie')+5, 3))>6)) {
		$(".lavaLamp").lavaLamp({ 
			fx: "backout", 
			speed: 800,
			click: function() {
			}
		});
	}
	
	if (($.browser.msie && parseFloat(navigator.userAgent.toLowerCase().substr(navigator.userAgent.toLowerCase().indexOf('msie')+5, 3))<7)) {
		$("#section #submenu .mod14").bind("mouseenter",function(){
			$(this).css("background-color","#9b0");
		});
		
		$("#section #submenu .mod14").bind("mouseleave",function(){
			if ($(this).hasClass("seccAct")) {
				$(this).css("background-color","#AACC00");
			} else {
				$(this).css("background-color","#8a0");
			}
		});
		
		$(".mod14 a").bind("mouseenter",function(){
			/*thepngfix();*/
			DD_belatedPNG.fix(".mod14 a:hover");
		});
	}
	 
	$("#privacidad").live("click",function(e) {
		e.preventDefault();
		e.stopPropagation();
		$.get($(this).attr("href"),{},function(c) {
			$('<div>'+c+'</div>').dialog({width:750});

		});


	});	
});

