/* Archvo de javascript para controlar las funciones de animacion
 * Author: Analee Glez
 * Property of: Lai-Sing 2010
 * Site: Lai-Sing.com
 */

$j = jQuery.noConflict();
$j(document).ready(function(){
    var getPage = location.href;
    var lookPage = getPage.indexOf('interior');
    var getPage = location.href;
    var lookPage = getPage.indexOf('?sec=');
    if(lookPage != -1){
        //Genera los valores iniciales de los tabs
        $j("#tab-links").css({width:'16px'});
        $j(".wrapper-sec-cont").css({width:'0', display:'none'});
        $j(".film-tab").css({margin:'0'});
        $j("#wrapper-main-content").css({width:'630px',margin:'0 auto'});
        var getSec = location.href;
        var varInit = getSec.indexOf("?")+5;
        var sec = getSec.substring(varInit);
        //Corre la funcion inicial
        window.setTimeout("enterSecs('"+sec+"')", '1500');
    }
    //Asigna los efectos al small menu
    $j('.menu-item').bind('mouseover',mainMenuOpen);
    $j('.menu-item').bind('mouseout',mainMenuClose);
    //Asigna las funciones al menu de la secciones
    $j(".film-tab").bind('click', tabEffect);
    $j(".film-tab").bind('mouseover', filmOver);
    $j(".film-tab").bind('mouseout', filmOut);

});

function mainMenuOpen(){
    var menuId = $j(this).attr('id');
    $j('#'+menuId).animate({top:"-10px"}, "slow");
}
function mainMenuClose(){
    var menuId = $j(this).attr('id');
    $j('#'+menuId).animate({top:"-146px"}, "slow");
}

function enterSecs(sec){
	var options = {};
	var tabId = "tab-"+sec;
	var contId = "cont-"+sec;
    //Elimina el margen de la estructura para pegar los tabas a la izquierda y abre el ancho
	$j("#wrapper-main-content").animate({"margin-left":"0", "width":"705px"}, 900);
    //Cierra todos los tabs
    $j(".film-images").animate({"width":"0px"}, 850);
	$j(".film-tab").animate({"width":"16px","margin-left":"3px"}, 850);
    //Abre el negativo seleccionado
    $j("#"+tabId).animate({'width':'151px'}, 750);
    $j("#"+tabId+"-img").animate({"width":"135px"}, 800, function(){
		$j("#"+contId).animate({"width":"456px"}, 1000);
        $j("#"+contId+" .sec-cont").show('slide',options,1150);
		//$(".film-tab").addClass('clearTab');
    });
	if(navigator.appName.indexOf("Microsoft") == -1){
		if(sec == 'autora'){
			var secNom = 'Sobre la autora';	
		} else {
			var secCapital = sec.substring(0,1);
			var secLeft = sec.substring(1);
			var capitalize = secCapital.toUpperCase();
			var secNom = capitalize+secLeft;
		}
		$j("title").text('Lai-Sing | '+sec);
	} 
}

function tabEffect(){
    var options = {};
    //Obtiene el id del tab y del contenido de la seccion abierta
    var currentCont = $j(".wrapper-sec-cont:visible").attr("id");
    var currentSec = currentCont.substring(5);
    var currentTab = "tab-"+currentSec;
    //Obtiene los valores del elemento seleccionado
    var tabId = $j(this).attr('id');
    var sec = tabId.substring(4);
    var contId = "cont-"+sec;
    //Cierra los elementos de la seccion actual
    $j("#"+currentCont+" .sec-cont").hide('slide',options,900);
    //$j("#"+currentCont).animate({"width":"0", "padding":"0"}, 900, function(){
	$j("#"+currentCont).animate({"width":"0", "padding-left":"0px", "padding-top":"0px"}, 900, function(){
        $j("#"+currentTab+"-img").delay(200).animate({'width':'0'}, 850);
        $j("#"+currentTab).delay(200).animate({'width':'16px'}, 850, function(){
            //Abre el negativo seleccionado
            $j("#"+tabId).animate({'width':'151px'}, 750);
            $j("#"+tabId+"-img").animate({"width":"135px"}, 800, function(){
                //Cambia el título del documento
				if(navigator.appName.indexOf("Microsoft") == -1){
					if(sec == 'autora'){
						var secNom = 'Sobre la autora';	
					} else {
						var secCapital = sec.substring(0,1);
						var secLeft = sec.substring(1);
						var capitalize = secCapital.toUpperCase();
						var secNom = capitalize+secLeft;
					}
					$j("title").html('Lai-Sing | '+secNom);
				}
                $j("#"+contId).animate({"width":"456px", "padding-left":"10px", "padding-top":"10px"}, 1000);
                $j("#"+contId+" .sec-cont").show('slide',options,1150);
            });
        });
    }).fadeOut(30);
}

function filmOver(){
    //Revisa si se esta llenado a cabo la animacion
    if($j(".wrapper-sec-cont:visible").length != 0){
        //Obtiene el id del tab y del contenido de la seccion abierta
        var currentCont = $j(".wrapper-sec-cont:visible").attr("id");
        var currentSec = currentCont.substring(5);
        var currentTab = "tab-"+currentSec;
        //Obtiene los valores del elemento seleccionado
        var tabId = $j(this).attr('id');
        $j("#"+tabId+"[id!='"+currentTab+"']").animate({top:"-56px"},600);
    }
}

function filmOut(){
    var tabId = $j(this).attr('id');
    $j("#"+tabId).animate({top:"0"},600);
}



