$(document).ready(function () {
	
	$('#page').mouseenter(function (){
		$('body').css("overflow", "auto");
	});


    var date = new Date();
    date.setTime(date.getTime() + (15 * 60 * 1000));
    $('#enter').click(function () {
        $.cookie('intro', 'collapsed', {
            expires: date
        })
    });
    var intro = $.cookie('intro');
    if (intro == 'collapsed') {
        $('#intro').css("display", "none");
        $('#intro2').css("display", "none");
        $('#intro3').css("display", "none");
        $('.soundcloud').css('visibility', 'visible')
    };
    if (intro != 'collapsed') {
        $('body').css('overflow', 'hidden');
        $('.soundcloud').css('visibility', 'hidden')
    };
    jQuery.each(jQuery.browser, function (i) {
        if ($.browser.msie) {
            $('#video-js').empty()
        } else {}
    });
    $(document).pngFix();
    if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
        $(".view .item-list .pager").css("position", "static");
        $(window).load(function () {
            if (intro != 'collapsed') {
                $("#page-wrapper").hide()
            }
        })
    };
    $('#enter').click(function () {
        $("#page-wrapper").show();
        var speed = 500,
            $wall = $('.wrap');
        $wall.masonry({
            columnWidth: 100,
            itemSelector: '.box:not(.invis)',
            animate: true,
            animationOptions: {
                duration: speed,
                queue: false
            }
        });
        $('#intro').slideUp(400, function () {
            $('#intro2').slideUp(1000);
            $('#intro3').slideUp(1400, function () {
                $('body').css('overflow', 'visible');
                $('#intro').empty();
                $('.soundcloud').css('visibility', 'visible')
            })
        })
    });
//BANNERONI



//PRIMO
	
	  $('ul#banner_a').parallax({
      'elements': [
        {
          'selector': 'li#a1',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 25,
                'multiplier': 0.04
              }
            }
          }
        },
		{
          'selector': 'li#a2',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.01
              }
            }
          }
        },
		{
          'selector': 'li#a3',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.0
              }
            }
          }
        }
      ]
    });
    
//SECONDO
    
    $('ul#banner_b').parallax({
      'elements': [
        {
          'selector': 'li#b1',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.05
              }
            },
			'y': {
              'background-position-y': {
                'initial': 0,
                'multiplier': 0.01
			  }
			}
          }
        },
		{
          'selector': 'li#b2',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.00
              }
            }
          }
        }
      ]
    });
    
//ORABOX

    $('ul#banner_c').parallax({
      'elements': [
				   {
          'selector': 'li#c0',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.02,
                'invert': true
              }
            }
          }
        },
        {
          'selector': 'li#c1',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.02
              }
            }
          }
        },
		{
          'selector': 'li#c2',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.00
              }
            }
          }
        }
      ]
    });
	
	
//QUARTO
	
	 $('ul#banner_d').parallax({
      'elements': [
        {
          'selector': 'li#d1',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.00
              }
            }
          }
        }
      ]
    });
    


 //SASSI
	
	 $('ul#banner_f').parallax({
      'elements': [
        {
          'selector': 'li#f1',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.0
				
              }
            }
			
          }
        },
		{
          'selector': 'li#f2',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.02,
                'invert': true
				
              }
            }
          }
        },
		{
          'selector': 'li#f3',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.0
				
				
              }
            }
          }
        }
      ]
    });
	
//ORA
	
	  $('ul#banner_g').parallax({
      'elements': [
		{
          'selector': 'li#g1',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.0
              }
            }
          }
        },
        {
          'selector': 'li#g2',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.01,
                'invert': true
              }
            },
			'y': {
              'background-position-y': {
                'initial': 25,
                'multiplier': 0.01
			  }
			}
          }
        },
		{
          'selector': 'li#g3',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.01
              }
            }
          }
        },
        {
          'selector': 'li#g4',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.02
              }
            }
          }
        },
        {
          'selector': 'li#g5',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.03
              }
            }
          }
        },
        {
          'selector': 'li#g6',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.0
              }
            }
          }
        }
      ]
    });	
    
