﻿
MAK = function() {

    /* Private */

    /* Properties */

    var cmp = {};

    var aboutMenuShown = false;



    /* Methods */

    var init = function() {

        /* Constructor */

        // Watermark for the newsletter signup
        $('#newsletterSignupForm-email-control').focus(function() {
            if ($(this).val() == 'Enter Email Address') {
                $(this).val('');
            }
        });
        $('#newsletterSignupForm-email-control').blur(function() {
            if ($(this).val() == '') {
                $(this).val('Enter Email Address');
            }
        });

        // Reset the newsletter signup form
        TVI.event('#newsletterSignupForm .thankYou A', 'click', function() {
            $('#newsletterSignupForm .thankYou').hide();
        });


        // Open and close the search panel
        TVI.event('#searchPanelClosed', 'click', function() {
            $('#searchPanelClosed').hide();
            $('#searchPanelClose').show();
            $('#searchPanelOpen').slideDown(200);
        });

        TVI.event('#searchPanelClose', 'click', function() {
            $('#searchPanelOpen').slideUp(200, function() {
                $('#searchPanelClose').hide();
                $('#searchPanelClosed').show();
            });
        });

        // Left hand menu hover action
        TVI.event('.menuBox LI', 'mouseover', function() {
            $(this).css({ 'background': '#E9E9DA' });
        });
        TVI.event('.menuBox LI', 'mouseout', function() {
            $(this).css({ 'background': '#F2F2EA' });
        });

        // Remove dotted line from bottom menu items
        $('.menuBox UL LI:last-child A').css({ 'border-bottom': 'none' });


        // Show About menu on hover
        $('#topMenu .about').mouseenter(function() {
            $('#topMenu .about .layer').show();
            $('#topMenu .about').addClass('selected');
        });
        $('#topMenu .about').mouseleave(function() {
            $('#topMenu .about .layer').hide();
            $('#topMenu .about').removeClass('selected');
        });


        // Create newsletter signup form
        MAK.newsletterSignupForm = new TVI.Form({
            ID: 'newsletterSignupForm',
            buttons: [{

                selector: '#newsletterSignupButton A',
                enter: true,
                handler: function() {

                    // Check to make sure it's not empty or default
                    var emailField = MAK.newsletterSignupForm.field('email');
                    
                    if (emailField.val() === '' || emailField.val() === 'Enter Email Address') { return; }

                    // Submit the form
                    MAK.newsletterSignupForm.submit({

                        query: 'addNewsletterEmail',
                        success: function() {
                        
                            emailField.val('Enter Email Address');
                            
                            MAK.newsletterSignupForm.el.find('.thankYou').show();
                            
                        }

                    });

                }


            }]

        });

        // Newsletter signup thankyou message
        TVI.event('#newsletterSignup A', 'click', function() {
            $('#newsletterSignup .thankYou').hide();
        });


        //search form
        MAK.masterSearchForm = new TVI.Form({
        
            ID: 'masterSearchForm',
            buttons: [{
            
                selector: '#searchPanelSubmit A',
                enter: true,
                handler: function(){
                
                    cmp.masterSearchForm.redirect({
                    
                        url: 'Category.aspx?search=true',
                        empty: true
                    
                    });
                
                }
            
            }]
        
        });
                
        // Fill the form from the querystring
        var args = TVI.Request.QueryString;
        
        //pound signs are corrupted in IE so get from .net
        TVI.apply(args, {
           priceRange : MAK.priceRange
        });
        
        MAK.masterSearchForm.val(args);

    };
    
    
    
    
    
    var writeMedia = function(id, file, width, height){
    
        /* Wimpy Media Player */
    
        writeWasp({
            r: 'MVhUZiUyRm40TSUyMSU3RDl0JTdGVSUyOVIzUXg2JTNFeSU3RlIlNjBlN05HN1FwLjUlM0VO', //makinorgans.co.uk
            instanceID: id,
            waspSwf: 'i/wasp.swf',
            pageColor: 'F2F2EA',
            f: file,
            s: '0',
            pw: width,
            ph: height || undefined,
            waspSkin: 'sr_1|1^st_1|1|16||000000^sg_1|1^sb_1|4|26|F8F8F8||B8B8B8^sp_1|11|24|3D3D8F|FFFFFF|69DAFF^sm_1|11|24|3D3D8F|FFFFFF|69DAFF^sa_1|1|5^sz_1|1|5'
        });
    
    };





    /* Public */

    TVI.apply(cmp, {

        /* Properties */

        /* Methods */

        writeMedia: function(id, file, width, height) {
        
            writeMedia(id, file, width, height);            

        }

    });


    TVI.ready(init);


    return cmp;


} ();