﻿// JavaScript Document

/*FUNKTION TIL POP-UP AF MODELLER*/
function stopUrl() {
    if (!document.getElementsByTagName) return false;
    var lnks = document.getElementsByTagName("a");
    for (var i = 0; i < lnks.length; i++) {
        if (lnks[i].className == "control") {
            lnks[i].onclick = function() {
                this.getAttribute("href");
                return false;
            }
        }
    }
}

/*FUNKTIION TIL STØRRE/MINDRE TEKST*/
var min = 9;
var max = 15;
function increaseFontSize() {
    var p = document.getElementsByTagName('p');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != max) {
            s += 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('div');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != max) {
            s += 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('a');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != max) {
            s += 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('h1');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != max) {
            s += 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('h2');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != max) {
            s += 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('h3');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != max) {
            s += 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('h4');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != max) {
            s += 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('span');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != max) {
            s += 1;
        }
        p[i].style.fontSize = s + "px"
    }
}
function decreaseFontSize() {
    var p = document.getElementsByTagName('p');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != min) {
            s -= 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('div');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != min) {
            s -= 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('a');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != min) {
            s -= 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('h1');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != min) {
            s -= 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('h2');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != min) {
            s -= 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('h3');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != min) {
            s -= 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('h4');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != min) {
            s -= 1;
        }
        p[i].style.fontSize = s + "px"
    }
    var p = document.getElementsByTagName('span');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != min) {
            s -= 1;
        }
        p[i].style.fontSize = s + "px"
    }
}



$(document).ready(function() {
    var currentPosition = 0;
    var currentSubPosition = 0;
    var slideWidth = 493;
    var slideWidthPadding = 503;
    var slides = $('.box');
    var slidesSub = $('.box-sub');
    var numberOfSlides = slides.length;
    var numberOfSlidesSub = slidesSub.length;

    // Remove scrollbar in JS
    $('#slidesContainer').css('overflow', 'hidden');

    // Wrap all .slides with #slideInner div
    slides
    .wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
	    'float': 'left',
	    'width': slideWidth
	});

    slidesSub
    .wrapAll('<div id="slideInnerSub"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
	    'float': 'left',
	    'width': slideWidthPadding
	});

    // Set #slideInner width equal to total width of all slides
    $('#slideInner').css('width', slideWidthPadding * numberOfSlides);
    $('#slideInnerSub').css('width', slideWidthPadding * numberOfSlidesSub);

    // Insert controls in the DOM
    $('#slideshowsub')
.prepend('<div id="controls"></div>');

    $('#slidesContainer')
.prepend('<div id="frontcontrols"></div>');

    $('#controls')
.prepend('<div id="left"><p class="more"><span class="control" id="rightControl">Forrige</span></p></div>')
.append('<div id="right"><p class="more"><span class="control" id="leftControl">Næste</span></p></div>');

    $('.box')
.append('<p class="morefront"><span id="rightControl" class="frontcontrol">Forrige</span><span id="leftControl" class="frontcontrol">Næste</span></p>');

    // Hide left arrow control on first load
    //manageControls(currentSubPosition);

    // Create event listeners for .controls clicks
    $('.control')
    .bind('click', function() {
        // Hide / show controls


        // Determine new position
        //currentSubPosition = ($(this).attr('id') == 'leftControl') ? currentSubPosition + 1 : currentSubPosition - 1;
        currentSubPosition = ($(this).attr('id') == 'rightControl') ? currentSubPosition - 1 : currentSubPosition + 1;
        manageSubControls(currentSubPosition);

        // Move slideInner using margin-left
        $('#slideInnerSub').animate({
            'marginLeft': slideWidthPadding * (-currentSubPosition)
        }, 0)
    });

    $('.frontcontrol')
    .bind('click', function() {
        // Determine new position
        currentPosition = ($(this).attr('id') == 'rightControl') ? currentPosition - 1 : currentPosition + 1;


        // Hide / show controls
        manageControls(currentPosition);

        // Move slideInner using margin-left
        $('#slideInner').animate({
            'marginLeft': slideWidthPadding * (-currentPosition)
        }, 0)

    });

    // manageControls: Hides and Shows controls depending on currentPosition
    function manageControls(position) {

        if (position == numberOfSlides) { currentPosition = 0; }
        if (position < 0 && $(this).attr('id') != 'rightControl') { currentPosition = numberOfSlides - 1; }
        //if (position == numberOfSlides) { currentPosition = 0; }
        // Hide left arrow if position is first slide
        //if (position == 0) { $('#left').hide() } else { $('#left').show() }
        // Hide right arrow if position is last slide
        //if (position == numberOfSlides - 1) { $('#right').hide() } else { $('#right').show() }
    }

    function manageSubControls(position) {
        if (position == numberOfSlidesSub) { currentSubPosition = 0; }
        if (position < 0 && $(this).attr('id') != 'rightControl') { currentSubPosition = numberOfSlidesSub - 1; }
        // Hide left arrow if position is first slide
        //if (position == 0) { $('#left').show() } else { $('#left').show() }
        // Hide right arrow if position is last slide
        //if (position == numberOfSlidesSub - 1) { $('#right').hide() } else { $('#right').show() }
        //if (position == numberOfSlidesSub-1) { $('#right').hide() } else { $('#right').show() }
    }

});
