﻿//TEXT TOGGLE FUNCTION
function setText(ele, str) {
    document.getElementById(ele).innerHTML = str;
}
//SUSCKER FISH IE FIX
sfHover = function () {
    if (document.getElementById("main_nav") != null) {
        var sfEls = document.getElementById("main_nav").getElementsByTagName("LI");
        for (var i = 0; i < sfEls.length; i++) {
            sfEls[i].onmouseover = function () {
                this.className += " sfhover";
            }
            sfEls[i].onmouseout = function () {
                this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
            }
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//JAVASCRIPT FIX FOR NAV STYLES - OVER & OUT STATES
function parentStyles(ele) {
    if (document.getElementById(ele).className == 'active') {
        document.getElementById(ele).className = 'active over';
    } else if (document.getElementById(ele).className == '') {
        document.getElementById(ele).className = 'over';
    } else if (document.getElementById(ele).className == 'active over') {
        document.getElementById(ele).className = 'active';
    } else if (document.getElementById(ele).className == 'over') {
        document.getElementById(ele).className = '';
    }
}
//JAVSCRIPT BG IMAGE POSITION ADJUST
function moveBg(ele, int) {
    var int_x_pos = int * 130;
    document.getElementById(ele).style.backgroundPosition = '0px -' + int_x_pos + 'px';
}

// main function to process the fade request //
function colorFade(id, element, start, end, steps, speed) {
    var startrgb, endrgb, er, eg, eb, step, rint, gint, bint, step;
    var target = document.getElementById(id);
    steps = steps || 20;
    speed = speed || 20;
    clearInterval(target.timer);
    endrgb = colorConv(end);
    er = endrgb[0];
    eg = endrgb[1];
    eb = endrgb[2];
    if (!target.r) {
        startrgb = colorConv(start);
        r = startrgb[0];
        g = startrgb[1];
        b = startrgb[2];
        target.r = r;
        target.g = g;
        target.b = b;
    }
    rint = Math.round(Math.abs(target.r - er) / steps);
    gint = Math.round(Math.abs(target.g - eg) / steps);
    bint = Math.round(Math.abs(target.b - eb) / steps);
    if (rint == 0) { rint = 1 }
    if (gint == 0) { gint = 1 }
    if (bint == 0) { bint = 1 }
    target.step = 1;
    target.timer = setInterval(function () { animateColor(id, element, steps, er, eg, eb, rint, gint, bint) }, speed);
}

// incrementally close the gap between the two colors //
function animateColor(id, element, steps, er, eg, eb, rint, gint, bint) {
    var target = document.getElementById(id);
    var color;
    if (target.step <= steps) {
        var r = target.r;
        var g = target.g;
        var b = target.b;
        if (r >= er) {
            r = r - rint;
        } else {
            r = parseInt(r) + parseInt(rint);
        }
        if (g >= eg) {
            g = g - gint;
        } else {
            g = parseInt(g) + parseInt(gint);
        }
        if (b >= eb) {
            b = b - bint;
        } else {
            b = parseInt(b) + parseInt(bint);
        }
        color = 'rgb(' + r + ',' + g + ',' + b + ')';
        if (element == 'background') {
            target.style.backgroundColor = color;
        } else if (element == 'border') {
            target.style.borderColor = color;
        } else {
            target.style.color = color;
        }
        target.r = r;
        target.g = g;
        target.b = b;
        target.step = target.step + 1;
    } else {
        clearInterval(target.timer);
        color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
        if (element == 'background') {
            target.style.backgroundColor = color;
        } else if (element == 'border') {
            target.style.borderColor = color;
        } else {
            target.style.color = color;
        }
    }
}

// convert the color to rgb from hex //
function colorConv(color) {
    var rgb = [parseInt(color.substring(0, 2), 16),
    parseInt(color.substring(2, 4), 16),
    parseInt(color.substring(4, 6), 16)];
    return rgb;
}


// wrap as a jQuery plugin and pass jQuery in to our anoymous function
(function ($) {
    $.fn.cross = function (options) {
        return this.each(function (i) {
            // cache the copy of jQuery(this) - the start image
            var $$ = $(this);

            // get the target from the backgroundImage + regexp
            var target = $$.css('backgroundImage').replace(/^url|[\(\)'"]/g, '');

            // nice long chain: wrap img element in span
            $$.wrap('<span style="position: relative;"></span>')
            // change selector to parent - i.e. newly created span
                    .parent()
            // prepend a new image inside the span
                    .prepend('<img>')
            // change the selector to the newly created image
                    .find(':first-child')
            // set the image to the target
                    .attr('src', target);

            // the CSS styling of the start image needs to be handled
            // differently for different browsers
            if ($.browser.msie) {
                $$.css({
                    'position': 'absolute',
                    'left': 0,
                    'background': ''
                });
            }

            else if ($.browser.mozilla) {
                $$.css({
                    'position': 'absolute',
                    'left': 0,
                    'background': '',
                    'top': this.offsetTop
                });
            } else if ($.browser.opera && $.browser.version < 9.5) {
                // Browser sniffing is bad - however opera < 9.5 has a render bug 
                // so this is required to get around it we can't apply the 'top' : 0 
                // separately because Mozilla strips the style set originally somehow...                    
                $$.css({
                    'position': 'absolute',
                    'left': 0,
                    'background': '',
                    'top': "0"
                });
            } else { // Safari
                $$.css({
                    'position': 'absolute',
                    'left': 0,
                    'background': ''
                });
            }

            // similar effect as single image technique, except using .animate 
            // which will handle the fading up from the right opacity for us
            $$.hover(function () {
                $$.stop().animate({
                    opacity: 0
                }, 750);
            }, function () {
                $$.stop().animate({
                    opacity: 1
                }, 750);
            });
        });
    };

})(jQuery);

// note that this uses the .bind('load') on the window object, rather than $(document).ready() 
// because .ready() fires before the images have loaded, but we need to fire *after* because
// our code relies on the dimensions of the images already in place.
$(window).bind('load', function () {
    $("img#header_img").fadeIn(1000);
    $('img.fade').cross();
});



function theRotator() {
    //Set the opacity of all images to 0
    $('div#rotator ul li').css({ opacity: 0.0 });

    //Get the first image and display it (gets set to full opacity)
    $('div#rotator ul li:first').css({ opacity: 1.0 });

    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
    setInterval('rotate()', 6000);

}

function rotate() {
    //Get the first image
    var current = ($('div#rotator ul li.show') ? $('div#rotator ul li.show') : $('div#rotator ul li:first'));

    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') : current.next()) : $('div#rotator ul li:first'));

    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000);

    //Hide the current image
    current.animate({ opacity: 0.0 }, 1000)
	.removeClass('show');

};

$(document).ready(function () {
    //Load the slideshow
    $('#rotator').cycle({
        fx: 'wipe', speed: 1500, timeout: 4500, delay: 0, clip: 'r2l' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });
    if (document.getElementById('avail')) { arrcalc(); }
    //theRotator();
});

function input_focus(thisName, defaultValue) {
    if (document.getElementById(thisName).value == defaultValue) { document.getElementById(thisName).value = ''; }
}

function input_lost_focus(thisName, defaultValue) {
    if (document.getElementById(thisName).value == '') { document.getElementById(thisName).value = defaultValue; }
}

function verify_email(str) {
    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)

    if (str.indexOf(at) == -1) { return false }
    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) { return false }
    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) { return false }
    if (str.indexOf(at, (lat + 1)) != -1) { return false }
    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) { return false }
    if (str.indexOf(dot, (lat + 2)) == -1) { return false }
    if (str.indexOf(" ") != -1) { return false }
    return true
}

