$(document).ready(function(){
		
	//Opens the Side Menu
	side_menu();


	$("a.myPopup").open({
		width: 600,
		height: 200,
		scrollbars: false
	});
	
	$(".lightbox").fancybox({
		'autoScale'			: true,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'overlayOpacity'	:	0.6,
		'overlayColor'		:	'#000',
		'titleShow'			: false
	});
	$(".lightbox_form").fancybox({
		'width'				: 640,
		'height'			: '75%',
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'overlayOpacity'	:	0.6,
		'overlayColor'		:	'#000',
		'titleShow'			: false,
		'type'				: 'iframe'
	});


}); //End document.ready

// Debug Console
var debugging = true; // or true
if (typeof console == "undefined") var console = { log: function() {} };
else if (!debugging || typeof console.log == "undefined") console.log = function() {};


// Functions


// Open
(function ($) {

    $.open = {};

    // Default popup window parameters
    $.open.defaultParams = {
        "width":       "800",   // Window width
        "height":      "300",   // Window height
        "top":         "50",     // Y offset (in pixels) from top of screen
        "left":        "50",     // X offset (in pixels) from left side of screen
        "directories": "no",    // Show directories/Links bar?
        "location":    "no",    // Show location/address bar?
        "resizeable":  "yes",   // Make the window resizable?
        "menubar":     "no",    // Show the menu bar?
        "toolbar":     "no",    // Show the tool (Back button etc.) bar?
        "scrollbars":  "yes",   // Show scrollbars?
        "status":      "no"     // Show the status bar?
    };


    // Some configuration properties
    $.open.defaultConfig = {
        autoFocus: true
    };


    // Open popup window static function
    $.open.newWindow = function (href, params, config) {

        // Popup window defaults (don't leave it to the browser)
        var windowParams = $.extend($.open.defaultParams, params);

        // Configuration properties
        var windowConfig = $.extend($.open.defaultConfig, config);

        var windowName = params["windowName"] || "new_window";

        var i, paramString = "";

        for (i in windowParams) {
            if (windowParams.hasOwnProperty(i)) {
                paramString += (paramString === "") ? "" : ",";
                paramString += i + "=";

                // Allow true/false instead of yes/no in params
                if (windowParams[i] === true || windowParams[i] === false) {
                    paramString += (windowParams[i]) ? "yes" : "no";
                }
                else {
                    paramString += windowParams[i];
                }
            }
        }

        var popupWindow = window.open(href, windowName, paramString);

        if (windowConfig.autoFocus) {
            popupWindow.focus();
        }

        return popupWindow;
    };


    // Plugin method: $("...").popup()
    $.fn.open = function (parameters, callback) {

        var params = parameters.params || parameters;
        var config = parameters.config || {};

        // Loop over all matching elements
        this.each(function (){

            // Add an onClick behavior to this element
            $(this).click(function (event) {

                // Prevent the browser's default onClick handler
                event.preventDefault();

                // Use the target attribute as the window name
                if ($(this).attr("target")) {
                    params.windowName = $(this).attr("target");
                }

                // Determine the url to open
                //   Use param.href over element's href
                var href;
                if (params.href) {
                    href = params.href;
                }
                else if ($(this).attr("href")) {
                    href = $(this).attr("href");
                }
                else {
                    return;  // Can't openWindow anything, so stop here
                }

                
                // Pop up the window
                var windowObject = $.open.newWindow(href, params, config);

                if (callback) {
                    callback(windowObject);
                }
            });
        });

        return $;
    };

})(jQuery);
// End Open //

// jquery cookie //
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
// End jquery cookie //



// Side Menu
function side_menu() {
	//$("#main #side_menu ul").children("li").hide();
	
	$("#side_menu .open").show();
	$("#side_menu .open").parents("ul").show();
	//$("#side_menu .open").parents("li").show();
	//$("#side_menu .open").parent("ul").parent("li").siblings("li").show();
	//$("#side_menu .open").siblings("li").show();

	$("#side_menu .open").children("ul").show();
	$("#side_menu .open ul").children("li").show();
}

// Menu Open
function menu_open() {
	$("#side_menu li span.no_page").click( function () {
		$(this).attr("class", "no_page-open");
		$(this).parent("li").children("ul").show();
		$(this).parent("li").children("li").show();
	});
	$("#side_menu li span.no_page-open").click( function () {
		$(this).attr("class", "no_page");
		$(this).parent("li").children("ul").hide();
		$(this).parent("li").children("li").hide();
		//menu_open();
	});
}
