/** MENU **/
var Rollimage = new Array()

Rollimage['noticias_0']= new Image(121,153)
Rollimage['noticias_0'].src = template_path+"img/menu/noticiasoff.gif"
Rollimage['noticias_1'] = new Image(121,153)
Rollimage['noticias_1'].src = template_path+"img/menu/noticiason.gif"

Rollimage['descargas_0']= new Image(121,153)
Rollimage['descargas_0'].src = template_path+"img/menu/descargasoff.gif"
Rollimage['descargas_1'] = new Image(121,153)
Rollimage['descargas_1'].src = template_path+"img/menu/descargason.gif"

Rollimage['discografia_0']= new Image(121,153)
Rollimage['discografia_0'].src = template_path+"img/menu/discografiaoff.gif"
Rollimage['discografia_1'] = new Image(121,153)
Rollimage['discografia_1'].src = template_path+"img/menu/discografiaon.gif"

Rollimage['biografia_0']= new Image(121,153)
Rollimage['biografia_0'].src = template_path+"img/menu/biografiaoff.gif"
Rollimage['biografia_1'] = new Image(121,153)
Rollimage['biografia_1'].src = template_path+"img/menu/biografiaon.gif"

Rollimage['conciertos_0']= new Image(121,153)
Rollimage['conciertos_0'].src = template_path+"img/menu/conciertosoff.gif"
Rollimage['conciertos_1'] = new Image(121,153)
Rollimage['conciertos_1'].src = template_path+"img/menu/conciertoson.gif"

Rollimage['fotos_0']= new Image(121,153)
Rollimage['fotos_0'].src = template_path+"img/menu/fotosoff.gif"
Rollimage['fotos_1'] = new Image(121,153)
Rollimage['fotos_1'].src = template_path+"img/menu/fotoson.gif"

Rollimage['contacto_0']= new Image(121,153)
Rollimage['contacto_0'].src = template_path+"img/menu/contactosoff.gif"
Rollimage['contacto_1'] = new Image(121,153)
Rollimage['contacto_1'].src = template_path+"img/menu/contactoson.gif"

Rollimage['guestbook_0']= new Image(121,153)
Rollimage['guestbook_0'].src = template_path+"img/menu/guestbookoff.gif"
Rollimage['guestbook_1'] = new Image(121,153)
Rollimage['guestbook_1'].src = template_path+"img/menu/guestbookon.gif"

Rollimage['links_0']= new Image(121,153)
Rollimage['links_0'].src = template_path+"img/menu/linksoff.gif"
Rollimage['links_1'] = new Image(121,153)
Rollimage['links_1'].src = template_path+"img/menu/linkson.gif"

Rollimage['merchandising_0']= new Image(121,153)
Rollimage['merchandising_0'].src = template_path+"img/menu/merchandisingoff.gif"
Rollimage['merchandising_1'] = new Image(121,153)
Rollimage['merchandising_1'].src = template_path+"img/menu/merchandisingon.gif"

function SwapOut(nom){
  eval("document."+nom+".src = Rollimage['"+nom+"_1'].src;");
  return true;
}

function SwapBack(nom){
  eval("document."+nom+".src = Rollimage['"+nom+"_0'].src;");
  return true;
}
/** FI MENU **/

/** CREAR AJAX **/

function divLoading(divId) {
    var str = "<div class=\"loading\">Cargando ...<br/><img src='"+template_path+"img/ajax-loader.gif' alt=''></div>"
    $('#'+divId).html(str).fadeIn('slow');
}

function posicionarDIVpopupCentral(divId) {
    var d = document;
    var scrollTop = document.documentElement.scrollTop - 10;
    var XpositionDIV = (document.documentElement.clientWidth/2) - (document.getElementById('divContenedorPopupCentro').clientWidth/2);

    if (window.innerHeight || window.opera) {
        var YpositionDIV = window.innerHeight + window.scrollMaxY;
        //var YpositionDIV = window.innerHeight + window.outerHeight;
    } else if (document.body) {
        //var YpositionDIV = document.documentElement.clientHeight + document.getElementById('divContenedorPopupCentro').clientHeight + scrollTop;
        var YpositionDIV = document.body.offsetHeight;
    }

    document.getElementById('divContenedorPopupCentro').style.left = XpositionDIV+'px';
    document.getElementById('divContenedorPopupCentro').style.top =  scrollTop+'px';

    document.getElementById('divContenedorPopupCentro').style.visibility = "visible";
    document.getElementById('divPantallaNegra').style.top = '0px';
    document.getElementById('divPantallaNegra').style.visibility = "visible";
    document.getElementById('divPantallaNegra').style.width = document.documentElement.clientWidth+'px';
    document.getElementById('divPantallaNegra').style.height = YpositionDIV+'px';

    $('#reproductor').hide();

    return false;
}

