
var containerWidth = 800;
 
var log = function (msg){
    if(window.console && console.log){
        console.log(msg);
    }
};




function centerPos(){
    docWidth = $(window).width();
    docHeight = $(window).height();
    
            itemLeft = (docWidth / 2) - ($('#item2').width() / 2)+5;
    $('#item2').css('left', itemLeft);
    
    itemLeft = (docWidth / 2) - ($('#item1').width() / 2) - 30;
    $('#item1').css('left', itemLeft);
    

    
       $('.e1').css('left', itemLeft-55);
       $('.e2').css('left', itemLeft+605);
  
    itemLeft = (docWidth / 2) - ($('#contact').width() / 2);
    $('#contact').css('left', itemLeft);
    
    itemLeft = (docWidth / 2) - ($('.tip').width() / 2);
     itemTop = (docHeight / 2) - ($('.tip').height() / 2)+50;

    $('.tip').css({'left':itemLeft});
}

$(document).ready(function() {
    
    containerWidth = $('#stage').width();   
    
    centerPos();
    $(window).resize(function() {
        centerPos();
    });
    
    
    $('#contact').mouseover(function() {

        $(this).stop().animate({
            'top':0
        },900);
    }).mouseout(function(){
        //$(this).css('top',-225);
        // $(this).css({'top':-180});
        //$(this).animate({'top':-180},900);
        });
    
    $('.area').mouseenter(function() {
        $('.tip').fadeIn(900);
        //$('.tip').animate({'opacity':1},900);
    });
       $('.tip').mouseleave(function(){
          $('.tip').fadeOut(900);
          // $('.tip').animate({'opacity':0},900);
        });
    
    
    
    
    
    $('#stage').mouseover(function() {
        /// $(this).css({'top':0});
        log('over body');
        $('#contact').stop().animate({
            'top':-180
        },900);
    })

  
    $("#stage .cloud").each(function(index, value) {	
        //$(this).css('left', rand(0,500));
        runCloud($(this).attr('id'));
    });

    //$('#stage .item').plaxify()
    $('#stage .item').plaxify({
        "xRange":120,
        "yRange":120
    })
    $.plax.enable()



});



function runCloud(id) {
    if ( parseInt($("#" + id).css("left")) >= containerWidth) {
        $("#" + id).css("left", "-300px");
    } 
      
    cloudSpeed = parseInt($("#" + id).attr('speed'));
    log('speed ' +cloudSpeed);
    $("#" + id).animate({
        left:containerWidth
    }, cloudSpeed, "linear", function(){
        runCloud(id);
    });
//setTimeout("runCloud('" + id + "')", cloudSpeed+100);
} 
    
    
function rand (min, max) {

    var argc = arguments.length;
    if (argc === 0) {
        min = 0;
        max = 2147483647;
    } else if (argc === 1) {        
        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
