$(document).ready(function(){


window.onload = imgHeights;

//$title = $('#title');
//$title.css('width', $(window).width() - 600);

$(window).bind("resize", function(){
    imgHeights();
//    $title.css('width', $(window).width() - 600);
});


$h1 = $('#title');
$menu = $('#menu');
$menuli = $menu.find('li');

//$menu_li_a = $menuli.find('a');
//$menu_li_a = $('#menu li a:not(#menu #logoSmall a), a#presentationTrigger');
$menu_li_a = $('#menu li a:not(#menu #logoSmall a), .no-touch a#presentationTrigger');

$projectLink = $('.projectLink');
$showDetail = $('#showDetail');

$logo = $('h1 .logo');

$info = $('#title, #menu li, #menu a, #presentationTrigger');
$detailTrigger = $('#showDetail');

verticals[-1] = 0;
//titles[-1] = 'Koncern Design';
colors[-1] = colors[0];
url[-1] = '';

var pos = -1;
var actual = -1;

$menu_li_a.hover(
    function() {
	$(this).css('color', colorsInverse[pos]);
	$(this).css('background-color', colors[pos]);
    },
    function() {
	$(this).css('color', colors[pos]);
	$(this).css('background-color', 'transparent');
    }
);

function refreshTitle() {
    // title
    if (titles[pos] != '') {
	$h1.text( titles[pos]);
//	Cufon.replace('#title', {fontFamily: 'Purista'});
    }

    // logo
    pos == -1 ? $logo.show() : $logo.hide();
}

function refreshColors() {
    // colors
    $menuli.removeClass('highlighted');
    $info.css('color', colors[pos]);
//    $menu_li_a.css('border-bottom-color', 'silver');
//    $menu_li_a.css('border-bottom-color', 'rgba(0, 0, 0, 0.25)');
    $menu.find('li.selected a').css('border-bottom-color', colors[pos]);
    $detailTrigger.css('background-color', colors[pos]);
    $detailTrigger.css('color', colorsInverse[pos]);

//    Cufon.replace('#title', {fontFamily: 'PuristaBold'});
}

function refreshRefs() {
    // project ref
    if (type[pos] == 'project') {
	$showDetail.fadeIn(300);
	$projectLink.attr('href', url[pos]);
	$menu.find('li[id="' +  ids[pos] + '"]').addClass('highlighted').find('a').css('border-bottom-color', colors[pos]);
    } else {
	$showDetail.hide();
	$projectLink.removeAttr('href');
    }
}

if ($(window).width() > 480) {

    refreshTitle();
    refreshColors();
    refreshRefs();

    $(window).scroll(function () {
	scroll = $(window).scrollTop();

    //    $h1.text( verticals[0]);

	pos = 0;
	for (var i = 0; i < verticals.length; i++) {
	    if (scroll + 42> verticals[i]) {
		pos = i;
	    }
	}

	if (pos != actual) {
	    actual = pos;

	    refreshTitle();
	    refreshColors();
	    refreshRefs();
	}

    }).trigger('scroll');
} // win.width > 480


});
