// Funcion Carga Ajax

$.ajaxSetup({'beforeSend' : function(xhr) {

if (xhr.overrideMimeType) {

//FF & Chrome

xhr.overrideMimeType('text/html; charset=UTF-8');

}

}

});

/* Funciones */


// Funcion Carga Ajax

$.ajaxSetup({'beforeSend' : function(xhr) {

if (xhr.overrideMimeType) {

//FF & Chrome
xhr.overrideMimeType('text/html; charset=UTF-8');
}

}

});

$(function(){
	animation = 'incomplete';
	QueryLoader.init();
	$.get("home.php", function(data) {
	    $('#content').html(data);
	});
	$('#music').load('music.php');
	
	$('#menu a').live('click', function(event) {
		event.preventDefault();
		$('.select').removeClass('select');
		$(this).addClass('select');
		var whatid = $(this).attr('href');
		if (whatid == '#home'){ transition01(); }
		else { transition02(); }
		var what = $(this).attr('rel');
		$.get(what, function(data) {
		    $('#content').html(data);
		    $('#content').fadeIn();
		});
	});
	$('#logoleft a').live('click', function(event) {
		event.preventDefault();
		var whatid = $(this).attr('href');
		if (whatid == '#home'){ transition01(); }
		else { transition02(); }
		var what = $(this).attr('rel');
		$.get(what, function(data) {
		    $('#content').html(data);
		    $('#content').fadeIn();
		});
	});
	$('.choseitem a').live('click', function(event) {
		event.preventDefault();
		var what = $(this).attr('rel');
		$.get(what, function(data) {
		    $('#content').html(data);
		    $('#content').fadeIn();
		});
	});
});
$(window).resize(function () {
	resizer();
});


function resizer(){
	var mainWidth = $(window).width();
	var mainHeight = $(window).height();
	$('#wrapper').centerh();
	$('#layer').centerh();
}

function chainAnim(e,s,o) {
		$('.colors2').hide();
		$('.colors').show();
        var $fade = $(e);
        var code = function() {console.log('Done.');};
        $fade.each(function( i ){
        	$('.anim').hide();
            $(this).delay(i * s).fadeIn(200);
        });
        animation = 'complete';
}
function chainAnim2(e,s,o) {
		$('.anim2').hide();
		$('.colors2').show();
        var $fade = $(e);
        var code = function() {console.log('Done.');};
        $fade.each(function( i ){
            $(this).delay(i * s).fadeIn(200);
        });
        animation = 'complete';
}

function transition02(){
	 $('#mask').fadeIn('fast');
	 if (animation == 'incomplete'){ chainAnim('.anim',100,'1'); }
     else if (animation == 'complete'){ chainAnim2('.anim2',100,'1'); }
}
function transition01(){
     $('.anim, .anim2').fadeOut();
     animation = 'incomplete';
     
}
jQuery.fn.centercont = function () {
    this.css("position","absolute");
    this.css("top", ( $('#content').height() - this.outerHeight() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $('#content').width() - this.outerWidth() ) / 2+$(window).scrollLeft() + "px");
    return this;
}
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.outerHeight() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.outerWidth() ) / 2+$(window).scrollLeft() + "px");
    return this;
}
jQuery.fn.centerh = function () {
    this.css("top", ( $(window).height() - this.outerHeight() ) / 2+$(window).scrollTop() + "px");
    return this;
}
