// JavaScript Document

var carousel;
var carouselchildren;
var carouselcurrent = 1;
var carouselcount = 1;

$(document).ready(function() {	
	
	$("#button-collection").mouseover(
	
		function () {
			$('#navigation-bar-collection').show();
			$('#navigation-bar-press').hide(); 
			//$('#navigation-bar-collection').fadeIn();
			//$('#navigation-bar-press').fadeOut(); 
		}
	);
	
	$("#button-press").mouseover(
	
		function () {
			$('#navigation-bar-press').show();
			$('#navigation-bar-collection').hide()
			//$('#navigation-bar-collection').fadeOut();
			//$('#navigation-bar-press').fadeIn(); 
		}
	);
	
	$("#header").mouseleave(
		function () {
			$("#navigation-bar-press").hide();
			$('#navigation-bar-collection').hide();
			//$('#navigation-bar-collection').fadeOut();
			//$('#navigation-bar-press').fadeIn(); 
		}
	);
	
});

/* COLLECTION */
/* -------------------------------------------------------------- */

function initCollection()
{
	carousel = $('#content-box-big-inner-carousel');
	carouselchildren = carousel.children();
	carouselcount = carouselchildren.length;
	
	for (var i = 1; i< carouselcount; i++)
	{
		carousel.find("div:nth-child("+(i)+")").hide();
	}
	
	carousel.find("div:nth-child(1)").show();
	
	carousel.click(function()
	{
		nextItemInCollection();	
	})
}

function nextItemInCollection()
{
	carousel.find("div:nth-child("+carouselcurrent+")").hide();
	
	carouselcurrent += 1
	if (carouselcurrent > (carouselcount-1)) carouselcurrent = 1;
	
	carousel.find("div:nth-child("+carouselcurrent+")").fadeIn(400);
}

/* PRESS */
/* -------------------------------------------------------------- */

function initPress(year)
{

	$('.press-category a:first').addClass('selected');
	$('.press-holder').children().hide();
	$('.press-holder').find('.'+year).fadeIn(400);
	
	$('.year').each(function(){ 
		$(this).click(function() {
			
			$('.year').each(function(){ 
				$(this).removeClass('selected')
			});	
			$(this).addClass('selected')
			showPressItemsByYear($(this).html())
		});		
	});
}

function initStocklist(country)
{

	
	$('.press-category a:first').addClass('selected');
	$('.press-holder').children().hide();
	$('.press-holder').find('.'+country).fadeIn(400);
	
	$('.country').each(function(){ 
		$(this).click(function() {
			
			$('.country').each(function(){ 
				$(this).removeClass('selected')
			});	
			$(this).addClass('selected')
			showStocklistItemsByCountry($(this).html())
		});		
	});
	
}

function showStocklistItemsByCountry(country)
{
	$('.press-holder').children().hide();
	$('.press-holder').find('.'+country).fadeIn(400);
	$('.press-holder-scroller').jScrollPane();
}

function showPressItemsByYear(year)
{
	$('.press-holder').children().hide();
	$('.press-holder').find('.'+year).fadeIn(400);
	$('.press-holder-scroller').jScrollPane();
}

/* HELPERS */
/* -------------------------------------------------------------- */

function Void()
{

}
