$(window).load(function() {
                //Shadowbox.open({
                    //content:    'img/clients/hl/hl_big.jpg', 
                    //player:     "img",
                    //title:      "Henri Lloyd (Advertising)",
                    //height:     700,
                    //width:      476
                //});
                
                $.cookie("lingua","italiano");
                window.location.replace("#goup");
                
                
                Cufon.replace('h1', { fontFamily: 'DIN' });
                Cufon.replace('h2', { fontFamily: 'DIN' });
                Cufon.replace('h3', { fontFamily: 'DIN' });
                Cufon.replace('h4', { fontFamily: 'DIN Light' });
                Cufon.replace('article p', { fontFamily: 'DIN Light' });
                Cufon.replace('#navside ul li a', { fontFamily: 'DIN Light' });
                Cufon.replace('h3', { fontFamily: 'DIN' });
                Cufon.replace('#background p', { fontFamily: 'DIN Light' });
                Cufon.replace('#sb-title-inner', { fontFamily: 'DIN Light' });
                
                var currenth = $(window).height();
                $('#goup').css('height', currenth);
                var hall = 11300 + currenth;
                $('#content').css('height', hall);
                $('#navside ul li a').css('opacity', 0.8);
                $('.settore article ul li').css('opacity', 0.8);
                $('#navside ul li').click(function() {
                                 if($(this).attr('id') != 'italianomenu' && $(this).attr('id') != 'englishmenu') {
                                                  scrollGoUp($('a',this).attr("href"));
                                };
                });
                               
                $('#arrow').click(function() {
                                scrollGoUp('#sett_strategy');
                });
                
                                                                                
                $("#sett_clientslist").show();
                $("#sett_people").show();

                
                $('#italianomenu').click(function() {     
                                $(this).addClass('current');
                                $('#englishmenu').removeClass('current');
                                $('.english').hide();
                                $('.italiano').show();
                                $.cookie("lingua","italiano");
                                return false;
                });
                
                $('#englishmenu').click(function() {
                                $(this).addClass('current');
                                $('#italianomenu').removeClass('current');
                                $('.english').show();
                                $('.italiano').hide();
                                $.cookie("lingua","english");
                                return false;
                });
                
                $('.settore article ul li').hover(function(e) {
                                $(this).animate({'opacity': 1}, 500);
                                $(this).append('<b></b>');                                
                                $(this).find("b:last").animate({'bottom':'-15px'},500, function() {
                                            //   $(this).append('<span>'+ $(this).find("a.last").attr("title") +'</span>');
                                });
                                $(this).append('<span>'+ $("a", this).attr("title") +'</span>');
                                $this = $('a',this);
                                $.data(this, 'title', $this.attr('title'));
                                $this.removeAttr('title');
                                $(this).find("span:last").fadeIn('1000');
                                Cufon.replace('.settore article ul li span', { fontFamily: 'DIN Light' });
                                e.preventDefault();
                
                }, function(e) {
                                $(this).animate({'opacity': 0.8}, 500);
                                $(this).find("b:last").remove();
                                $(this).find("span:last").remove();
                                e.preventDefault();
                                $this.attr('title',$.data(this, 'title'));
                });
                
                $.Window = $(window);
                $.Scroll = ($.browser.mozilla || $.browser.msie) ? $('html') : $('body');
                $.Mobile = ($('body').hasClass('webkit-mobile') || (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))),
                $.Unsupported = $('body').hasClass('unsupported-browser');
                $('.settore').initsc(); 
});
 

function scrollGoUp(anc){  
                target = $(anc);
                $('html, body').animate({  
                scrollTop: target.offset().top  
                }, 1000, 'swing', function() {
              });
}
 
(function($) {
$.Events = {
                SECTION_ENTER: 'sectionEnter',
                SCROLL_TO: 'scrollTo',
                SCROLL: 'windowScroll',
                SCROLL_ENTER: 'windowScrollEnter',
                SCROLL_LEAVE: 'windwScrollLeave'
}  
})(jQuery);


(function($) {
$.fn.initsc = function(settings) {
var config = {};
if (settings) $.extend(config, settings);
                this.each(function() { 
                var $self = $(this),
                $settname = $self.attr('id');
                if ($self[$settname])
                $self[$settname]();     
                });   
}
})(jQuery); 