function checkform() {
    var str_name = document.getElementById('name').value;
    var str_email = document.getElementById('udikkr-udikkr').value;
    var bln_valid = true;
    var str_message = '';
    if (str_name == "Name" || str_name == "") {
        str_message = str_message + 'Please enter your name\n';
        bln_valid = false;
    }
    if (!verify_email(str_email) || str_email == "Email") {
        str_message = str_message + 'Please enter a valid email\n';
        bln_valid = false;
    }
    if (!bln_valid) {
        alert(str_message);
        return false;
    } else {
        document.getElementById('subscriber_form').submit();
    }
}

function submit_enquiry() {
    var str_name = document.forms["frm_enquiry"].name.value;
    var str_email = document.forms["frm_enquiry"].email.value;
    var str_postcode = document.forms["frm_enquiry"].postcode.value;
    var str_country = document.forms["frm_enquiry"].country.value;
    var bln_valid = true;
    var str_message = '';
    if (str_name == "") {
        str_message = str_message + 'Please enter your name\n';
        bln_valid = false;
    }
    if (!verify_email(str_email) || str_email == "Email") {
        str_message = str_message + 'Please enter a valid email\n';
        bln_valid = false;
    }
    if (str_postcode == "") {
        str_message = str_message + 'Please enter your postcode\n';
        bln_valid = false;
    }
    if (str_country == "") {
        str_message = str_message + 'Please enter your country\n';
        bln_valid = false;
    }
    if (!bln_valid) {
        alert(str_message);
        return false;
    } else {
        document.getElementById('frm_enquiry').submit();
    }
}

//function
//window.onload=function(){resizebg();}
//window.onresize=function(){resizebg();}

/*Start of Home Page Amends - Aug 2011*/
$(document).ready(function () {
    $('meta').each(function (index) {
        var theMeta = $(this).attr('http-equiv');
        var theContent = $(this).attr('content');
        if (theMeta == "content-language") {
            if (theContent == "en") {
                $(".lang-opts ul li a[rel=en]").attr('class', 'active en');
            }
            else if (theContent == "fr") {
                $(".lang-opts ul li a[rel=fr]").attr('class', 'active fr');
            }
            else if (theContent == "de") {
                $(".lang-opts ul li a[rel=de]").attr('class', 'active de');
            }
        }
    });

    /*Short Breaks*/
    $('.large-promo .buttons ul li:last').attr('class', 'last');
    $('.gift-block .buttons ul li a:last').attr('class', 'last');

    var a_href = $('.fading-images > a').attr('href');
    var img_path = $('.fading-images > a').attr('rel');

    if ($('.fading-images')[0]) {
        var div = $('<div>').attr('class', 'iw').css('opacity', 0);
        var a = $('<a>').attr('href', a_href);
        var img = $('<img>').attr('src', img_path);
        $('.fading-images').append(div.append(a.append(img)));

        $('div.fading-images').hover(function () {
            var imgFade = $('.iw');
            imgFade.stop().fadeTo(750, 1);
        }, function () {
            var imgFade = $('.iw');
            imgFade.stop().fadeTo(750, 0);
        });

        $('.large-promo .buttons li a').hover(function () {
            var imgFade = $('.iw');
            imgFade.stop().fadeTo(750, 1);
        });
    }
    /*Gift Vouchers*/
    $('.gimg').css('opacity', 0);

    $('.gift-block .buttons ul li').hover(function () {
        var a = $('> a', this);
        var imgHolder = $('.gimg');
        imgHolder.find('img').attr('src', a.attr('rel'));
        imgHolder.stop().fadeTo(500, 1);
    }, function () {
        var imgHolder = $('.gimg');
        imgHolder.stop().fadeTo(500, 0);
    });
});
/*End of Home Page Amends - Aug 2011*/

