$(document).ready(function(){
	$(".hidden_on_load").each(function(i) {
		$(this).css("display", "none");
		$(this).removeClass("hidden_on_load");
	});
	$("a.print").css("display", "block");

	$("#column-a ul li a").hover(function() {
		$(this).parent().children("div.note").css("display", "block");
	},function() {
		$(this).parent().children("div.note").css("display", "none");
	});

	$("#info-user p.login a").click(function() {
		if ("none" == $(this).parent().parent().children("#box-login").css("display")) {
			$(this).parent().parent().children("#box-login").css("display", "block");
		} else {
			$(this).parent().parent().children("#box-login").css("display", "none");
		}
		return false;
	});

	$("#info-user div#box-login form p.close a").click(function() {
		$(this).parent().parent().parent().parent().children("#box-login").css("display", "none");
		return false;
	});

	$(document).bind('click', function(e) {
		var $clicked=$(e.target);
		if( ! ( $clicked.is('#box-login') || $clicked.parents().is('#box-login') ) ) {
			$('#box-login').hide();
		}
	});

	$("ul.inside-news li").hover(function() {
		$(this).addClass("hover");
	},function() {
		$(this).removeClass("hover");
	});
	
	$("ul.home-news li").hover(function() {
		$(this).addClass("hover");
	},function() {
		$(this).removeClass("hover");
	});
	
	$("table.data-a tbody tr").hover(function() {
		if ($(this).find("a").length) {
			$(this).addClass("hover");
		}
	},function() {
		if ($(this).find("a").length) {
			$(this).removeClass("hover");
		}
	});
	
	$("ul.list-a li").each(function(i) {
		if ($(this).hasClass("active") && $(this).hasClass("category-0" + (i+1))) {
			$(this).children("a").css("background-image", "url(mult/icon-category-0" + (i+1) + "b-32px.png)");
		}
	});

	$("button.submit").hover(function() {
		$(this).addClass("hover");
	},function() {
		$(this).removeClass("hover");
	});
	
	$("button.cancel").hover(function() {
		$(this).addClass("hover");
	},function() {
		$(this).removeClass("hover");
	});
	
	if ($("#column-e").length) {
		var nBorderX = $("#column-e").outerWidth() + $("#column-e").position().left - $("#column-d").position().left - 1;
		var nBorderY = $("#column-e").position().top - $("#column-d").position().top;
		$("#column-e").parent("#column-d").css("background-position", nBorderX + "px " + nBorderY + "px");
		$("#column-e").parent("#column-d").css("background-repeat", "no-repeat");
		$("#column-e").parent("#column-d").css("background-image", "url(mult/border-01.png)");
	}

	$("div.more-info").each(function(i) {
		$(this).css("display", "none");
	});
	$("button.more-info").each(function(i) {
		$(this).css("display", "");
	});

	$("button.more-info").click(function() {
		if ($(this).hasClass("active")) {
			$(this).removeClass("active");
			$(this).parent().next("div.more-info").css("display", "none");
		} else {
			$(this).addClass("active");
			$(this).parent().next("div.more-info").css("display", "block");
		}
		return false;
	});

	$("button.more-info").hover(function() {
		$(this).addClass("hover");
	},function() {
		$(this).removeClass("hover");
	});

	$("div.team ul li ul").css("display", "none");
	$("div.team ul li").removeClass("opened");
																						
	$("div.team ul li p.name a").click(function() {
		if ($(this).parent().parent().children("ul").length) {
			if ($(this).parent().parent().hasClass("opened")) {
				$(this).parent().parent().children("ul").css("display", "none");
				$(this).parent().parent().removeClass("opened");
			} else {
				$(this).parent().parent().children("ul").css("display", "");
				$(this).parent().parent().addClass("opened");
			}
			return false;
		}
	});
	
	$("div.area-select div.buttons a.button-01").click(function() {
		var oSelectA = $(this).parent().prev("div.multi-select").children("select");
		var oSelectB = $(this).parent().next("div.multi-select").children("select");
		oSelectA.children("option:selected").remove().appendTo(oSelectB);
		oSelectB.children("option:selected").attr("selected","");
		return false;
	});
	
	$("div.area-select div.buttons a.button-04").click(function() {
		var oSelectA = $(this).parent().prev("div.multi-select").children("select");
		var oSelectB = $(this).parent().next("div.multi-select").children("select");
		oSelectB.children("option:selected").remove().appendTo(oSelectA);
		oSelectA.children("option:selected").attr("selected","");
		return false;
	});
	
	if (typeof $.fn.prettyPhoto == 'function') {
		$("a[rel^='prettyPhoto']").prettyPhoto({showTitle: false});
	}

	$("a[rel^='prettyPhoto']").hover(function() {
		$(this).prepend('<div class="image-zoom" style="margin-left: ' + ($(this).find('img').width() / 2 - 10) + 'px; margin-top: ' + ($(this).find('img').height() / 2 - 10) + 'px;"></div>');
		$(this).find('img').css("filter", "alpha(opacity=50)");
		$(this).find('img').css("-moz-opacity", "0.5");
		$(this).attr({title: $(this).find('img').attr("alt")});
	},function() {
		$(this).find('div.image-zoom').remove();
		$(this).find('img').css("filter", "alpha(opacity=100)");
		$(this).find('img').css("-moz-opacity", "1");
	});
	
	function portletActions() {
		$('li.portlet div.title h4 a').click(function()
			{
				$(this).parent().parent('div').next('div').toggle();
				if ($(this).hasClass("opened")) {
					$(this).removeClass("opened");
				} else {
					$(this).addClass("opened");
				}
				return false;
			}
		);
	
		$('li.portlet div.title p.edit a').click(function()
			{
				$(this).parent().parent().next('div.content').children('div.edit').toggle();
				return false;
			}
		);
	
		$('li.portlet div.content div.edit div.edit-title p.finish a').click(function()
			{
				$(this).parent().parent().parent().toggle();
				return false;
			}
		);
	
		$('li.portlet div.content div.edit div.edit-title p.close a').click(function()
			{
				$(this).parent().parent().parent().toggle();
				return false;
			}
		);
	
		$('li.portlet div.content div.edit button.cancel').click(function()
			{
				$(this).parent().parent().parent().toggle();
			}
		);

		$('li.portlet div.content div.edit button.submit').click(function()
			{
				$(this).parent().parent().parent().toggle();
				return false;
			}
		);

		$("button.submit").hover(function() {
			$(this).addClass("hover");
		},function() {
			$(this).removeClass("hover");
		});
		
		$("button.cancel").hover(function() {
			$(this).addClass("hover");
		},function() {
			$(this).removeClass("hover");
		});
		
		$('div.portlets').equalHeights();
	}
	
	function savePortletPositions(e, ui) {
		var sUrl = "21.html";
		var sPositions = 'column-a=' + $('#portlet-column-a').sortable('toArray') + '&column-b=' + $('#portlet-column-b').sortable('toArray') + '&column-c=' + $('#portlet-column-c').sortable('toArray');
		//alert(sUrl + '?' + sPositions);
		$.ajax({
			type: "GET",
			url: sUrl,
			data: sPositions
		});
	}
	
	if (typeof $.fn.sortable == 'function') {
		$("#portlet-column-a").sortable({
			connectWith: ["#portlet-column-b","#portlet-column-c"],
			tolerance: 'intersect',
			opacity: 0.5,
			handle: 'div.title',
			placeholder: 'sort_placeholder',
			revert: true,
			scroll: true,
			zIndex: 1000,
			update: guardarCambios
		});
		$("#portlet-column-b").sortable({
			connectWith: ["#portlet-column-a","#portlet-column-c"],
			tolerance: 'intersect',
			opacity: 0.5,
			handle: 'div.title',
			placeholder: 'sort_placeholder',
			revert: true,
			scroll: true,
			zIndex: 1000,
			update: guardarCambios
		});
		$("#portlet-column-c").sortable({
			connectWith: ["#portlet-column-a","#portlet-column-b"],
			tolerance: 'intersect',
			opacity: 0.5,
			handle: 'div.title',
			placeholder: 'sort_placeholder',
			revert: true,
			scroll: true,
			zIndex: 1000,
			update: guardarCambios
		});
	
		portletActions();
		$('li.portlet div.content div.edit').hide();
	}

	$("div.area-select").each(function(i) {
		$(this).removeClass("hidden_on_load");
		$(this).css("display", "block");
	});

	$("div.area-select-nojs").each(function(i) {
		$(this).css("display", "none");
	});
});