﻿// UTF8‼
Cufon
.replace('#content h1, #nav_cat_context_list a, #products h2, #products h3, #products h4, #products_details .downloads li',{
	separate:'none',
	fontFamily:'AgencyFB-BoldCondensed',
	textShadow:'2px 2px rgba(0,0,0,0.25)'
})
.replace('#productrange_list li a .title',{
	separate:'none',
	fontFamily:'AgencyFB-BoldCondensed',
	textShadow:'1px 1px rgba(0,0,0,0.75)'
})
.replace('#nav_sub a',{
	separate:'none',
	fontFamily:'Serpentine-Light',
	textShadow:'1px 1px rgba(0,0,0,0.5)',
	hover:true
});

$(document).ready(function () {

    // If location data exists and a cookie hasn't been set (i.e. we haven't redirected already)
    if (google.loader.ClientLocation && $.cookie('country_code') === null) {
        $.cookie('country_code', google.loader.ClientLocation.address.country_code, { path: '/', expires: 10 });
        switch (google.loader.ClientLocation.address.country_code) {
            case 'GB':
                if (v_lng_id != 'EN') {
                    window.location.href = window.location.href.toLowerCase().replace('/' + v_lng_id.toLowerCase() + '/', '/');
                }
                break;
            case 'DE':
            case 'ES':
            case 'FR':
            case 'IT':
            case 'NL':
            case 'US':
                if (v_lng_id != google.loader.ClientLocation.address.country_code) {
                    switch (v_lng_id) {
                        case 'EN':
                            // No Sub-folder for English
                            window.location.href = window.location.href.toLowerCase().replace(v_url_root.toLowerCase(), v_url_root.toLowerCase() + google.loader.ClientLocation.address.country_code.toLowerCase() + '/');
                            break;
                        default:
                            window.location.href = window.location.href.toLowerCase().replace('/' + v_lng_id.toLowerCase() + '/', '/' + google.loader.ClientLocation.address.country_code.toLowerCase() + '/');
                            break;
                    }
                }
                break;
        }
    }

    $('html').addClass('jquery-active');
    var v_anim_safe = ((/MSIE (\d+\.\d+);/.test(navigator.userAgent) == false) ? true : false);

    // Calculate Total Width of Scroller (Remove the negative margin from each li)
    var nav_cat_context_list_w = 0;
    $('#nav_cat_context_list li').each(function () {
        nav_cat_context_list_w += ($(this).width() - 90);
    });
    $('#nav_cat_context_list').width(nav_cat_context_list_w);

    if ($('#nav_cat_context_list').width() > $('#nav_cat_context_vp').width()) {
        $('#nav_cat_context_list').parallax({
            mouseport: $('#nav_cat_context_vp').css({ 'overflow': 'hidden' }),
            //width:($('#nav_cat_context_list').width()-$('#nav_cat_context_vp').width()), // This does NOT change the css, only jParallax's idea of how big a layer is
            //height:0,
            xparallax: '112%', // boolean | 0-1 | 'n%' | 'npx'
            yparallax: false,
            xorigin: 'left', // 0-1 | 'n%' | 'left', 'center', 'middle', 'right'
            yorigin: 1,
            freezeClass: 'freeze', // Class set on a layer when it is frozen
            decay: 0.8, // Sets the rate at which the layers 'catch up' with the mouse position. 0 is instantly, 1 is forever
            frameDuration: 30 // Length of milliseconds between animation frames
        });
    }
    if (v_anim_safe == true) {
        $('#nav_cat_context_list a').bind('mouseenter', function () {
            $('#nav_cat_context_list a').stop(false, false).fadeTo(250, 1).not($(this)).stop(false, false).fadeTo(250, 0.5);
        });
        $('#nav_cat_context_list').bind('mouseleave', function () {
            $('#nav_cat_context_list a').stop(false, false).fadeTo(250, 1);
        });
    }

    isIphone = (/iphone/gi).test(navigator.appVersion);
    isIpad = (/ipad/gi).test(navigator.appVersion);
    isAndroid = (/android/gi).test(navigator.appVersion);
    isTouch = isIphone || isIpad || isAndroid;

    if (isTouch == true) {

        // Categories
        var v_cat_lst_w_max = $('#productrange_list').width();
        var v_cat_lst_vp_w = $('#productrange_vp').css('overflow', 'hidden').width();
        var v_cat_lst_x_min = v_cat_lst_vp_w - v_cat_lst_w_max; // Negative Number
        var v_cat_lst_x_max = 0;

        $('#productrange_left').css({ 'cursor': 'pointer' }).bind('touchstart', function () {
            $('#productrange_list').animate({ 'left': v_cat_lst_x_max + 'px' }, 2000);
        }).bind('touchend', function () {
            $('#productrange_list').stop();
        });
        $('#productrange_right').css({ 'cursor': 'pointer' }).bind('touchstart', function () {
            $('#productrange_list').animate({ 'left': v_cat_lst_x_min + 'px' }, 2000);
        }).bind('touchend', function () {
            $('#productrange_list').stop();
        });

        // Products
        var v_prd_lst_w_max = (($('#products_list_bgrnd').width() > $('#products_list').width()) ? $('#products_list_bgrnd').width() : $('#products_list').width());
        var v_prd_lst_vp_w = $('#products_vp').width();
        var v_prd_lst_x_min = v_prd_lst_vp_w - v_prd_lst_w_max; // Negative Number
        var v_prd_lst_x_max = 0;
        $('#content .container')
		.append(
			$('<div/>', { 'id': 'productlist_left' }).css({ 'cursor': 'pointer' }).bind('touchstart', function () {
			    $('#products_list,#products_list_bgrnd').animate({ 'left': v_prd_lst_x_max + 'px' }, 2000);
			}).bind('touchend', function () {
			    $('#products_list,#products_list_bgrnd').stop();
			})
		)
		.append(
			$('<div/>', { 'id': 'productlist_right' }).css({ 'cursor': 'pointer' }).bind('touchstart', function () {
			    $('#products_list,#products_list_bgrnd').animate({ 'left': v_prd_lst_x_min + 'px' }, 2000);
			}).bind('touchend', function () {
			    $('#products_list,#products_list_bgrnd').stop();
			})
		);

    } else {

        $.getScript('http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4c612b5070ddefeb', function () {
            // Add This Links
        });

        // Categories
        $('#productrange_list').parallax({
            mouseport: $('#productrange_vp').css({ 'overflow': 'hidden' }),
            //width:($('#productrange_list').width()-$('#productrange_vp').width()), // This does NOT change the css, only jParallax's idea of how big a layer is
            //height:0,
            xparallax: true, // boolean | 0-1 | 'n%' | 'npx'
            yparallax: false,
            xorigin: 'center', // 0-1 | 'n%' | 'left', 'center', 'middle', 'right'
            yorigin: 1,
            freezeClass: 'freeze', // Class set on a layer when it is frozen
            decay: 0.8, // Sets the rate at which the layers 'catch up' with the mouse position. 0 is instantly, 1 is forever
            frameDuration: 30 // Length of milliseconds between animation frames
        });
        $('#productrange_list a').bind('mouseenter', function () {
            $('#productrange_list a').stop(false, false).fadeTo(250, 1).not($(this)).stop(false, false).fadeTo(250, 0.5);
        });
        $('#productrange_list').bind('mouseleave', function () {
            $('#productrange_list a').stop(false, false).fadeTo(250, 1);
        });

        // Products
        if ($('#products_list').width() > $('#products_vp').width()) {
            $('#products_list,#products_list_bgrnd,#products_landscape').parallax({
                mouseport: $('#products_vp').css({ 'overflow': 'hidden' }),
                //width:($('#nav_cat_context_list').width()-$('#nav_cat_context_vp').width()), // This does NOT change the css, only jParallax's idea of how big a layer is
                //height:0,
                xparallax: '100%', // boolean | 0-1 | 'n%' | 'npx'
                yparallax: false,
                xorigin: 'center', // 0-1 | 'n%' | 'left', 'center', 'middle', 'right'
                yorigin: 1,
                freezeClass: 'freeze', // Class set on a layer when it is frozen
                decay: 0.95, // Sets the rate at which the layers 'catch up' with the mouse position. 0 is instantly, 1 is forever
                frameDuration: 30 // Length of milliseconds between animation frames
            });
        }

    }

    $('#products_list article, #products_list_bgrnd article, #products_single article').css({ 'cursor': 'pointer' }).click(function () {
        location.href = $(this).find('a').attr('href');
    });

    $('#nav_main li').bind('mouseenter', function () {
        $(this).children('ul').slideDown('fast');
    });
    $('#nav_main li').bind('mouseleave', function () {
        $(this).find('ul').slideUp('fast');
    });


    // Header Menu Interaction Code - Based on Click action

    $('#nav_sub > nav > ul > li > ul').each(function () {
        var this_ul = $(this);
        var this_ul_w_orig = this_ul.width();
        var toggle = 1;
        this_ul.css({ 'width': 1 + 'px', 'opacity': 0 }).parent().click(function () {

            if (toggle) {
                this_ul.stop().animate({ 'width': this_ul_w_orig + 'px', 'opacity': 1 }, 500); // Menu expanding speed
                if (v_anim_safe == false) {
                    this_ul.children('li').show();
                }
            }
            else {
                this_ul.stop().animate({ 'width': 1 + 'px', 'opacity': 0 }, 200);  // Menu collapsing speed
                if (v_anim_safe == false) {
                    this_ul.children('li').hide();
                }
            }
            toggle = !toggle;
        
        });
        if (v_anim_safe == false) {
            this_ul.children('li').hide();
        }
    });


    /* Original Code - using hover for opening / closing animation

    $('#nav_sub > nav > ul > li > ul').each(function () {
    var this_ul = $(this);
    var this_ul_w_orig = this_ul.width();
    this_ul.css({ 'width': 1 + 'px', 'opacity': 0 }).parent().hover(function () {
    this_ul.stop().animate({ 'width': this_ul_w_orig + 'px', 'opacity': 1 }, 500); // Menu expanding speed
    if (v_anim_safe == false) {
    this_ul.children('li').show();
    }
    }, function () {
    this_ul.stop().animate({ 'width': 1 + 'px', 'opacity': 0 }, 200);  // Menu collapsing speed
    if (v_anim_safe == false) {
    this_ul.children('li').hide();
    }
    });
    if (v_anim_safe == false) {
    this_ul.children('li').hide();
    }
    });

    */

    $('#video_manual_link, #video_manual_link2').click(function () {
        $('body').append(
			$('<div/>', { 'id': 'video_curtain' }).css({
			    'position': 'absolute',
			    'top': '0px',
			    'left': '0px',
			    'width': '100%',
			    'height': '100%',
			    'background': 'black',
			    'z-index': '1000'
			})
			.hide()
			.delay(1)
			.fadeTo(500, 0.75)
		).append(
			$('<div/>', { 'id': 'video_container' }).css({
			    'position': 'absolute',
			    'top': (($(window).height() / 2) - (360 / 2)) + 'px',
			    'left': (($(window).width() / 2) - (640 / 2)) + 'px',
			    'width': '640',
			    'height': '360',
			    'z-index': '1001'
			})
			.hide()
			.delay(1)
			.fadeTo(500, 1)
			.append($('<div/>', { 'id': 'video_frame' }))
		).append(
			$('<a/>', { 'id': 'video_close' }).css({
			    'position': 'absolute',
			    'top': (($(window).height() / 2) - (360 / 2) - 25) + 'px',
			    'right': (($(window).width() / 2) - (640 / 2) + 2) + 'px',
			    'width': '100',
			    'height': '20',
			    'background': 'black',
			    'font-size': '10px',
			    'font-weight': 'bold',
			    'cursor': 'pointer',
			    'z-index': '1002'
			}).click(function () {
			    $('#video_curtain,#video_container,#video_container,#video_close').fadeTo(500, 0, function () { $(this).remove(); });
			})
			.hide()
			.delay(1)
			.fadeTo(500, 1)
			.append('CLOSE')
		);
        f_swfobject_mcmp("video_frame", 640, 360, {
            fpFileURL: $(this).attr('href'),
            fpAction: 'play',
            defaultEndAction: 'pauseAtStart',
            fpButtonOpacity: '0',
            cpSize: '640x24',
            cpCounterPosition: '450x340',
            cpPlayBtnColor: 'CCCCCC',
            cpStopBtnColor: 'CCCCCC',
            cpScrubberColor: 'CCCCCC'
        });
        return false;
    });

    // Scroll Bars
    $('#online_stockists_results, #find_stockist_results').jScrollPane({ scrollbarWidth: 20, scrollbarMargin: 0, showArrows: false, dragMinHeight: 20, dragMaxHeight: 20, topCapHeight: 7, bottomCapHeight: 2 });

    // Styled Drop Downs
    $('#find_stockist_country, #find_stockist_radius, #ctl00_ctl00_content_v_f_enq_typ, #ctl00_ctl00_content_v_f_cntry, #ctl00_ctl00_content_v_f_dte_pur').selectbox();

    $('#download_manuals_content .prd > ul').hide().parent().children('h2').click(function () {
        var e = $(this).parent();
        if (e.children('h2').children('span').hasClass('close')) {
            e.children('ul').show();
            e.children('h2').children('span').removeClass('close').addClass('open');
        } else {
            e.children('ul').hide();
            e.children('h2').children('span').removeClass('open').addClass('close');
        }
    }).css({ 'cursor': 'pointer' }).children('span').removeClass('open').addClass('close');

    $('#download_manuals_content .prd:first h2').click();

    $('#presentation_container').cycle({
        //fx: 'scrollLeft',
        fx: 'fade',
        timeout: 6000,
        pager: '#presentation_container_nav',
        fastOnEvent: true
    });

});
