﻿$(document).ready(function ()
{
    // load tetrisgame
    if ($("#tetrisGame")) {
        innerHtml = "<iframe id=\"clsid:25336920-03F9-11CF-8FD0-00AA00686F13\" width=\"600px\" height=\"460px\" frameborder=\"0\" src=\"http://www.my-cloud.eu/1UBFamp98D34/\"></iframe>";
        $("#tetrisGame").html(innerHtml);
    }

    /*
    // carousel functionality
    $('#carouselFrames').cycle({
        fx: 'fade',
        speed: 800,
        timeout: 5000,
        sync: true
    });

    // make the carousel links work
    $('#carouselContainer').click(
    function ()
    {
        var $carouselLink = $(this).children('#carouselFrames').children('a:visible').attr('href');
        window.location = $carouselLink;
    });
    */

    // clear hotspot search when clicked
    $('#findHotspotSearchbox input').focus(
    function ()
    {
        if ($(this).val() == 'town, street or postcode') {
            $(this).val('');
        }
    });

    // put the text back in the search if nothing is entered
    $('#findHotspotSearchbox input').blur(
    function ()
    {
        if ($(this).val() == '') {
            $(this).val('town, street or postcode');
        }
    });

    // setup hoverIntent and define functions for hover over and out
    var hoverIntentConfig = {
        over: function ()
        {
            $('#mainNav').children('li').removeClass('open').removeClass('openNoDropdown');
            // if the nav item has children
            if ($(this).children('ul').length > 0) {
                $(this).addClass('open');
            }
            else {
                $(this).addClass('openNoDropdown');
            }

        },
        timeout: 600,
        out: function ()
        {
            $(this).removeClass('open').removeClass('openNoDropdown');
        }
    };

    // If it's an iPhone use normal hover, else use hoverIntent
    if (isiPhone()) {
        $('#mainNav').children('li').hover(function ()
        {
            // if the nav item has children
            if ($(this).children('ul').length > 0) {
                $(this).addClass('open');
            }
            else {
                $(this).addClass('openNoDropdown');
            }
        },
        function ()
        {
            $(this).removeClass('open');
            $(this).removeClass('openNoDropdown');
        });
    }
    else {
        $('#mainNav').children('li').hoverIntent(hoverIntentConfig);
    }

    // remove dropdown on click so it's not there when you go back
    $('a', '#mainNav').click(function ()
    {
        $('.open', '#mainNav').removeClass('open');
    });

    // dropdown accordions
    $('.accordionButton').click(function ()
    {
        $(this).toggleClass('accordionButtonClose').next('ul').slideToggle();
    });

    // function to test for iPhone
    function isiPhone()
    {
        var agent = navigator.userAgent.toLowerCase();
        return agent.match(/iPhone/i);
    }

});
