﻿

var menu = new menu.dd('menu');
menu.init('menu', 'menuhover');


$(function() {

    // search form submit on enter 
    $('form[id=search-form]').submit(function(e) {
        if ($(':text', this).val().length === 0) {
            e.preventDefault();
        }
    });

    $('a[rel=external]').click(function() {
        $(this).attr('target', '_blank');
    });

    // push any popup windows to bottom of body
    $('.hidden_popup').appendTo($('body'));

    // share this
    var IE6 = $('html').hasClass('ie6');
    if (!IE6) {
        $('.share .link a').sharePopup({
            target: '#sharing',
            oofsetX: -20
        });

        $('.share .link ').show();
    }

    $('#sharing a').click(function(e) {

        e.preventDefault();

        var target = $(this).attr('href');
        $.fn.colorbox({
            width: '572px',
            inline: true,
            href: '#leaving_notice_share',
            opacity: '0.6',
            transition: 'none',
            onComplete: function() {
                $('#colorbox').removeClass().addClass('normal');
                $('#leaving_notice_share a#continue').attr('href', target);
            }
        });
    });

    $('#leaving_notice_share a#cancel').click(function(e) {
        $.fn.colorbox.close();
        e.preventDefault();
    });

    $('#leaving_notice_share a#continue').click(function(e) {
        $.fn.colorbox.close();
    });

    // give forms some HTML5 love
    if (Modernizr.inputtypes.email) {
        $('form :text#email').each(function() {
            this.setAttribute('type', 'email');
        });
    }
    if (Modernizr.inputtypes.search) {
        $('form :text#searchParameter').each(function() {
            this.setAttribute('type', 'search');
        });
    }
});

// video player
function playerSwfLoadEvent(e) {
    if (e.success === false) {
        $('.calpol_products_container .cnt_repeat_tv').hide();
    }
}

function loadVideo(pathToPlayer, pathToVideo) {

    if (swfobject) {

        var params = {
            bgcolor: '#ffffff',
            scale: 'noscale',
            wmode: 'transparent',
            quality: 'high',
            allowFullScreen: 'true'
        };
        var flashVars = {
            videoUrl: pathToVideo
        };
        swfobject.embedSWF(pathToPlayer, 'modal_window_product_detail_inner', '580', '401', '9.0.0', '', flashVars, params, null, playerSwfLoadEvent);

        $('.video_player').colorbox({
            width: '640px',
            inline: true,
            href: '#video_player',
            close: '',
            onComplete: function() {
                $('#colorbox').removeClass().addClass('video');

                if (_gaq) {
                    _gaq.push(['_trackPageview', 'watch-the-tv-ad'])
                }
            }
        });
    }
}

function CloseFlashVideoPlayer() {
    $.fn.colorbox.close();
}
