/**
 * Description of kickers
 * @date 21-lug-2011 11.26.12
 * @author eddie eddie.dumitrescu@gmail.com
 */

function kickers(){
    this.cookieName='footerStatus';
    this.footerContainer='.footer-content';
    this.minHeight='60px';
    this.maxHeight='220px';
    this.filterDelay=700;
    this.activeFilter=null;
}
kickers.prototype = {
    footerToggle: function(){
        var status=this.getFooterCookie();
        var height=(status==1 || status==null?this.minHeight:this.maxHeight);
        var cookie=(status==1 || status==null?0:1);
        var parent=this;
        
        $j(this.footerContainer).animate(
              {height: height},
              800,
              function(){
                    parent.setFooterCookie(cookie);
                }
            );
    },
    footerHide: function(){
//        console.log('footerHide');
        $j(this.footerContainer).css({height:this.minHeight});
    },
    setFooterCookie: function(value){
        $j.cookie(this.cookieName, value, {
            expires: 1
        });
    },
    getFooterCookie: function(){
        return ($j.cookie(this.cookieName));
    },
    getFilterClass: function(obj){
        var cssClass=$j(obj).attr('className');
        cssClass=cssClass.replace('filter ','');
        cssClass=cssClass.replace('over','');
        cssClass=$j.trim(cssClass);
        return cssClass;
    },
    filterOver: function(obj){
        if(this.activeFilter){
            this.hideFilter(this.activeFilter);
        }
        this.activeFilter=this.getFilterClass(obj);
        $j(obj).addClass('over');
        $j('dd.'+this.activeFilter).show();
    },
    filterOut: function(){
        var _this=this;
        this.timeoutName=setTimeout(function(){
            _this.hideFilter();
        },this.filterDelay);
    },
    hideFilter: function(){
        $j('dt.'+this.activeFilter).removeClass('over');
        $j('dd.'+this.activeFilter).hide();
        this.activeFilter=null;
        clearTimeout(this.timeoutName);
    },
    filterContentOver: function(){
        clearTimeout(this.timeoutName);
    },
    filterContentOut: function(){
        this.filterOut();
    }
}

function openFancy(link, width, height){
    $j.fancybox({
        'href'                  : link,
        'overlayOpacity'	: .7,
        'overlayColor'		: '#000000',
        'autoScale'     	: true,
        'width'			: width,
        'height'		: height,
        'transitionIn'		: 'fade',
        'transitionOut'		: 'fade',
        'type'			: 'iframe'
    });
}

function mondoShow(blockId){
    var divs = ['storia','ambiente','azienda'];
    console.log('show');
    for(var i=0;i<divs.length;i++){
        if(divs[i]!=blockId){
            $j('#'+divs[i]).hide()
        }else{
            $j('#'+divs[i]).show()
        }
    }
    $j('#menu-mondo li').each(function(){
        console.log(blockId);
        if($j(this).attr('id').indexOf(blockId)!=-1){
            $j(this).addClass('selected');
        }else{
            $j(this).removeClass('selected');
        }
    })
}
function drawDoubleColor(box,color1,color2){
  // get the canvas element using the DOM
  var canvas = document.getElementById(box);
  var width=30;

  // Make sure we don't execute when canvas isn't supported
  if (canvas.getContext){

    // use getContext to use the canvas for drawing
    var ctx = canvas.getContext('2d');

    // Filled triangle
    ctx.beginPath();
    ctx.moveTo(width,0);
    ctx.lineTo(0,width);
    ctx.lineTo(0,0);
    ctx.fillStyle = color1; 
    ctx.fill();
    
    // Stroked triangle
    ctx.beginPath();
    ctx.moveTo(width,0);
    ctx.lineTo(width,width);
    ctx.lineTo(0,width);
    ctx.fillStyle = color2; 
    ctx.fill();

  } else {
    document.write("<div class='color-tile' style='background-color:"+color1+"'></div>")
  }
}


var kick = new kickers();
$j(document).ready(function(){
//    try{
//        console.log('cookie:'+kick.getFooterCookie());
//    }catch(ex){}
   if(kick.getFooterCookie()==0){
      kick.footerHide(); 
   }
});
