/**
 * Namespaced object. Encapsulating private methods, exposing these 
 * as public via an object proxy. 
 *
 * @author 		Zone
 * @email		info@zonecontent.com
 * @url 			http://www.zonecontent.com/
 * @copyright 	Copyright (c) 2009, zonecontent.com. All rights reserved.
 * @version		0.0.1
 */

var wemakestories = window.wemakestories = function($) {
    // Call init methods

    /*
    Dialog method application
    */
    function applyDialogControls() {



        var triggers = $("#popup-terms");

        triggers.each(function() {
            var trigger = $(this);

            //find where to append the dialog box
            var parent = trigger.parent();

            //find the actual box by its ID
            var dialog = $("#terms")

            //find the close buttons within it
            var close = dialog.find(".close");

            // Set parent to relative position to allow element relative absolute positioning
            parent.append(dialog);
            parent.css("position", "relative");
            dialog.addClass("active").hide();

            //what does this do?
            // msie_href.push(trigger, close);

            close.click(function() {
                dialog.fadeOut("slow");
                return (false);
            });

            trigger.click(function() {

                if (dialog.is(":hidden")) {
                    dialog.fadeIn("slow");
                } else {
                    dialog.fadeOut("slow");
                }
                return (false);
            });
        });

    }

    /*
    Stop paypal buttons clicking terms not accepted or country not specified
    */
    function stopPaypal() {

        var triggers = $(".paypal");

        triggers.each(function() {
            var trigger = $(this);

            //find the checkbox
            var check = $("#chkAgree")

            var dropdown = $(".country-select");

            trigger.click(function() {
                if (!check.is(":checked")) {
                    alert('Please accept our terms and conditions');
                    return false;

                }

                if (dropdown.val() == 0) {
                    alert('Please tell us where you are from');
                    return false;

                }
                
                
            });
        });

    }

    return {

        // Return public methods 	
        "initialize": function() {

            applyDialogControls();
            stopPaypal();
        }

    };

} (jQuery);