/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var preload_images = new Array();

var page;

function addNaviHover(){
    ori_img = true;
    $('#navigation a img.inactive').hover(
	function(){ //HOVER IN
	    ThisImage = $(this);
	    imagepath = $(this).attr('src');
	    ori_img = imagepath;
	    imagepath = imagepath.replace("-norm.png","-hover.png");
	    newimg = new Image();
	    $(newimg).bind('load',function(){
		//alert('Fu Bar');
		
	    });
	    newimg.src = imagepath;
	    $(ThisImage).css("margin-top", "0px").attr('src', imagepath.toString());
	},
	function(){ //HOVER OUT
	    imagepath = $(this).attr('src');
	    imagepath = imagepath.replace("-hover.png","-norm.png");
	    $(this).css("margin-top", "26px").attr('src', imagepath.toString());
	});
}

function addSocialHover(){
    ori_img = true;
    $('div.social-link-icon a img').hover(
	function(){ //HOVER IN
	    ThisImage = $(this);
	    imagepath = $(this).attr('src');
	    ori_img = imagepath;
	    imagepath = imagepath.replace(".png","-hover.png");
	    newimg = new Image();
	    $(newimg).bind('load',function(){
		//alert('Fu Bar');
		$(ThisImage).css("margin-top", "0px").attr('src', imagepath.toString());
	    });
	    newimg.src = imagepath;
	},
	function(){ //HOVER OUT
	    imagepath = $(this).attr('src');
	    imagepath = imagepath.replace("-hover.png",".png");
	    $(this).attr('src', imagepath.toString());
	});
}

function addNaviActive(name){
    sitename = explode('_', name);
    $('#navigation a#'+sitename[0]+' img').removeClass('inactive');
    $('#navigation a#'+sitename[0]+' img').addClass('active');
    $('#navigation a#'+sitename[0]+' img').attr('src', 'css/images/'+sitename[0].toString()+'.png');
}

function resetNaviActive(){
    $('#navigation a img').each(function(){
	$(this).removeClass('active');
	$(this).addClass('inactive');
    })
}

function drawNavi(){
    $('div#navibar').empty();
    $('div#navibar').append("<ul id=\"navigation\">\n\
                    <li><a href=\"#home\" rel=\"history\" id=\"home\"><img style=\"margin-top: 26px;\" src=\"css/images/home-norm.png\" alt=\"home\" class=\"inactive\"></a></li>\n\
                    <li><a href=\"#news\" rel=\"history\" id=\"news\"><img style=\"margin-top: 26px;\" src=\"css/images/news-norm.png\" alt=\"news\" class=\"inactive\"></a></li>\n\
                    <li><a href=\"#gigs\" rel=\"history\" id=\"gigs\"><img style=\"margin-top: 26px;\" src=\"css/images/gigs-norm.png\" alt=\"gigs\" class=\"inactive\"></a></li>\n\
                    <li><a href=\"#bio\" rel=\"history\" id=\"bio\"><img style=\"margin-top: 26px;\" src=\"css/images/bio-norm.png\" alt=\"bio\" class=\"inactive\"></a></li>\n\
                    <li><a href=\"#rels\" rel=\"history\" id=\"rels\"><img style=\"margin-top: 26px;\" src=\"css/images/rels-norm.png\" alt=\"rels\" class=\"inactive\"></a></li>\n\
                    <li><a href=\"#compilations\" rel=\"history\" id=\"compilations\"><img style=\"margin-top: 26px;\" src=\"css/images/compilations-norm.png\" alt=\"compilations\" class=\"inactive\"></a></li>\n\
                    <li><a href=\"#refs\" rel=\"history\" id=\"refs\"><img style=\"margin-top: 26px;\" src=\"css/images/refs-norm.png\" alt=\"refs\" class=\"inactive\"></a></li>\n\
                    <li><a href=\"#downloads\" rel=\"history\" id=\"downloads\"><img style=\"margin-top: 26px;\" src=\"css/images/downloads-norm.png\" alt=\"downloads\" class=\"inactive\"></a></li>\n\
                    <li><a href=\"#contact\" rel=\"history\" id=\"contact\"><img style=\"margin-top: 26px;\" src=\"css/images/contact-norm.png\" alt=\"contact\" class=\"inactive\"></a></li>\n\
                    <li><a href=\"#links\" rel=\"history\" id=\"links\"><img style=\"margin-top: 26px;\" src=\"css/images/links-norm.png\" alt=\"links\" class=\"inactive\"></a></li>\n\
                    <li><a href=\"#imprint\" rel=\"history\" id=\"imprint\"><img style=\"margin-top: 26px;\" src=\"css/images/imprint-norm.png\" alt=\"imprint\" class=\"inactive\"></a></li>\n\
                </ul>");
}

