m = 260;
try {
	b = $(window).width();
	h = $(window).height();
}
catch (e) {
}
hok = h - m;
hoknav = hok / 2 - 46;

$(function() {
    function slidePanel( newPanel, direction ) {
        // define the offset of the slider obj, vis a vis the document
        var offsetLeft = $slider.offset().left;

        // offset required to hide the content off to the left / right
        var hideLeft = -1 * ( offsetLeft + $slider.width() );
        var hideRight = $(window).width() - offsetLeft;

        // change the current / next positions based on the direction of the animation
        if ( direction == 'left' ) {
            currPos = hideLeft;
            nextPos = hideRight;
        }
        else {
            currPos = hideRight;
            nextPos = hideLeft;
        }

        // slide out the current panel, then remove the active class
        $slider.children('.slide-panel.active').animate({
            left: currPos
        }, 500, function() {
            $(this).removeClass('active');
        });

        // slide in the next panel after adding the active class
        $( $sliderPanels[newPanel] ).css('left', nextPos).addClass('active').animate({
            left: 0
        }, 500 );
    }

    var $slider = $('#full-slider');
    var $forside_neste = $('.forside_neste');
    var $forside_tilbake = $('.forside_tilbake');
    var $sliderPanels = $slider.children('.slide-panel');

    var $navWrap = $('').appendTo( $slider );
    var $navLeft = $('').appendTo( $navWrap );
    var $navRight = $('').appendTo( $navWrap );

    var currPanel = 0;

    $forside_tilbake.click(function() {
        currPanel--;

        // check if the new panel value is too small
        if ( currPanel < 0 )  currPanel = $sliderPanels.length - 1;

        slidePanel(currPanel, 'right');
    });

    $forside_neste.click(function() {
        currPanel++;

        // check if the new panel value is too big
        if ( currPanel >= $sliderPanels.length ) currPanel = 0;

        slidePanel(currPanel, 'left');
    });
    
	$(document.documentElement).keyup(function (event) {

	if (event.keyCode == 37) {
		currPanel--;
        if ( currPanel < 0 ) currPanel = $sliderPanels.length - 1;
        slidePanel(currPanel, 'right');
	} 
	else if (event.keyCode == 39) {
		currPanel++;
		if ( currPanel >= $sliderPanels.length ) currPanel = 0;
		slidePanel(currPanel, 'left');
	}
});
});


function reportSize()
{
	myWidth = 0; 
	myHeight = 0;
	if (typeof( window.innerWidth ) == 'number')
	{
		//Non-IE
	}
	else
	{
		if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
		{
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		}
		else
		{
			if(document.body && (document.body.clientWidth || document.body.clientHeight))
			{
				//IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
		}
	}
}


 
function hallo()
{
	reportSize();
	$('#full-slider').css({width: b + 'px', height: hok + 'px'});
}
		
function init(){
	window.onresize = hallo;
	hallo();
}


function setImageSize(img){
	$(img).imageResize({width:$(window).width(),height:hok});
}
	
			
$(window).bind("load", function() {
	setImageSize('.slide-panel img');
	$(window).resize(function(){
		h = $(window).height();
		hok = h - m;
		setImageSize('.slide-panel img');
	});
});
