var lang=gup('lang');

switch (lang){
	case 'ES':
		var txt_cerrar='Cerrar';
		var txt_enviar='Enviar';
		break;
	case 'US':
		var txt_cerrar='Close';
		var txt_enviar='Send';
		break;
	case 'IT':
		var txt_cerrar='Chiudere';
		var txt_enviar='Enviare';	
		break;
}

var Info = function(){
    // define some private variables
    var dialog, showBtn;
   
    // return a public interface
    return {
        init : function(){
             showBtn = getEl('show-info-btn');
             // attach to click event
             showBtn.on('click', this.showDialog, this, true);
        },
        
        showDialog : function(){
            if(!dialog){ // lazy initialize the dialog and only create it once
                dialog = new YAHOO.ext.BasicDialog("info-dlg", { 
                        //modal:true,
                        autoTabs:true,
                        width:500,
                        height:300,
                        shadow:true,
                        minWidth:300,
                        minHeight:250,
                        proxyDrag: true
                });
				tmp=getEl('info-dlg');
				tmp.addClass('ydlg');
                dialog.addKeyListener(27, dialog.hide, dialog);
                dialog.addButton(txt_cerrar, dialog.hide, dialog);
            }
            dialog.show(showBtn.dom);
        }
    };
}();


var CV = function(){
    // define some private variables
    var dialog, showBtn;
   
    // return a public interface
    return {
        init : function(){
             showBtn = getEl('show-cv-btn');
             // attach to click event
             showBtn.on('click', this.showDialog, this, true);
        },
        
        showDialog : function(){
            if(!dialog){ // lazy initialize the dialog and only create it once
                dialog = new YAHOO.ext.BasicDialog("curriculum_vitae-dlg", { 
                        //modal:true,
                        autoTabs:true,
                        width:500,
                        height:300,
                        shadow:true,
                        minWidth:300,
                        minHeight:250,
                        proxyDrag: true
                });
				tmp=getEl('curriculum_vitae-dlg');
				tmp.addClass('ydlg');
                dialog.addKeyListener(27, dialog.hide, dialog);
                dialog.addButton(txt_cerrar, dialog.hide, dialog);
            }
            dialog.show(showBtn.dom);
        }
    };
}();

var Code = function(){
      // define some private variables
    var dialog, showBtn;
   
    // return a public interface
    return {
        init : function(){
             showBtn = getEl('show-code-btn');
             // attach to click event
             showBtn.on('click', this.showDialog, this, true);
        },
        
        showDialog : function(){
            if(!dialog){ // lazy initialize the dialog and only create it once
                dialog = new YAHOO.ext.BasicDialog("code-dlg", { 
                        //modal:true,
                        autoTabs:true,
                        width:500,
                        height:300,
                        shadow:true,
                        minWidth:300,
                        minHeight:250,
                        proxyDrag: true
                });
				tmp=getEl('code-dlg');
				tmp.addClass('ydlg');
                dialog.addKeyListener(27, dialog.hide, dialog);
                dialog.addButton(txt_cerrar, dialog.hide, dialog);
            }
            dialog.show(showBtn.dom);
        }
    };
}();

var Mail = function(){
    // define some private variables
    var dialog, showBtn;
   
    // return a public interface
    return {
        init : function(){
             showBtn = getEl('show-mail-btn');
             // attach to click event
             showBtn.on('click', this.showDialog, this, true);
        },
        
        showDialog : function(){
            if(!dialog){ // lazy initialize the dialog and only create it once
                dialog = new YAHOO.ext.BasicDialog("contactar-dlg", { 
                        //modal:true,
                        autoTabs:true,
                        width:500,
                        height:300,
                        shadow:true,
                        minWidth:300,
                        minHeight:250,
                        proxyDrag: true
                });
				tmp=getEl('contactar-dlg');
				tmp.addClass('ydlg');
                dialog.addKeyListener(27, dialog.hide, dialog);
                dialog.addButton(txt_cerrar, dialog.hide, dialog);
                dialog.addButton(txt_enviar, this.saveForm, dialog);
            }
            dialog.show(showBtn.dom);
        },
		
		saveForm : function() {
			var formObject = document.getElementById('frmMail'); 
			YAHOO.util.Connect.setForm(formObject); 
			YAHOO.util.Connect.asyncRequest("POST","mail.php", {
			  timeout: 5000,
			  success: function(o) {
					alert(o.responseText);
			  },
			  failure: function(o) {}
			}); 
			dialog.hide();
			formObject.reset();
		}		
    };
}();


var Foto = function(){
      // define some private variables
    var dialog, showBtn;
   
    // return a public interface
    return {
        init : function(){
             showBtn = getEl('show-foto-btn');
             // attach to click event
             showBtn.on('click', this.showDialog, this, true);
        },
        
        showDialog : function(){
            if(!dialog){ // lazy initialize the dialog and only create it once
                dialog = new YAHOO.ext.BasicDialog("fotos-dlg", { 
                        //modal:true,
                        autoTabs:true,
                        width:685,
                        height:595,
                        shadow:true,
                        minWidth:685,
                        minHeight:595,
                        proxyDrag: true
                });
				tmp=getEl('fotos-dlg');
				tmp.addClass('ydlg');
                dialog.addKeyListener(27, dialog.hide, dialog);
                dialog.addButton('Cerrar', dialog.hide, dialog);
            }
            dialog.show(showBtn.dom);
        }
    };
}();

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "ES";
  else
    return results[1];
}

// using onDocumentReady instead of window.onload initializes the application
// when the DOM is ready, without waiting for images and other resources to load

YAHOO.ext.EventManager.onDocumentReady(Info.init, Info, true);
YAHOO.ext.EventManager.onDocumentReady(CV.init, CV, true);
YAHOO.ext.EventManager.onDocumentReady(Code.init, Code, true);
YAHOO.ext.EventManager.onDocumentReady(Mail.init, Mail, true);
YAHOO.ext.EventManager.onDocumentReady(Foto.init, Foto, true);