$(document).ready(function(){

	$(".slider-button").click(function(e){e.preventDefault();});	
 
	
	var wrapper = $("#slider-wrapper"),
	 	s=$("#slider");
		sc=$("#slider-container"),
	 	scl=$("#slider-collapse"),
	 
		se=$("#slider-expand"),
		bg=$("#slider-bg"),
		height = wrapper.height();
 
	
 
	sWidth = sc.width();

	
	bg.css({
		width:0,
		height:height,
		left:"100%",
		"margin-top":-height/2
	}).add(wrapper).hide();
	
	sc.css({left:"100%"});
 
 
	
	function collapse()
	{		
			var height =  s.height();
		 
			sc.stop(true).animate({
							left:$(window).width()
						 
						},
						
						{ 	
							duration:800,
						 
							complete:function()
							{	 
									
									
									bg.stop(true).animate({
							 
													left:$(window).width(),
													height:0,
													"margin-top":-s.height()/2
										  
												 
												 
												},
												{
												 
													duration:1200,
													complete:function(){
														$(this).add(sc).hide();
														se.stop(true).show().animate({"margin-left":-75});
														
													}
												
												})
							}
						})
	}
	
	function expand()
	{
	
	 
		se.stop(true).animate({"margin-left":0},se.hide);
		wrapper.show();
		var width = $(window).width();
		 
		sc.width(sWidth);
		
		bg.css({left:width}).stop(true).show().animate({"margin-top":-height ,left:0,width:width,height:height},{duration:500,complete:function(){
				
				sc.show().stop(true).css({left:width})
				 
				.animate({left:0},{duration:300 });
				 
		
		}})
							 
						
						
						
	
	}
	scl.click(collapse);
	se.click(expand);
	document.documentElement
  $(window).bind("resize scroll",glue).resize();
 
 
	function glue(){
	 
	bg.add(s).width("100%");
 
 
 
		
	};
	//ie + doctype 4.01 = brak onresize na window
	if(document.all)
		setInterval(glue,500);
 
  setTimeout(function(){
	se.css({ "margin-left":-75})
	 
	},200);
 
 
});
