﻿/// <reference path="jquery-1.4.1-vsdoc.js" />

/*----------------------------------
*Filename: StyleSheet.css
*Description: Landing Page Scripts
*Author: Greg Rafferty
*Date: 10-08-2010
*Website: durex.com
----------------------------------*/
// open modal
var showModalWindow = function (selectedArea) {
    if ($.browser.msie) {
        $('#modal').show();
    } else {
        $('#modal').fadeIn(500);
    }

    selectContinent(selectedArea);

    return false;
}

//close modal
function closeModalWindow() {
    if ($.browser.msie) {
        $('#modal').hide();
        $('#modal .continent').fadeOut(500);
    } else {
        $('#modal').fadeOut(500);
        $('#modal .continent').fadeOut(500);
    }
    return false;
}

//select Continent
function selectContinent(selectedArea) {
    $('#modal .continent li a').removeClass('selected').parent().find('.' + selectedArea).addClass('selected');

    if ($.browser.msie) {
        $('#modal .continent').hide();
        $('#modal .continent.' + selectedArea).show();
    } else {
    $('#modal .continent').fadeOut(500);
    //$('#modal .continent').slideUp(500);
    $('#modal .continent.' + selectedArea).delay(505).fadeIn(500);
        //$('#modal .continent').slideDown(500);
    }
    return false;
}

// country selector
$(document).ready(function () {

    $('#country-list .continent').hide(); //makes sure there is no intitial cross fading
    $('#country-list .continent h2').hide(); //Makes these invisible on handhelds with javascript
    //Hover/Click behaviours

    $('.country-selector .area, .continent-text-list .area').bind('click.openModal',
        function () {
            var selectedArea = $(this).attr('class');

            selectedArea = selectedArea.replace('area', '').replace(' ', '');

            showModalWindow(selectedArea);

            return false;
        }
    ).bind('mouseover focus',
        function () {
            var selectedArea = $(this).attr('class');

            selectedArea = selectedArea.replace('area', '').replace(' ', '');

            $('.country-selector .area-highlight').addClass('highlight-' + selectedArea);

        }).bind('mouseout blur',
        function () {
            $('.country-selector .area-highlight')
                .removeClass('highlight-africa')
                .removeClass('highlight-asia-pacific')
                .removeClass('highlight-europe')
                .removeClass('highlight-latin-america')
                .removeClass('highlight-middle-east')
                .removeClass('highlight-north-america');
        }
    );

    //Click within modal
    $('#continent-list a').click(function () {

        var continentName = $(this).attr('class');

        selectContinent(continentName);

        return false;
    });

    //Close Button
    $('#modal .close').click(function () {
        closeModalWindow();
        return false;
    });

    //Select Continent (modal already open)
    $('.continent-list li a').click(function () {
        var selectedArea = $(this).attr('class');
        selectContinent(selectedArea);
        return false;
    });

});

$(document).ready(function () {
    //image rotator
    $('.rotator').append('<div id="rotator-nav">');
    $('#cycle').cycle({
        fx: 'fade',
        speed: '1900',
        timeout: 5000,
        pager: '#rotator-nav'
    });
});

//refomat long country lists
$(document).ready(function () {

    $('#country-list .continent').each(function (i) {
        var continentDiv = $(this);
        var listLength = $(this).find('li').length;
        if (listLength > 15) {
            var splitListLength = Math.ceil(listLength / 2);
            var Jlistobj = null;
            $(this).find('li').each(function (i) {
                if (i % splitListLength == 0) {
                    Jlistobj = $("<ul></ul>");
                }
                Jlistobj.append($(this));
                continentDiv.append(Jlistobj);
            }); //end li loop

            $(this).find('ul:first').remove();
        }
    }); // end continent loop

});
