function slideSwitch() {
	if (typeof $current_slide == "undefined") {
		$current_slide = $("#slideshow a:first-child");
		$prev_slide = $("#slideshow a:last-child");
		$current_slide.html("<img src='" + $current_slide.attr("href") + "' />");
		if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
			$current_slide.children("img").css(($current_slide.height() > $current_slide.width() ? "height" : "width"), "100px");
		}
	} else {
		$prev_slide = $current_slide;
		$current_slide = $next_slide;
	}
	$next_slide = $current_slide.next().length ? $current_slide.next()
	        : $('#slideshow a:first-child');
	$prev_slide.animate({opacity: 0}, 1000, function() {
		$next_slide.html("<img src='" + $next_slide.attr("href") + "' />").css({display: "none", opacity: 0});
		if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
			$current_slide.children("img").css(($current_slide.height() > $current_slide.width() ? "height" : "width"), "100px");
		}
		$current_slide.css("display", "block").animate({opacity: 1}, 1000);
		$prev_slide.html("").css("display", "none");
	});
}

function blink(object) {
	object.animate({ opacity: 0 }, 500, function() {
		object.animate({ opacity: 1 }, 500);
	});
}

$(document).ready(function() { 
	
	$("#box").draggable({ handle: "#header" });

	$("#menu .btn").click(function() {
		if (!$(this).hasClass("active")) {
			$("#menu .btn.active").removeClass("active");
			$(this).addClass("active");
			//$("#center #text").hide().load($(this).attr("href"), {}, function() { $("#center #text").fadeIn("slow"); });
			//$("#center").hide().load($(this).attr("href"), {}, function() {
			//	$("#center").fadeIn("slow");
			//});
			//$("#center #content :not(#notification)").remove();
			//$.get("html/" + $(this).attr("id") + ".html" , function(data) {
			//	$("#center #content #text").html(data);
			//	if (!jQuery.browser.msie) {
			//		$("#center #content #text").hide();
			//		$("#center #content #text").fadeIn("slow");
			//	}
			var current = $("#center #content #text .section.current");
			var selected = $("#center #content #text #" + $(this).attr("id").replace("_btn", ""));
			if (!jQuery.browser.msie) {
				current.animate({opacity: 0}, 1000, function() {
					current.removeClass("current");
					selected.addClass("current").css("opacity", 0);
					selected.animate({opacity: 1}, 1000);
				});
			} else {
				current.removeClass("current");
				selected.addClass("current");
			}
		}
		$("#header .txt").html($(this).html());
	});
	
	//$("#box").tabs();

	$("#acercade_btn").trigger("click");
	$("#acercade").addClass("current");

	//$current_slide = $("#slideshow a:first-child");
	//$next_slide = $current_slide.next();
	//$("#header_txt").html($current_slide.attr("src") + "");
	//$current_slide.html("<img src='" + $current_slide.attr("href") + "' />");
	//$current_slide.children().attr("src", $current_slide.attr("href"));
	//$next_slide.css({opacity: 0, display: "none"}).html("<img src='" + $next_slide.attr("href") + "' />");
	//$next_slide.css({opacity: 0, display: "none"}).children().attr("src", next_slide.attr("href"));
	slideSwitch();
	setInterval("slideSwitch()", 5000);

	//var notification_blink = setInterval("$('#notification').effect('pulsate', { times: 1 }, 1200)", 1200);
	var notification_blink = setInterval("blink($('#notification'))", 1500);
	$("#notification").hover(
		function() {
			clearInterval(notification_blink);
		},
		function() {
			notification_blink = setInterval("blink($('#notification'))", 1500);
			//notification_blink = setInterval("$('#notification').effect('pulsate', { times: 1 }, 1200)", 1200);
		}
	);

	$("#notification").css({
		"-moz-border-radius": "10px",
		"-webkit-border-radius": "10px",
		"-o-border-radius": "10px",
		"border-radius": "10px"
	});
	
	Shadowbox.setup("a.slide", {
        	gallery: "Slideshow"
	});

	$("#arrow").click(function() {
		if ($("#icons").css("display") == "none") {
			$(this).animate({rotate: "+=180deg"});
			//$(this).css("rotate", "33deg");
		} else {
			$(this).animate({rotate: "-=180deg"});
			//$(this).css("rotate", "77deg");
		}
		$("#icons").toggle("slide", { direction: "up" });
	});

	/*if (jQuery.browser.msie) {
		$("#advertising").css("display", "inline");
	}*/


	var dialog = $("#proyectbox").dialog({ title: "Proyectos", height: 400, width: 600, show: "blind", hide: "blind", autoOpen: false });
	$(".trigger").click(function() {
		if (dialog.dialog("isOpen")) {
			dialog.dialog("close");
		}
		$("#proyectbox").load("html/proy/" + $(this).attr("id") + ".html").css("display", "none");
		dialog.dialog("open");
	});

});