$(function(){

    

    $.history.init(pageload);
    $("a[rel='history']").click(function(e) {
	var url = this.href;
	url = url.replace(/^.*#/, '');
	$.history.load(url);
	return false;
    });

    if (location.hash && location.hash !== '#home') {
	$.history.load(location.hash.replace(/^.*#/, ''));
    } else {
	$.history.load('home');
    }

    function pageload(hash) {
	if(hash) {
	    if($.browser.msie) {
		hash = encodeURIComponent(hash);
	    }
	    loadpage(hash);
	}
    }

    function loadpage (page){
	$('#maincontent').empty();
	$('#back').html('&nbsp;');
	$('#loadmore').html('&nbsp;');
	$('#forward').html('&nbsp;');

	//PRELOAD HOVER IMAGES
	$('#navigation a img').each(function(){
	    imagepath = $(this).attr('src');
	    imagepath = imagepath.replace("-norm.png","-hover.png");
	    newimg = new Image();
	    newimg.src = imagepath;
	    preload_images[preload_images.length] = newimg;
	    imagepath = $(this).attr('src');
	    imagepath = imagepath.replace("-norm.png",".png");
	    newimg = new Image();
	    newimg.src = imagepath;
	    preload_images[preload_images.length] = newimg;
	})


	$('#navigation a img').css("margin-top", "26px");
	$('#navigation a').css({
	    "height": "53px",
	    "display": "block"
	});

	drawNavi();

	// LOAD ACTIVE NAVI ELEMENT
	resetNaviActive();
	addNaviActive(page);
	addNaviHover();
	addSocialHover();
	// ------------------------

	if (page == "home"){
	    load_home();
	}
	else if( page == "news" ){
	    load_news(1);
	}
	else if ((match_res = page.match(/^news_p_([0-9]+)/)) != null){
	    load_news(match_res[1]);
	}
	else if ((match_res = page.match(/^news_([0-9]+)/)) != null){
	    load_news_item(match_res[1]);
	}
	else if (page == "bio"){
	    load_bio();
	}
	else if (page == "gigs"){
	    load_gigs(1);
	}
	else if ((match_res = page.match(/^gigs_p_([0-9]+)/)) != null){
	    load_gigs(match_res[1]);
	}
	else if ((match_res = page.match(/^gigs_([0-9]+)/)) != null){
	    load_gigs_item(match_res[1]);
	}
	else if (page == "compilations"){
	    load_comps(1);
	}
	else if ((match_res = page.match(/^compilations_p_([0-9]+)/)) != null){
	    load_comps(match_res[1]);
	}
	else if (page == "refs"){
	    load_refs();
	}
	else if (page == "rels"){
	    load_rels(1);
	}
	else if ((match_res = page.match(/^rels_p_([0-9]+)/)) != null){
	    load_rels(match_res[1]);
	}
	else if (page == "imprint"){
	    load_imprint();
	}
	else if (page == "contact"){
	    load_contact();
	}
	else if (page == "links"){
	    load_links();
	}
	else if (page == "downloads"){
	    load_downloads();
	}
	match_res = null;
    }

 
/*
     * NAVIGATION MOUSEOVER IMAGES
     */

    

    
});