function cerrar(divId) {
    if(document.getElementById(divId)) {
        if(document.getElementById('divContenedorPopupCentro').style.visibility == "visible") {
            if(document.getElementById('divPantallaNegra')) {
                document.getElementById('divPantallaNegra').style.visibility = "hidden";
                $('#reproductor').show();
            }
            document.getElementById('divContenedorPopupCentro').style.visibility = "hidden";
        }
        $('#'+divId).html('').fadeOut('slow');
    }
    return false;
}
function cerrar2(divId) {
    $('#divPantallaNegra').fadeOut('slow');
    $('#reproductor').show();
    $('#divContenedorPopupCentro').fadeOut('slow');
    $('#'+divId).html('').fadeOut('slow');
    return false;
}

function getPlainResponse(_values_send,divId) {
    $.ajax({
        type: "POST",
        url: WWW+"ajax.php",
        data: _values_send,
        beforeSend: function() {
            divLoading(divId);
            $(".loading").corner();
        },
        success: function(msg){
            var _retorno = unescape(msg);
            _retorno=_retorno.replace(/\+/gi," ");
            $('#'+divId).hide().html(_retorno).fadeIn('slow');

            scriptsAdicionals();
        }
    });
}
//SCRIPTS ADICIONALS
function scriptsAdicionals() {

    //lightbox
    var lightbox = new LightBox({
        loadingimg:template_path+'img/loading.gif',
        expandimg:template_path+'img/expand.gif',
        shrinkimg:template_path+'img/shrink.gif',
        effectimg:template_path+'img/zzoop.gif',
        effectpos:{x:-40,y:-20},
        effectclass:'effectable',
        closeimg:template_path+'img/close.gif'
    });
    //wforms
    wf.onLoadHandler();


    //Rounded Corners
    $(".generalbox_left_div").corner("round 8px").corner("round 10px");

    $(".caja").corner();

    $(".descargas_div").corner();
    $(".summary_div").corner();
    $(".list_conciertos").corner();
    $("#contacto").corner();
    $(".foro_message").corner();
    $(".guestbook_menu").corner();
    $(".biografia_content1").corner();
    $(".disco").corner();
    $(".merch").corner();

    //Formularis

    //Jcarousel
    setTimeout(myc,1500);
}


/** ENCUESTAS **/
function votarEncuesta(idPregunta) {
    var voto = false;
    idPregunta = parseInt(idPregunta);

    for (i=0;i<document.encuesta.voto.length;i++) {
        if (document.encuesta.voto[i].checked) {
            voto = parseInt(document.encuesta.voto[i].value);
            break;
        }
    }
    if(voto) {
        var _values_send = "idPregunta="+idPregunta+"&idRespuesta="+voto+"&option=encuesta"; //variables
        return getPlainResponse(_values_send,'encuesta');
    } else {
        alert('No ha seleccionado ninguna cancion');
    }
}

/** USUARIOS **/
function showUser(idUser,divId) {
    if(idUser) {
        idUser = parseInt(idUser);
    } else {
        idUser = "";
    }
    var _values_send = "idUser="+idUser+"&option=biografia"; //variables
    getPlainResponse(_values_send,divId);
}

/** MAILING LIST **/
function addContact() {
    var email = document.mailing.email.value;
    var antyBoot = document.mailing.antyBoot.value;
    var _values_send = "email="+email+"&option=mailing_list&antyBoot="+antyBoot; //variables
    return getPlainResponse(_values_send,'mailing_list');
}

/** GUESTBOOK **/
function addComment() {
    var _values_send = "option=form_comment"; //variables
    getPlainResponse(_values_send,'generalbox_right');
    return false;
}
function sendComment(evt) {
    // call the wForms default validation routine
    if(wf.formValidation(evt)) {
        var _values_send = "option=sendComment&name="+$('#id_name').val()+"&email="+$('#id_email').val()+"&web="+$('#id_web').val()+"&message="+$('#id_message').val()+"&submit=1"; //variables
        getPlainResponse(_values_send,'generalbox_right');
    }
    // will prevent the form from being submitted.
    return wf.utilities.XBrowserPreventEventDefault(evt);
}
/** CONTACT **/

function sendContact(evt) {
    // call the wForms default validation routine
    if(wf.formValidation(evt)) {
        var _values_send = "option=contact&seccion="+$('#id_seccion').val()+"&name="+$('#id_name').val()+"&email="+$('#id_email').val()+"&comments="+$('#id_comments').val()+"&send=1&check="+$('#id_check').val(); //variables
        getPlainResponse(_values_send,'generalbox_right');
    }
    // will prevent the form from being submitted.
    return wf.utilities.XBrowserPreventEventDefault(evt);
}

/** UTILS **/
function myc() {
    for(var i=0;i<10;i++) {
        if ( $('#jMyCarousel_'+i).length ) {
            $("#jMyCarousel_"+i).fadeIn().jMyCarousel({
                visible: '100%',
                eltByElt: false,
                circular: true
            });
        }
    }
    /*$(".jMyCarousel").jMyCarousel({
        visible: '100%'
    });*/
}
function loadContent(req,divId,pager) {
    var _values_send = "option=loadContent&req="+req; //variables
    if(typeof pager!='undefined')
        _values_send = _values_send + "&start="+pager;
    getPlainResponse(_values_send,divId);
    return false;
}