/// <reference path="jquery-1.4.1-vsdoc.js" />
/// <reference path="swfobject-vsdoc.js" />

var still_hover = true;
var width_inactive = 160;
var width_avtive = 545;

$(document).ready(function() {


    function scan(this_div) {
        $(this_div).textscan({

            spanize: -1,
            unspanize: -1,
            spanClass: 'anim',
            initColor: 'ffffff',
            endColor: 'ffffff',
            transColor: '666666',
            cb: function() {
                if (still_hover) {
                    scan(this_div);
                }
            }
        });
    }

    $('.div_top_menu .menu li a.inactive').spanize('anim', 1);
    $('.div_top_menu .menu li a.inactive').hover(function animateit() {
        still_hover = true;
        scan(this);
    },
    // on mouse out
    function() {
        window.clearInterval;
        still_hover = false;
    });

    $("#div_contentwrapper_middle li").hover(function() {

        var this_id = (($(this).attr("id")).substring(3, $(this).attr("id").length));

        if (this_id == 1) {
            $("li#li_2").stop().animate({ left: (width_avtive - 5) + "px" }, { duration: 200 });
            $("li#li_3").stop().animate({ left: (width_avtive + width_inactive - 5) + "px" }, { duration: 200 });
            $("li#li_4").stop().animate({ left: (width_avtive + width_inactive * 2 - 5) + "px" }, { duration: 200 });
        }

        else if (this_id == 2) {
            $("li#li_2").stop().animate({ left: (width_inactive - 5) + "px" }, { duration: 200 });
            $("li#li_3").stop().animate({ left: (width_avtive + width_inactive - 5) + "px" }, { duration: 200 });
            $("li#li_4").stop().animate({ left: (width_avtive + width_inactive * 2 - 5) + "px" }, { duration: 200 });
        }

        else if (this_id == 3) {
            $("li#li_2").stop().animate({ left: (width_inactive - 5) + "px" }, { duration: 200 });
            $("li#li_3").stop().animate({ left: (width_inactive * 2 - 5) + "px" }, { duration: 200 });
            $("li#li_4").stop().animate({ left: (width_avtive + width_inactive * 2 - 5) + "px" }, { duration: 200 });
        }

        else if (this_id == 4) {
            $("li#li_2").stop().animate({ left: (width_inactive - 5) + "px" }, { duration: 200 });
            $("li#li_3").stop().animate({ left: (width_inactive * 2 - 5) + "px" }, { duration: 200 });
            $("li#li_4").stop().animate({ left: (width_inactive * 3 - 5) + "px" }, { duration: 200 });
        }
    },
    // on mouse out
    function() {

    });

    $("#div_contentwrapper_middle ul").hover(function() {
    },
    // on mouse out
    function() {

        var width_inactive = 160;
        var width_avtive = 545;

        if ($("li.last").hasClass("active_last")) {
            $("li#li_2").stop().animate({ left: (width_inactive - 5) + "px" }, { duration: 200 });
            $("li#li_3").stop().animate({ left: (width_inactive * 2 - 5) + "px" }, { duration: 200 });
            $("li#li_4").stop().animate({ left: (width_inactive * 3 - 5) + "px" }, { duration: 200 });
        }

        else {
            var this_id = (($("li.active").attr("id")).substring(3, $("li.active").attr("id").length));


            if (this_id == 1) {
                $("li#li_2").stop().animate({ left: (width_avtive - 5) + "px" }, { duration: 200 });
                $("li#li_3").stop().animate({ left: (width_avtive + width_inactive - 5) + "px" }, { duration: 200 });
                $("li#li_4").stop().animate({ left: (width_avtive + width_inactive * 2 - 5) + "px" }, { duration: 200 });
            }

            else if (this_id == 2) {
                $("li#li_2").stop().animate({ left: (width_inactive - 5) + "px" }, { duration: 200 });
                $("li#li_3").stop().animate({ left: (width_avtive + width_inactive - 5) + "px" }, { duration: 200 });
                $("li#li_4").stop().animate({ left: (width_avtive + width_inactive * 2 - 5) + "px" }, { duration: 200 });
            }

            else if (this_id == 3) {
                $("li#li_2").stop().animate({ left: (width_inactive - 5) + "px" }, { duration: 200 });
                $("li#li_3").stop().animate({ left: (width_inactive * 2 - 5) + "px" }, { duration: 200 });
                $("li#li_4").stop().animate({ left: (width_avtive + width_inactive * 2 - 5) + "px" }, { duration: 200 });
            }
            else if (this_id == 4) {
                $("li#li_2").stop().animate({ left: (width_inactive - 5) + "px" }, { duration: 200 });
                $("li#li_3").stop().animate({ left: (width_inactive * 2 - 5) + "px" }, { duration: 200 });
                $("li#li_4").stop().animate({ left: (width_inactive * 3 - 5) + "px" }, { duration: 200 });
            }
        }


        //$("li.not_last").stop().animate({width: "155px"}, {duration: 200});
        //$("li.active_last").stop().animate({width: "540px"}, {duration: 200});

    });



    // add resize event on window - to position elements according to Mister Senior Art Director Tom Olsens disgressions.
    $(window).resize(function () { repos($(this)) });
});


function show_more_news() {
    $("#div_more_news").css("display", "block");
}
function repos(w) {
	var wh = $(window).height();
    var ch = $("#div_main").height();

	var bh = wh;
	var totalh = ch;

if (w.height() > totalh) totalh = w.height();

$("#div_main").css("height", totalh);
$("#div_contentwrapper").css("height", totalh-76);
$("body").height(totalh);
}
