// JavaScript Document

var storeitems = [];
var columns = [];

function setup_nav()
{
	// elements
	var nav = $('nav');
	var logo = $('header');
	
	var navy = parseInt(nav.css('margin-top'));
	var logoy = parseInt(logo.css('margin-top'));
	
	var wy = 0;
	
	$(window).scroll(function(){
	
		wy = $(window).scrollTop();
		
		/*
		if(wy >= 60)
		{
			//$('#bodylogo').css({'position' : 'fixed', 'top' : 0});
			$('#bodylogo').css({'position' : 'fixed', 'top' : 0, 'left' : '50%', 'margin-left' : '-550px'});	
		}
		else if(wy < 60)
		{
			$('#bodylogo').css({'position' : 'relative', 'top' : '60px', 'left' : '50%', 'margin-left' : '-550px'});
		}
		*/
		// nav
		if(wy >= logoy)
		{
			logo.removeClass('relative-logo');
			logo.addClass('fixed-logo');
		}
		else if(wy < logoy)
		{
			logo.removeClass('fixed-logo');
			logo.addClass('relative-logo');
		}
		
		if(wy >= navy)
		{
			nav.removeClass('relative-navigation');
			nav.addClass('fixed-navigation');
		}
		else if(wy < navy)
		{
			nav.removeClass('fixed-navigation');
			nav.addClass('relative-navigation');
		}
	
	}).trigger('scroll');

}

function setup_store()
{
	
	
	
	
	
	
	
	$('.store-item').each(function(){ 
	
		$('.store-item-text', this).stop(true,true).hide();
		$('.store-item-text-bg', this).stop(true,true).hide();
				
		var width = $('.store-item-image img', this).attr('width')
		var height = $('.store-item-image img', this).attr('height')
		
		
		$(this).css("width", width+"px")
		$(this).css("height", height+"px")
		
		$('.store-item-text', this).css("width", width+"px")
		$('.store-item-text', this).css("height", height+"px")
		
		$('.store-item-text-bg-inner', this).css("width", width+"px")
		$('.store-item-text-bg-inner', this).css("height", height+"px")
		
		$('.store-item-text', this).find('.store-item-text-inner').css('margin-top', (height/2 - 20) + "px")

		$(this).hover(
			function () {
				$('.store-item-text', this).stop(true,true).fadeIn(100);	
				$('.store-item-text-bg', this).stop(true,true).fadeIn(100);		
			},
			function () {
				$('.store-item-text', this).stop(true,true).fadeOut(100);
				$('.store-item-text-bg', this).stop(true,true).fadeOut(100);
			}
		);
		
	});
	
	$('.store-item-holder').each(function(){ 
		storeitems.push($(this))
	})
	
	columns.push($('.column-01'))
	columns.push($('.column-02'))
	columns.push($('.column-03'))
	
	
	var smallestnumber = 999999999999999;
	
	
	var shortestcolumn = $('.column-01');
	
	for(var i=0; i < storeitems.length; i++)
	{
		var currentsmallestcolumn;
		
		smallestnumber = 999999999999999;
		var smallestcolumn;
		
		for (var j= 0; j< columns.length; j++)
		{
			
			if (columns[j].height() < smallestnumber)
			{
				smallestnumber = columns[j].height()
				smallestcolumn = columns[j];
				
			}	
		}
		
		smallestcolumn.append(storeitems[i]);
		smallestcolumn.append('<div class="clear"></div>');
	
	}
	
	//smallestcolumn.append(storeitems[i]);
	
	columns[0].append('<div class="clear"></div>');
	columns[1].append('<div class="clear"></div>');
	columns[2].append('<div class="clear"></div>');
	
}