(function($) {
  $.fn.parallo = function(settings) {
     var config = { threshold: -100, offset_scroll: 6, offset_intertia: .15 };
     if (settings) $.extend(config, settings);
     this.each(function() { 
        var $self = $(this),
            $id = $self.attr('id');
        config.threshold = 0
        if ($.Mobile || $.Unsupported) {  
          $self.css({backgroundAttachment:'scroll'})
        }else{
        $.Window
          .bind('scroll',
            function(e){    
              if ( $.inview($self,{threshold:config.threshold}) ) {
                if (!$self.hasClass('_active')){
                $self.addClass('_active');
                if (settings.is_nav)
                    $('body').triggerHandler($.Events.SECTION_ENTER,$id);
                $self.triggerHandler($.Events.SCROLL_ENTER);
                }
                _scroll_background();
                $self.triggerHandler($.Events.SCROLL,$.distancefromfold($self,{threshold:config.threshold}) - config.threshold)
              }else{
                if ($self.hasClass('_active')){
                  $self.removeClass('_active');
                  $self.triggerHandler($.Events.SCROLL_LEAVE);
                }
              }
          })
        }   
        function _scroll_background() {
          var _x = '50% '
          var bpos = _x + (-($.distancefromfold($self,{threshold:config.threshold}) - config.threshold) * config.offset_intertia) + 'px';          
          $self.css({'backgroundPosition':bpos})
        }
    });
 return this;
} 
  
$.fn.sett_advertising = function() {
                this.each(function() { 
                                var $self = $(this),
                                $bg = $self.find('#ragazza'),
                                _threshold = -200;
                                $self
                                .parallo({threshold: _threshold,is_nav:true})
                                .bind($.Events.SCROLL,on_scroll)
                                .bind($.Events.SCROLL_ENTER,on_scroll_enter)
                                .bind($.Events.SCROLL_LEAVE,on_scroll_leave);
                                function on_scroll(e,distance) {
                                } 
                                function on_scroll_enter(e) {
                                                $("#advmenu").addClass('current');
                                }
                                function on_scroll_leave(e) {
                                                 $("#advmenu").removeClass('current');
                                }  
                });       
                return this;
};

$.fn.sett_strategy = function() {
                this.each(function() { 
                                var $self = $(this),
                                $bg = $self.find('#nave'),
                                _threshold = -200;
                                $self
                                .parallo({threshold: _threshold,is_nav:true})
                                .bind($.Events.SCROLL,on_scroll)
                                .bind($.Events.SCROLL_ENTER,on_scroll_enter)
                                .bind($.Events.SCROLL_LEAVE,on_scroll_leave);
                                
                                function on_scroll(e,distance) {
                                 var bpos = 1000 - (1400+$.Window.height()*2 - (distance)*3) + 'px 70%';
 
                                $bg.css({'backgroundPosition':bpos})
                                
                                } 
                                function on_scroll_enter(e) {
                                                $("#strategymenu").addClass('current');
                                }
                                function on_scroll_leave(e) {
                                              //  $("#nave").hide();
                                                // soundManager.stop('mySound3');
                                                $("#strategymenu").removeClass('current');
                                }  
                });       
                return this;
};

$.fn.sett_guerrilla = function() {
                this.each(function() { 
                                var $self = $(this),
                                $header = $self.find('header'),
                                $bg = $self.find('#mototop'),
                                _threshold = -200;
                                $self
                                .parallo({threshold: _threshold,is_nav:true})
                                .bind($.Events.SCROLL,on_scroll)
                                .bind($.Events.SCROLL_ENTER,on_scroll_enter)
                                .bind($.Events.SCROLL_LEAVE,on_scroll_leave);
                                
                                function on_scroll(e,distance) {
                                var bpos = '50% ' + ((distance/3)-470) + 'px';
                                $bg.css({'backgroundPosition':bpos})
                                } 
                                function on_scroll_enter(e) {
                                                $("#guerrillamenu").addClass('current');
                                }
                                function on_scroll_leave(e) {
                                                $("#guerrillamenu").removeClass('current');                                                
                                }  
                });       
                return this;
};

$.fn.sett_web = function() {
                this.each(function() { 
                                var $self = $(this),
                                $header = $self.find('header'),
                                $bg = $self.find('#logocorsica'),
                                _threshold = -200;
                                $self
                                .parallo({threshold: _threshold,is_nav:true})
                                .bind($.Events.SCROLL,on_scroll)
                                .bind($.Events.SCROLL_ENTER,on_scroll_enter)
                                .bind($.Events.SCROLL_LEAVE,on_scroll_leave);
                                
                                function on_scroll(e,distance) {
                                var bpos = '50% ' + (($.Window.height()/2.5-distance/3)) + 'px';
                                $bg.css({'backgroundPosition':bpos})
                                } 
                                function on_scroll_enter(e) {
                                                $("#webmenu").addClass('current');
                                }
                                function on_scroll_leave(e) {
                                                $("#webmenu").removeClass('current');
                                }  
                });       
                return this;
};

$.fn.sett_pop = function() {
                this.each(function() { 
                                var $self = $(this),
                                $header = $self.find('header'),
                                $bg = $self.find('#bicchiere'),
                                _threshold = -200;
                                $self
                                .parallo({threshold: _threshold,is_nav:true})
                                .bind($.Events.SCROLL,on_scroll)
                                .bind($.Events.SCROLL_ENTER,on_scroll_enter)
                                .bind($.Events.SCROLL_LEAVE,on_scroll_leave);    
                                function on_scroll(e,distance) {
                                                var bpos = '50% ' + (($.Window.height()/2.5-distance/3)+200) + 'px';
                                } 
                                function on_scroll_enter(e) {
                                                $("#popmenu").addClass('current');                                                
                                }
                                function on_scroll_leave(e) {
                                                $("#popmenu").removeClass('current');                                                
                                }  
                });       
                return this;
};

$.fn.sett_consulting = function() {
                this.each(function() { 
                                var $self = $(this),
                                $header = $self.find('header'),
                                $bg = $self.find('#bicchiere'),
                                _threshold = -200;
                                $self
                                .parallo({threshold: _threshold,is_nav:true})
                                .bind($.Events.SCROLL,on_scroll)
                                .bind($.Events.SCROLL_ENTER,on_scroll_enter)
                                .bind($.Events.SCROLL_LEAVE,on_scroll_leave);
                                function on_scroll(e,distance) {
                                                var bpos = '50% ' + (($.Window.height()/2.5-distance/3)+200) + 'px';
                                } 
                                function on_scroll_enter(e) {
                                                $("#consultingmenu").addClass('current');                                                
                                }
                                function on_scroll_leave(e) {
                                                $("#consultingmenu").removeClass('current');                                               
                                }  
                });       
                return this;
};
 
$.fn.sett_pr = function() {
                this.each(function() { 
                                var $self = $(this),
                                $header = $self.find('header'),
                                $bg = $self.find('#cathaybg'),
                                _threshold = -200;
                                $self
                                .parallo({threshold: _threshold,is_nav:true})
                                .bind($.Events.SCROLL,on_scroll)
                                .bind($.Events.SCROLL_ENTER,on_scroll_enter)
                                .bind($.Events.SCROLL_LEAVE,on_scroll_leave);
                                function on_scroll(e,distance) {
                                var bpos = '0px ' + (($.Window.height()/2.5-distance/3)) + 'px';
                                                $bg.css({'backgroundPosition':bpos})
                                } 
                                function on_scroll_enter(e) {
                                                $("#prmenu").addClass('current');                                                                                               
                                }
                                function on_scroll_leave(e) {
                                                $("#prmenu").removeClass('current');                                                                                                                                               
                                }  
                });       
                return this;
};

$.fn.sett_people = function() {
                this.each(function() { 
                                var $self = $(this),
                                $header = $self.find('header'),
                                _threshold = -200;
                                $self
                                .parallo({threshold: _threshold,is_nav:true})
                                .bind($.Events.SCROLL,on_scroll)
                                .bind($.Events.SCROLL_ENTER,on_scroll_enter)
                                .bind($.Events.SCROLL_LEAVE,on_scroll_leave);
                                function on_scroll(e,distance) {
                                                var bpos = '50% ' + ((480-distance/3)+200) + 'px';
                                } 
                                function on_scroll_enter(e) {
                                                $("#peoplemenu").addClass('current');                                                                                               
                                }
                                function on_scroll_leave(e) {
                                                $("#peoplemenu").removeClass('current');                                                                                                                                              
                                }  
                });       
                return this;
};

$.fn.sett_relations = function() {
                this.each(function() { 
                                var $self = $(this),
                                $header = $self.find('header'),
                                $h1 = $self.find('h1'),
                                $h2 = $self.find('h2'),
                                $id = $self.attr('id'),
                                $img = $self.find('img'),
                                _threshold = -200;
                                $self
                                .parallo({threshold: _threshold,is_nav:true})
                                .bind($.Events.SCROLL,on_scroll)
                                .bind($.Events.SCROLL_ENTER,on_scroll_enter)
                                .bind($.Events.SCROLL_LEAVE,on_scroll_leave);
                                function on_scroll(e,distance) {
                              
                                } 
                                function on_scroll_enter(e) {
                                                $("#relationsmenu").addClass('current');                                                                                                                                               
                                }
                                function on_scroll_leave(e) {
                                                $("#relationsmenu").removeClass('current');                                                                                                                                               
                                }  
                });       
                return this;
};
    
$.fn.sett_clientslist = function() {
                this.each(function() { 
                                var $self = $(this),
                                $header = $self.find('header'),
                                $loghiuno = $self.find('#loghiuno'),
                                $loghidue = $self.find('#loghidue'),
                                $loghitre = $self.find('#loghitre'),
                                $loghiquattro = $self.find('#loghiquattro'),
                                _threshold = -200;
                                $self
                                .parallo({threshold: _threshold,is_nav:true})
                                .bind($.Events.SCROLL,on_scroll)
                                .bind($.Events.SCROLL_ENTER,on_scroll_enter)
                                .bind($.Events.SCROLL_LEAVE,on_scroll_leave);
                                                                                              
                                                
                                function on_scroll(e,distance) {
                                                var unopos = '50% ' + (($.Window.height()/2.5-distance/3)+150) + 'px';
                                                $loghiuno.css({'backgroundPosition':unopos});
                                                
                                                var duepos = '50% ' + (250-($.Window.height()/2.5-distance/3)) + 'px';
                                                $loghidue.css({'backgroundPosition':duepos});
                                                
                                                var trepos = '50% ' + (($.Window.height()/2.5-distance/3)+150) + 'px';
                                                $loghitre.css({'backgroundPosition':trepos});
                                                
                                                var quattropos = '50% ' + (250-($.Window.height()/2.5-distance/3)) + 'px';
                                                $loghiquattro.css({'backgroundPosition':quattropos});
                                } 
                                function on_scroll_enter(e) {
                                                $("#clientsmenu").addClass('current');                                                                                                                                               
                                 }
                                function on_scroll_leave(e) {
                                                $("#clientsmenu").removeClass('current');                                                                                                                                                                                               
                                }  
                });       
                return this;
};

$.fn.goup = function() {
                this.each(function() { 
                                var $self = $(this),
                                $header = $self.find('header'),
                                $loghiuno = $self.find('#loghiuno'),
                                $loghidue = $self.find('#loghidue'),
                                $loghitre = $self.find('#loghitre'),
                                $loghiquattro = $self.find('#loghiquattro'),
                                _threshold = -200;
                                $self
                                .parallo({threshold: _threshold,is_nav:true})
                                .bind($.Events.SCROLL,on_scroll)
                                .bind($.Events.SCROLL_ENTER,on_scroll_enter)
                                .bind($.Events.SCROLL_LEAVE,on_scroll_leave);
                               
                                function on_scroll(e,distance) {
                                               
                                } 
                                function on_scroll_enter(e) {
                                                $("#startmenu").addClass('current');                                                                                                                                               
                                 }
                                function on_scroll_leave(e) {
                                                $("#startmenu").removeClass('current');                                                                                                                                                                                               
                                }  
                });       
                return this;
};


})(jQuery);


