/*
***
by Jan Tackmann
***
*/

var locationItemWidth = 420;
var referenceImageWidth = 586;
var referenceInfoWidth = 170;


// ScrollTO
$('nav a,footer a.up, #article_start .textContent p a, .inner .article_productions').click(function(e){
	$.scrollTo( this.hash || 0, 500);
	e.preventDefault();
});



// readyLoaded
$(document).ready(function() {
   // put all your jQuery goodness in here.
   // div showing
   //$(".inner").css('position', 'absolute' );
   //$("article").css('padding', 0 );
});

/*
// Waypoints
$('#article_start').waypoint(function() {  
	$("nav a").animate({ opacity: 1 }, 100);  
	$("nav a.article_start").animate({ opacity: 0.5 }, 100);
});
$('#article_productions').waypoint(function() { 
	$("nav a").animate({ opacity: 1 }, 100);  
	$("nav a.article_productions").animate({ opacity: 0.5 }, 100);
});
$('#article_locations').waypoint(function() { 
	$("nav a").animate({ opacity: 1 }, 100);  
	$("nav a.article_locations").animate({ opacity: 0.5 }, 100);
});
$('#article_services').waypoint(function() { 
	$("nav a").animate({ opacity: 1 }, 100);  
	$("nav a.article_services").animate({ opacity: 0.5 }, 100);
});
$('#article_country').waypoint(function() { 
	$("nav a").animate({ opacity: 1 }, 100);  
	$("nav a.article_country").animate({ opacity: 0.5 }, 100);
});
*/



//// update track-width locs
// count locations
var locItems = $("#locations #track .location-item").length;
var locWidth =  locItems * locationItemWidth;
// resize
$("#locations #track").css('width', locWidth );


/*
// count references
var refItems = $("#references_container .reference_box").length;
var refWidth =  refItems * referenceItemWidth;
// resize
$("#references_container").css('width', refWidth );
*/

// count references
var refImages = $("#references_container .lazy-2").length;
var refInfos = $("#references_container .ref_info").length;

var refImagesWidth =  refImages * referenceImageWidth;
var refInfoWidth =  refInfos * referenceInfoWidth;

var refBarWidth =  refImagesWidth + refInfoWidth;
// resize
$("#references_container").css('width', refBarWidth );





/*
*
dimensions + positioning
*
*/
var windowWidth;
var windowHeight;
var innerWidth = 450;
var innerHeight = 250;

/* init */
getWindowDimensions();
resizeContent();


/* get window dimensions */
function getWindowDimensions() {
	windowWidth = $(window).width();
	windowHeight = $(window).height();  
}

/* update window dimensions on resize */
$(window).resize(function(){ 
	getWindowDimensions();
	resizeContent();
});


/* resize content */
function resizeContent() {
	
	//$("article").css('width', windowWidth);
	//$("article").css('height', windowHeight);
	//$("article").css('top', 0);
	//$("article").css('left', 0);
	//$(".inner").css('top', (windowHeight / 2 - innerHeight) );
	//$(".inner").css('left', (windowWidth / 2 - innerWidth) );
	
	//$("#article_locations").css('width', windowWidth);
	//$("#article_locations").css('height', windowHeight);
	$("#article_locations .expand").css('width', (windowWidth-60) );
	$("#article_locations .expand").css('height', (windowHeight));
	$("#article_locations .expand").css('top', (100) );
	$("#article_locations .expand").css('left', (30) );
	$("#article_locations .expand #locations").css('width', 'auto' );
	
	/*
	if(windowWidth < 950){
		$("#article_start").css('background-position', '120% bottom');
		$("#articles").css('background-position', '30px 16px');
	} else {
		$("#article_start").css('background-position', 'right bottom');
		$("#articles").css('background-position', '70px 36px');
	}
	*/
}


/* jscrollpane */
$(function(){
	$('#locations').jScrollPane();
	//$('#article_productions .textContent').jScrollPane();
	$('#article_productions #references').jScrollPane();
});

/* lazyloader */
$("img.lazy").lazyload({         
     container: $("#locations"),
	 effect      : "fadeIn"
});

$("img.lazy").lazyload({         
     container: $("#locations-thumb"),
	 effect      : "fadeIn"
});

$("img.lazy-2").lazyload({         
     container: $(".reference_box"),
	 effect      : "fadeIn"
});

$("img.lazy-2").lazyload({         
	 effect      : "fadeIn"
});

