// giZ on gizstyle.com jQuery implementation ´¯`·.¸¸.*

//ACTIONS

$(document).ready(function(){

$("#topbar").animate({height: '60px'}, 500)
			.animate({paddingTop: '5px'}, 50)
			.animate({paddingBottom: '5px'}, 50);

$(".w1").css('height','93px');
$(".w1open").toggle(function(){
			$(".w1").css('height','auto');
			$(this).css('background-position','bottom');
		}, function() {
			$(".w1").css('height','93px');
			$(this).css('background-position','top');
	});

$(".w2").css('height','93px');
$(".w2open").toggle(function(){
			$(".w2").css('height','auto');
			$(this).css('background-position','bottom');
		}, function() {
			$(".w2").css('height','93px');
			$(this).css('background-position','top');
	});	

$("div.interface").html("<a href=\"#apri\" class=\"clip-open\">apri la news...</a><a href=\"#chiudi\" class=\"clip-close\">chiudi la news...</a>");

$("div.entry-title .interface a.clip-close").hide();

$("div.entry-title .interface a.clip-open").click(function(){
		$("a.clip-close:visible").hide();
		$("a.clip-open:hidden").show();
		$(this).hide();
		$(this).parent().children("a.clip-close").show();
		$(".entry-content:visible").hide();
		$(this).parent().parent().next().show();
		return false;
	});
$("div.entry-title .interface a.clip-close").click(function(){
		$(this).hide();
		$(this).parent().children("a.clip-open").show();
		$(".entry-content:visible").hide();
	});

setInterval(function () {
   $("a.sponsor-badge img").toggle();
}, 3000);	
	
//SLIDER	
var $panels = $('#slider .scrollContainer > div');
var $container = $('#slider .scrollContainer');

var horizontal = true;

if (horizontal) {
  $panels.css({
    'float' : 'left',
    'position' : 'relative'
  });
  $container.css('width', $panels[0].offsetWidth * $panels.length);
}

var $scroll = $('#slider .scroll').css('overflow', 'hidden');

$scroll
  .before('<a href="#left" class="scrollButtons left">prev</a>')
  .after('<a href="#left" class="scrollButtons right">next</a>');

function selectNav() {
  $(this)
    .parents('ul:first')
      .find('a')
        .removeClass('selected')
      .end()
    .end()
    .addClass('selected');
}

$('#slider .navigation').find('a').click(selectNav);

function trigger(data) {
  var el = $('#slider .navigation').find('a[href$="' + data.id + '"]').get(0);
  selectNav.call(el);
}

if (window.location.hash) {
  trigger({ id : window.location.hash.substr(1) });
} else {
  $('ul.navigation a:first').click();
}

var offset = parseInt((horizontal ? 
  $container.css('paddingTop') : 
  $container.css('paddingLeft')) 
  || 0) * -1;


var scrollOptions = {
  target: $scroll,
  items: $panels,
  navigation: '.navigation a',
  prev: 'a.left', 
  next: 'a.right',
  axis: 'xy',
  onAfter: trigger,
  offset: offset,
  duration: 500,
  easing: 'swing'
};
$('#slider').serialScroll(scrollOptions);
$.localScroll(scrollOptions);
scrollOptions.duration = 1;
$.localScroll.hash(scrollOptions);

//AUTOSLIDER	
var cycleTimer = setInterval(function () {
   $scroll.trigger('next');
}, 3000);
// select some trigger elements to stop the auto-cycle
var $stopTriggers = $('#slider .navigation').find('a')
    .add('.scroll')
    .add("a[href^='#']");
// this is the function that will stop the auto-cycle
function stopCycle() {
   // remove the no longer needed stop triggers
   $stopTriggers.unbind('click.cycle');
   clearInterval(cycleTimer);
   $buttons.show();
}
// bind stop cycle function to the click event using namespaces
$stopTriggers.bind('click.cycle', stopCycle);

});