﻿window.LANE = window.LANE = {};

(function () {
    var Lane = {

        /**
        * manages standard lightbox forms
        */
        lbForm: {
            launch: function (url, params) {

                // manipulate url for full page v. ajax response
                url = url.replace(/format=nojs/, "format=ajax");

                $.openDOMWindow($.extend({
                    borderSize: '0',
                    windowBGColor: '#f8f8f8',
                    width: 496,
                    windowSource: 'ajax',
                    windowSourceURL: url,
                    functionCallOnOpen: Lane.lbForm.handleForm
                }, params));
            },
            handleForm: function () {
                // hijack form inside response

                $("#DOMWindow form").bind("submit", function (e) {

                    // manipulate url for full page v. ajax response
                    var formUrl = $(this).attr("action").replace(/format=nojs/, "format=ajax");


                    if ("post" == $(this).attr("method").toLowerCase()) {
                        $.post(formUrl, $(this).serializeArray(), function (data) {
                            $("#DOMWindow").html(data);
                            Lane.lbForm.handleForm();
                        }, "html");
                    } else {
                        // make get request
                        $.get(formUrl, $(this).serializeArray(), function (data) {
                            $("#DOMWindow").html(data);
                            Lane.lbForm.handleForm();
                        }, "html");
                    }
                    e.preventDefault();
                });
                $("#DOMWindow a.closeDOMWindow").bind("click", function (e) {
                    $.closeDOMWindow();
                    e.preventDefault();
                });
            }
        },


        /**
        * Opens links in New Window
        */
        newWin: function () {
            $("a.newWin").bind("click", function (e) {
                window.open(this.href);
                e.preventDefault();
            });
        },

        /**
        * manages email list lightbox
        */
        emailList: function () {
            $("a.emailList").bind("click", function (e) {
                Lane.lbForm.launch(this.href, { height: '210' });
                e.preventDefault();
            });
        },

        officialRules: function () {
            $('a.officialRules').bind("click", function (e) {
                LANE.lbForm.launch(this.href, { width: '600', height: '465' });
                e.preventDefault();
            });
        },
       
        sendToFriend: function () {
            $('a.sendToFriend').bind("click",function(e) {
		        LANE.lbForm.launch(this.href,{width: '700', height: '700'});
		        e.preventDefault();
            });
        },

        choicesEprevue: function () {
            $('a.choicesEprevue').bind("click", function (e) {
                LANE.lbForm.launch(this.href, { width: '850', height: '610' });
                e.preventDefault();
            });
        },
        choicesDining: function () {
            $('a.choicesDining').bind("click", function (e) {
                LANE.lbForm.launch(this.href, { width: '950', height: '640' });
                e.preventDefault();
            });
        },

        viewLarger: function () {
            $('a.viewLarger').bind("click", function(e) {
                LANE.lbForm.launch(this.href, { width: '1000', height: '605' });
                e.preventDefault();
            });
        },

        viewZeroGravity: function () {
            $('a.viewZeroGravity').bind("click", function(e) {
                LANE.lbForm.launch(this.href, { width: '642', height: '418', overflow: 'hidden' });
                e.preventDefault();
            });
        },

        choicesConfigurator: function () {
            $('a.choicesConfigurator').bind("click", function (e) {
                LANE.lbForm.launch(this.href, { width: '848', height: '600', positionLeft: '0', positionTop: '0', positionType: 'absolute' });
                e.preventDefault();
            });
        },

        fabricVisualization: function () {
            $('a.fabricVisualization').bind("click",function(e) {
                LANE.lbForm.launch(this.href,{width: '870', height: '640', windowBGColor: '#fff'});
                e.preventDefault();
            });
       },

       fabricVisualization2: function () {
           $('a.fabricVisualization2').bind("click", function(e) {
                 LANE.lbForm.launch(this.href, { width: '840', height: '591', windowBGColor: '#fff' });
               e.preventDefault();
           });
        },

        winnersList: function () {
            $('a.winnersList').bind("click", function (e) {
                LANE.lbForm.launch(this.href, { width: '500', height: '200' });
                e.preventDefault();
            });
        },
        sectionals: function () {
            $('a.sectionals').bind("click", function (e) {
                LANE.lbForm.launch(this.href, { width: '880', height: '630' });
                e.preventDefault();
            });
        },
        /**
        * Initializes all global page interactions
        */
        _init: function () {
            this.newWin();
            this.emailList();
            this.sendToFriend();
            this.officialRules();
            this.choicesEprevue();
            this.choicesDining();
            this.choicesConfigurator();
            this.viewLarger();
            this.viewZeroGravity();
            this.winnersList();
            this.sectionals();
            this.fabricVisualization();
            this.fabricVisualization2();

        } // _init

    }; // Lane Namspace

    $(document).ready(function () {
        Lane._init();
    });

    window.LANE = Lane;

})();