(function($) {
    $.distancefromfold = function($element, settings) {
        if (settings.container === undefined || settings.container === window) {
            var fold = $(window).height() + $(window).scrollTop();
        } else {
            var fold = $(settings.container).offset().top + $(settings.container).height();
        }
        return (fold + settings.threshold) - $element.offset().top ;
    };
    $.belowthefold = function($element, settings) {
        if (settings.container === undefined || settings.container === window) {
            var fold = $(window).height() + $(window).scrollTop();
        } else {
            var fold = $(settings.container).offset().top + $(settings.container).height();
        }
        return fold <= $element.offset().top - settings.threshold;
    };
    $.rightoffold = function($element, settings) {
        if (settings.container === undefined || settings.container === window) {
            var fold = $(window).width() + $(window).scrollLeft();
        } else {
            var fold = $(settings.container).offset().left + $(settings.container).width();
        }
        return fold <= $element.offset().left - settings.threshold;
    };
    $.abovethetop = function($element, settings) {
        if (settings.container === undefined || settings.container === window) {
            var fold = $(window).scrollTop();
        } else {
            var fold = $(settings.container).offset().top;
        }
        return fold >= $element.offset().top + settings.threshold  + $element.height();
    };
    $.leftofbegin = function($element, settings) {
        if (settings.container === undefined || settings.container === window) {
            var fold = $(window).scrollLeft();
        } else {
            var fold = $(settings.container).offset().left;
        }
        return fold >= $element.offset().left + settings.threshold + $element.width();
    };
    $.inview = function($element, settings) {
        return ($.abovethetop($element,settings)!=true && $.belowthefold($element,settings)!=true)
    };
    $.extend($.expr[':'], {
        "below-the-fold" : "$.belowthefold(a, {threshold : 0, container: window})",
        "above-the-fold" : "!$.belowthefold(a, {threshold : 0, container: window})",
        "right-of-fold"  : "$.rightoffold(a, {threshold : 0, container: window})",
        "left-of-fold"   : "!$.rightoffold(a, {threshold : 0, container: window})"
    });
    
})(jQuery);

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
