/*************************
  Carlos Charles
  ************************
  Copyright (c) 2005-2011 Carlos Charles
  v 2.0 originally written by CARLOS CHARLES
  ********************************************
  http://www.carloscharles.com/
**********************************************/

// Scroller
function goToByScroll(id) {
    $('html,body').animate({scrollTop: $("#"+id).offset().top},2500);
}

// Load site content
function page(id) {
    $('#site_content').html('<table class="loading-00"><tr><td><p>Cargando...</p><p><img class="img-00" src="images/loading.gif" /></p></td></tr></table>');
    $('#site_content').load("site_content.php?do="+id);
}

function date(id) {
    var month = $("#month").val();
    var year = $("#year").val();
    $('#site_content').html('<table class="loading-00"><tr><td><p>Cargando...</p><p><img class="img-00" src="images/loading.gif" /></p></td></tr></table>');
    $('#site_content').load("site_content.php?do="+id+'&month='+month+'&year='+year);
}

function newsletter(id) {
    var email = $("#email").val();
    $('#site_content').html('<table class="loading-00"><tr><td><p>Cargando...</p><p><img class="img-00" src="images/loading.gif" /></p></td></tr></table>');
    $('#site_content').load("site_content.php?do="+id+'&submit=1&e='+email);
}

function video(id) {
    $('#video_player').html('<table class="loading-01"><tr><td><p>Cargando...</p><p><img class="img-00" src="images/loading.gif" /></p></td></tr></table>');
    $('#video_player').load("video_player.php?"+id);
}

function carrousel_one(id) {
    $('#carrousel_one').html('<table class="loading-02"><tr><td><p>Cargando...</p><p><img class="img-00" src="images/loading.gif" /></p></td></tr></table>');
    $('#carrousel_one').load("video_carrousel_one.php?"+id);
}

function carrousel_two(id) {
    $('#carrousel_two').html('<table class="loading-02"><tr><td><p>Cargando...</p><p><img class="img-00" src="images/loading.gif" /></p></td></tr></table>');
    $('#carrousel_two').load("video_carrousel_two.php?"+id);
}

function fan_zone(id) {
    var nme = $("#name").val();
    var eml = $("#email").val();
    var ttl = $("#title").val();
    var ctg = $("#category").val();
    var url = $("#link").val();
    var msg = $("#message").val();
    // Passing special characters
    var nme = escape(nme);
    var eml = escape(eml);
    var ttl = escape(ttl);
    var ctg = escape(ctg);
    var url = escape(url);
    var msg = escape(msg);
    $('#site_content').html('<table class="loading-00"><tr><td><p>Cargando...</p><p><img class="img-00" src="images/loading.gif" /></p></td></tr></table>');
    $('#site_content').load("site_content.php?do="+id+'&submit=1&nme='+nme+'&eml='+eml+'&ttl='+ttl+'&ctg='+ctg+'&url='+url+'&msg='+msg);
}

function contact(id) {
    var nme = $("#name").val();
    var eml = $("#email").val();
    var cnt = $("#country").val();
    var cty = $("#city").val();
    var msg = $("#message").val();
    // Passing special characters
    var nme = escape(nme);
    var cnt = escape(cnt);
    var cty = escape(cty);
    var msg = escape(msg);
    $('#site_content').html('<table class="loading-00"><tr><td><p>Cargando...</p><p><img class="img-00" src="images/loading.gif" /></p></td></tr></table>');
    $('#site_content').load("site_content.php?do="+id+'&submit=1&nme='+nme+'&eml='+eml+'&cnt='+cnt+'&cty='+cty+'&msg='+msg);
}

// Pop-Up Window
function popitup(url) {
	newwindow=window.open(url,'name','scrollbars=yes,height=600,width=600');
	if (window.focus) {newwindow.focus()}
	return false;
}

/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/
// Speed of the automatic slideshow
var slideshowSpeed = 12000;

// Variable to store the images we need to set as background
// which also includes some text and url's.
var photos = [ {
		"title" : "Album: Luis Miguel",
		"image" : "images/main_display-00.jpg",
		"url" : "",
		"firstline" : "",
		"secondline" : ""
	}, {
		"title" : "Album: Luis Miguel",
		"image" : "images/main_display-01.jpg",
		"url" : "",
		"firstline" : "",
		"secondline" : ""
	}, {
		"title" : "Album: Luis Miguel",
		"image" : "images/main_display-02.jpg",
		"url" : "",
		"firstline" : "",
		"secondline" : ""
	}, {
		"title" : "Album: Luis Miguel",
		"image" : "images/main_display-03.jpg",
		"url" : "",
		"firstline" : "",
		"secondline" : ""
	}
];

$(document).ready(function() {
    // Backwards navigation
	$("#back").click(function() {
		stopAnimation();
		navigate("back");
	});
	// Forward navigation
	$("#next").click(function() {
		stopAnimation();
		navigate("next");
	});
	var interval;
	$("#control").toggle(function(){
		stopAnimation();
	}, function() {
		// Change the background image to "pause"
		$(this).css({ "background-image" : "url(images/btn_pause.png)" });
		// Show the next image
		navigate("next");
		// Start playing the animation
		interval = setInterval(function() {
			navigate("next");
		}, slideshowSpeed);
	});
	var activeContainer = 1;	
	var currentImg = 0;
	var animating = false;
	var navigate = function(direction) {
		// Check if no animation is running. If it is, prevent the action
		if(animating) {
			return;
		}
		// Check which current image we need to show
		if(direction == "next") {
			currentImg++;
			if(currentImg == photos.length + 1) {
				currentImg = 1;
			}
		} else {
			currentImg--;
			if(currentImg == 0) {
				currentImg = photos.length;
			}
		}
		// Check which container we need to use
		var currentContainer = activeContainer;
		if(activeContainer == 1) {
			activeContainer = 2;
		} else {
			activeContainer = 1;
		}
		showImage(photos[currentImg - 1], currentContainer, activeContainer);
	};
	var currentZindex = -1;
	var showImage = function(photoObject, currentContainer, activeContainer) {
		animating = true;
		// Make sure the new container is always on the background
		currentZindex--;
		// Set the background image of the new active container
		$("#headerimg" + activeContainer).css({
			"background-image" : "url(" + photoObject.image + ")",
			"display" : "block",
			"z-index" : currentZindex
		});
		// Hide the header text
		$("#headertxt").css({"display" : "none"});
		// Set the new header text
		$("#firstline").html(photoObject.firstline);
		$("#secondline")
			.attr("href", photoObject.url)
			.html(photoObject.secondline);
		$("#pictureduri")
			.attr("href", photoObject.url)
			.html(photoObject.title);
		// Fade out the current container
		// and display the header text when animation is complete
		$("#headerimg" + currentContainer).fadeOut(function() {
			setTimeout(function() {
				$("#headertxt").css({"display" : "block"});
				animating = false;
			}, 500);
		});
	};
	var stopAnimation = function() {
		// Change the background image to "play"
		$("#control").css({ "background-image" : "url(images/btn_play.png)" });
		// Clear the interval
		clearInterval(interval);
	};
	// We should statically set the first image
	navigate("next");
	// Start playing the animation
	interval = setInterval(function() {
		navigate("next");
	}, slideshowSpeed);
});

