var MENU_COOKIE_NAME = 'is_menu_open';
var MENU_INSIDE_WIDTH = 250;
var NEWS_MENU_COOKIE_NAME = 'news_menu';
var NEWS_MENU_WIDTH = 212;
var news_timeout_id;
$(document).ready(function(){
  $("ul.top_nav li").hover(function() {
        $(this).find("ul.sub-menu").slideDown('fast').show(); //Drop down the subnav on click

        }, function(){  //On Hover Out
			$(this).find("ul.sub-menu").slideUp('fast');

    });
  $("#searchMenu li").hover(function() { 
        $(this).toggleClass('searFiltersHover');

        }, function(){  //On Hover Out
        $(this).toggleClass('searFiltersHover');

    });
  //$("#news_slider_wrapper").css({width:44});
  $("#news_slide_handle").click(function() {  
		if($("#news_slider_content_wrapper").width() <100){
			 $("#news_slider_content_wrapper").animate({width:212,marginLeft:0}, "medium");
		}
		else{
			$("#news_slider_content_wrapper").animate({width:1,marginLeft:0}, "medium",function(){$(this).css('display','none')});
		}
    });
  $("#menuinside_slide_handle").click(function() {  
		if($("#menuinside_slider_content_wrapper").width() <100){
			 $("#menuinside_slider_content_wrapper").animate({width:MENU_INSIDE_WIDTH}, "medium");
			 /*
			var date = new Date();
			date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
			$.cookie(MENU_COOKIE_NAME, true, { path: '/', expires: date });*/
		}
		else{
			$("#menuinside_slider_content_wrapper").animate({width:0}, "medium",function(){$(this).css('display','none')});
			/*
			var date = new Date();
			date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
			$.cookie(MENU_COOKIE_NAME, false, { path: '/', expires: date });*/
		}
    });	
  $("#educopy_slide_handle").click(function() {  
		if($("#educopy_slider_content_wrapper").width() <100){
			 $("#educopy_slider_content_wrapper").animate({width:MENU_INSIDE_WIDTH}, "medium");
			 $("#educopy_slide_handle").removeClass("show");
		}
		else{
			$("#educopy_slider_content_wrapper").animate({width:0}, "medium",function(){$(this).css('display','none')});
			$("#educopy_slide_handle").addClass("show");
		}
    });	
  $("#login_slide_handle").click(function() {  
		if($("#login_slider_content_wrapper").width() <100){
			$('#login_slider_wrapper').css('width', '244px');
			 $("#login_slider_content_wrapper").animate({width:200}, "medium");
		}
		else{
			$("#login_slider_content_wrapper").animate({width:0}, "medium",function(){$(this).css('display','none');$('#login_slider_wrapper').css('width', '44px')});
		}
    });

});
// when the document loads
$(window).load(function(){
	if($('#menuinside_slider_wrapper').length > 0){ 
		//alert($.cookie(NEWS_MENU_COOKIE_NAME));
		if($.cookie(NEWS_MENU_COOKIE_NAME)==null){
			/*var date = new Date();
			date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
			$.cookie(MENU_COOKIE_NAME, true, { path: '/', expires: date });
			$("#menuinside_slider_content_wrapper").css({width:MENU_INSIDE_WIDTH});*/
		  $("#menuinside_slide_handle").click(function() {  
					var date = new Date();
					date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
					$.cookie(NEWS_MENU_COOKIE_NAME, true, { path: '/', expires: date }); 
			});
			news_timeout_id = setTimeout('hideMenuSlider()',2000);
			$("#menuinside_slider_content_wrapper").css({width:MENU_INSIDE_WIDTH}); 
		}else if($.cookie(NEWS_MENU_COOKIE_NAME) == 'true'){  
		//if the cookie is set to true, open the slider
			//$("#menuinside_slider_content_wrapper").css({width:MENU_INSIDE_WIDTH});
		}
	}
	if($('#educopy_slider_wrapper').length > 0){ 
		$("#educopy_slider_content_wrapper").animate({width:MENU_INSIDE_WIDTH}, "medium");
		$("#educopy_slide_handle").removeClass("show");
	}
	if($('#news_slider_content_wrapper').length > 0){ 
	//	alert($.cookie(NEWS_MENU_COOKIE_NAME));
		if($.cookie(NEWS_MENU_COOKIE_NAME)==null){
		  $("#news_slide_handle").click(function() {  
					var date = new Date();
					date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
					$.cookie(NEWS_MENU_COOKIE_NAME, true, { path: '/', expires: date });
			});
		news_timeout_id = setTimeout('hideNewsSlider()',2000);
		$("#news_slider_content_wrapper").css({width:NEWS_MENU_WIDTH}); 
		
		}else if($.cookie(NEWS_MENU_COOKIE_NAME) == 'true'){  
		//if the cookie is set to true, open the slider
		}
	}
});
function hideNewsSlider(){
	$("#news_slider_content_wrapper").animate({width:1,marginLeft:0}, "medium",function(){$(this).css('display','none')});
}
function hideMenuSlider(){
	$("#menuinside_slider_content_wrapper").animate({width:0}, "medium",function(){$(this).css('display','none')});
}
function hideEducopylider(){
	$("#educopy_slider_content_wrapper").animate({width:0}, "medium",function(){$(this).css('display','none')});
}
 /**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
 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;
    }
};
