
function _showPresentation(){
    $("#presentation").fadeIn(1200);
    setTimeout("$(\"#presentation\").fadeOut(1000);", 2400);
    setTimeout("$(\"#mainpage\").fadeIn(1000);", 3900);
}

function _whipeRight() {
    $(".slideshow").cycle("prev");
}

function _whipeLeft() {
    $(".slideshow").cycle("next");
}

function _setSlideshowSize(){
    var images = getImages()
    var ratio_title = 1200 / 140;
    
    var ratio_mail = 444 / 27;
    
    var ratio_images = getPerfectWidth() / getPerfectHeight();
    var slideshow = document.getElementById("slideshow")
    var presentation = document.getElementById("presentation");
    var mainpage = document.getElementById("mainpage");
    var goback = document.getElementById("goback");
    var gonext = document.getElementById("gonext");
    
    var imgmail = document.createElement("img");
    var hrefimg = document.createElement("a");
//    var imgmail = document.getElementById("imgmail");
//    var hrefimg = document.getElementById("contactlink");

    $(goback).width(  "1px");
    $(goback).height( "1px");
    goback.style.top  = "0px";
    goback.style.left = "0px";

//     <a href="mailto:contact@battellini.com"><img src="images/battelinicontact.jpg" id="img_mail"/></a>
    
    imgmail.src = "images/battelinicontact.jpg";
    hrefimg.href = "mailto:contact@battellini.com";
//    document.getElementById("dummy_container").removeChild(hrefimg);
    document.getElementById("mailto").appendChild(hrefimg);
    hrefimg.appendChild(imgmail)
    $("#presentation img").height($(window).height() * 0.18 + "px");
    $("#presentation img").width($(window).height() * 0.18 * ratio_title + "px");
    
    $(imgmail).height($(window).height() * 0.035 * 0.5 + "px");
    $(imgmail).width($(window).height() * 0.035  * 0.5 * ratio_mail + "px");
    
    if($(window).width() > $(window).height()){
        $(".slideshow").height($(window).height() * 0.9  + "px" ); 
        $(".slideshow").width($(window).height() * 0.9  *  ratio_images + "px" );
    }else{
      $(".slideshow").height($(window).width() * 0.9 * (1/ratio_images) + "px" ) ;
      $(".slideshow").width($(window).width() * 0.9 + "px" );
    }
    var presentation_padding_top = (($(window).height() - $(presentation).height()) / 2)
    presentation.style.padding = presentation_padding_top + "px 0px 0px 0px";
    mainpage.style.padding = (($(window).height() - $(mainpage).height()) / 2) + "px 0px 0px 0px";
    
    $(goback).width(  $(".slideshow").width() / 2);
    $(goback).height( $(".slideshow").height() ) ;
    goback.style.top  = (($(window).height() - $("#mainpage").height())/2) + "px";
    goback.style.left = (($(window).width() - $(".slideshow").width()) / 2) + "px";
    $(goback).click(_whipeRight);
    
    $(gonext).width(  $(".slideshow").width() / 2);
    $(gonext).height( $(".slideshow").height() ) ;
    gonext.style.top  = (($(window).height() - $("#mainpage").height())/2) + "px";
    gonext.style.left = ($(window).width() / 2) + "px";
    $(gonext).click(_whipeLeft);
    
    for(var i = 0; i < images.length ; i++){
        var img = document.getElementById(images[i].name);
        img.style.margin = (($(".slideshow").height() - $(img).height()) / 2) + "px 0px 0px " + (($(".slideshow").width() - $(img).width()) / 2) + "px";
    }
//     alert("fixeado!");
}

function _startSlideshow(){
    // Iniciamos el plugin de cycle
    $('.slideshow').cycle({
      fx: 'scrollHorz', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
      speed:600,
      easing:null,
      sync: 1,
      timeout:0,
      next:   '.slideshow img', 
    });
    
    // Iniciamos el touchwipe para touchscreens
/*    $(".slideshow").touchwipe({
        wipeLeft: _whipeLeft ,
        wipeRight: _whipeRight
    });
    $("#goback").touchwipe({
        wipeLeft: _whipeLeft ,
        wipeRight: _whipeRight
    });*/
    
    // Iniciamos el plugin para touchme 
    //$(".slideshow").touchme({
	// 		wipeLeft: function(event){_whipeLeft();} ,		// Esto funcionara?
	// 		wipeRight: function(event){_whipeRight();},		// Esto funcionara?
	//onGestureEnd: function(event){_setSlideShow();}
    //});
    
    // Arrancamos con la presentacion en 200ms
    setTimeout('_showPresentation();', 200);
}
function getGlobal(what){
  return function(){return what;};
}

function setGlobal(what){
  return function(val){
    what = val;
  }
}

$(document).ready(function() {
    $("#mainpage").hide();
    $("#presentation").hide();
    
    _startSlideshow();
    $(window).resize(function(){
//     alert(1);
//     _setSlideshowSize();
    }
    );
});