//TEO
	
	 $('ul#banner_h').parallax({
      'elements': [
      {
          'selector': 'li#h1',
          'properties': {
            'x': {
              'background-position-x': {
                'initial': 0,
                'multiplier': 0.0
              }
            }
          }
        }
      ]
    });

    
    // MENU TAGS
   
   $('#block-menu-primary-links').find('.first').addClass('news');
	$('.tags-container').addClass('news');
	
  	var 
  		$news = $('.news')
  	;
	 	
	$('.tags-container').animate({height:0},{queue:false, duration:0, easing: 'linear'});
	$('.tag').animate({opacity:0},{queue:false, duration:0, easing: 'linear'});
	
    $news.mouseover(function(){
        $('.tags-container').animate({height:'50px'},{queue:false, duration:400, easing: 'easeOutExpo'});
        $('.tag').animate({opacity:1},{queue:false, duration:100, easing: 'easeOutExpo'});
    });   
    	
    $news.mouseleave(function(){
    	$('.tag').animate({opacity:0},{queue:false, duration:100, easing: 'easeInBack'});
        $('.tags-container').animate({height:0},{queue:false, duration:400, easing: 'easeInBack'}); 
    }); 
    
    
    $('.tags-container').mouseenter(function(){
        $('#block-menu-primary-links').find('.first a').animate({backgroundPosition: "(0 -250px)"}, {queue:false, duration:250});
    });   
    	
    $('.tags-container').mouseleave(function(){
        $('#block-menu-primary-links').find('.first a').animate({backgroundPosition: "(0 0)"}, {queue:false, duration:250});
    }); 
    
    $news.mouseover(function(){
    	$('#block-menu-primary-links').find('.first a').css("color","black");
    });
    
    $news.mouseout(function(){
    	$('#block-menu-primary-links').find('.first a').css("color","#E8E8E8");
    });
    
   
         
// MASONRY   

    
    var speed = 500,
        $wall = $('.wrap');
    $wall.masonry({
        columnWidth: 100,
        itemSelector: '.box:not(.invis)',
        animate: true,
        animationOptions: {
            duration: speed,
            easing: 'linear',
    		queue: false
        }
    });
    $('.filtering-nav a').click(function () {
        var colorClass = '.' + $(this).attr('class');
        if (colorClass == '.all') {
            $wall.children('.invis').toggleClass('invis').fadeIn(speed)
        } else {
            $wall.children().not(colorClass).not('.invis').toggleClass('invis').fadeOut(speed);
            $wall.children(colorClass + '.invis').toggleClass('invis').fadeIn(speed)
        }
        $wall.masonry();
        return false
    });
    
    
    $(function () {
        $('#block-menu-primary-links a').css({
            backgroundPosition: "0 0"
        }).mouseover(function () {
            $(this).stop().animate({
                backgroundPosition: "(0 -250px)"
            }, {
                duration: 250
            })
        }).mouseout(function () {
            $(this).stop().animate({
                backgroundPosition: "(0 0)"
            }, {
                duration: 250
            })
        })
    });
    
    
    
    $(function () {
        $(".redazione img").aeImageResize({
            height: 300,
            width: 280
        })
    });
    $(function () {
        $(".links img").aeImageResize({
            height: 300,
            width: 180
        })
    });
    $('#plug-and-play').cycle({
        fx: 'scrollLeft',
        timeout: 5000,
        speed: 400,
        pause: true,
        next: '#banner-next'
    });
    $('#banneroni').mouseenter(function () {
        $("#banner-next").fadeIn()
    });
    $('#banneroni').mouseleave(function () {
        $("#banner-next").fadeOut()
    });
    $('.immagini').cycle({
        fx: 'scrollLeft',
        timeout: 3000,
        speed: 200,
        pause: true
    });
    $('.next').click(function () {
        $('.slideoff').cycle('next')
    });
    $('.photonav').hide();
    $('#banner-next').hide();
    $('.prev').hide();
    $('.postslider').mouseenter(function () {
        $(this).find("div.immagini").addClass('slideoff');
        var nimg = $(".slideoff img");
        if (nimg.length > 1) {
            $(this).find(".photonav").fadeIn()
        }
    });
    $('.postslider').mouseleave(function () {
        $(this).find("div.immagini").removeClass('slideoff');
        $(this).find(".photonav").fadeOut()
    });
    jQuery.each(jQuery.browser, function (i) {
        if ($.browser.msie) {} else {
            $('img.imagecache-banner').css({
                opacity: 0.60
            });
            $('img.imagecache-banner').mouseenter(function () {
                $(this).animate({
                    opacity: 1
                })
            });
            $('img.imagecache-banner').mouseleave(function () {
                $(this).animate({
                    opacity: 0.60
                })
            })
        }
    });
    $('a.info-album').hide();
    $('div.album-cover').mouseenter(function () {
        $(this).find("a.info-album").fadeIn(200)
    });
    $('div.album-cover').mouseleave(function () {
        $(this).find("a.info-album").fadeOut(400)
    })
});
$(window).load(function () {
    var speed = 500,
        $wall = $('.wrap');
    $wall.masonry({
        columnWidth: 100,
        itemSelector: '.box:not(.invis)',
        animate: true,
        animationOptions: {
            duration: speed,
            queue: false
        }
    });
    $('#loading').hide();
    opaqalize()
});

function opaqalize() {
    $('embed').each(function () {
        if (!$(this).attr('wmode')) {
            $(this).attr({
                'wmode': 'opaque'
            })
        }
    });
    $('object').each(function () {
        var e = document.createElement('param');
        e.setAttribute('name', 'wmode');
        e.setAttribute('value', 'opaque');
        $(this).append(e)
    })
}
$(document).bind('cbox_open', function () {
    $('.soundcloud').css('visibility', 'hidden')
});
$(document).bind('cbox_closed', function () {
    $('.soundcloud').css('visibility', 'visible')
});
