$(document).ready(function(){
        jQuery(".trigger").click(function(){
                $(".panel").toggle("fast");
                $(".panel").load("motwsmall.php");
                $(this).toggleClass("active");
                return false;
        });
        //$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav

        $("ul.topnav li a").hover(function() { //When trigger is clicked...

                //Following events are applied to the subnav itself (moving subnav up and down)
                $(this).parent().find("ul.subnav").stop(true, true).delay(500).slideDown('fast').show(); //Drop down the subnav on click

                $(this).parent().hover(function() {
                }, function(){
                        $(this).parent().find("ul.subnav").stop(true, true).slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
                });

                //Following events are applied to the trigger (Hover events for the trigger)
                }).hover(function() {
                        $(this).addClass("subhover"); //On hover over, add class "subhover"
                }, function(){  //On Hover Out
                        $(this).removeClass("subhover"); //On hover out, remove class "subhover"
        });

        var initialState = "expanded";
        if($.cookie("panelState") == undefined) {
                        $.cookie("panelState",initialState);
        }


	var state = $.cookie("panelState");
        if(state == "collapsed") {
                $("#toolbar").hide();
                $("#toolbarbut").show();
		$("#toolbartop").hide();
                $("#toolbarbuttop").show();

        }

        //hide toolbar and make visible the 'show' button
        $("span.downarr a").click(function() {
                $("#toolbar").slideToggle("fast");
                $("#toolbarbut").fadeIn("slow");
		$("#toolbartop").slideToggle("fast");
                $("#toolbarbuttop").fadeIn("slow");
                $.cookie("panelState","collapsed");
        });

        //show toolbar and hide the 'show' button
        $("span.showbar a").click(function() {
                $("#toolbar").slideToggle("fast");
                $("#toolbarbut").fadeOut();
		 $("#toolbartop").slideToggle("fast");
                $("#toolbarbuttop").fadeOut();
                $.cookie("panelState","expanded");
        });

	$("input[type=text], input[type=password],input[type=file] ,textarea, select").each(function () {
                $(this).addClass("blur");
                $(this).focus(function () {
                    $(this).removeClass("blur").addClass("focus");
                });
                $(this).blur(function () {
                    $(this).removeClass("focus").addClass("blur");
                });
            });
	
});

var showmessages =function(t,wtitle,wtext ){
                        if (t=='M') {img='pic/pmunread.png';}
                        else if (t=='W') {img='pic/warning-icon.png';}
                        else if (t=='S') {img='pic/reseed.png';}
                        else if (t=='D') {img='pic/donations.png';}
                        else if (t=='R') {img='pic/reports.png';}
                        else if (t=='A') {img='pic/important.png';}
                        if (t=='S' || t=='D') {
			var initialStateM = "Open";
        		if($.cookie(t+"State") == undefined) {
                        	$.cookie(t+"State",initialStateM);
        		}
			 var stateM = $.cookie(t+"State");
			} else stateM ="Open";
        		if(stateM == "Open") {
			
                        var unique_id = $.gritter.add({
                                // (string | mandatory) the heading of the notification
                                title: wtitle ,
                                // (string | mandatory) the text inside the notification
                                text: wtext,
                                // (string | optional) the image to display on the left
                                image: img,

                                // (bool | optional) if you want it to fade out on its own or just sit there
                                sticky: true,
                                // (int | optional) the time you want it to be alive for before fading out
                                time: '',
                                // (string | optional) the class name you want to apply to that specific message
                                class_name: 'my-sticky-class',
				after_close: function(e, manual_close){
                    			if (manual_close) {
						 if (t=='D') {
						$.cookie(t+"State","Closed",{ expires: 1 });}
						 if (t=='S') {
                                                $.cookie(t+"State","Closed",{ expires: 7 });}
					}
				}
                        });
			// You can have it return a unique id, this can be used to manually remove it later using
                        /*
                        setTimeout(function(){

                                $.gritter.remove(unique_id, {
                                        fade: true,
                                        speed: 'slow'
                                });

                        }, 6000)
                        */
			}
                        return false;

                };


