 $(document).ready(function() {
 
// CAROUSEL
	
    // Append shadow
	$("div#carousel div.box").css({width:"auto", marginLeft: "30px" /*, paddingLeft:"50px" */});
	$("div#carousel div.box div.carousel_content").css({display:"none"});
	$("div#carousel div.box div.carousel_content").first().css({display:"block", width:"200px"});
	$("div#carousel div.box div.carousel_image").css({display:"block"});
	
	$("div#carousel div.box div.carousel_image").each(function(i){
	 $image_width = $(this).find("img").width() + 10;
		$(this).css({display: "block", width: $image_width + "px"});
		$("span.promotion_book").each(function(i)
				{
				$image_width = $(this).parent().width();
				$(this).css({display: "block", width: $image_width + "px"});
				});
	});
	$("div#carousel div.box div.carousel_image").append('<img class="shadow" src="img/icons-shadow.png" height="27" alt="" />');
	
	 if ($.browser.msie == true)
     {
	        $("div#carousel div.box p.author, div#carousel div.box p.title").css({position: "relative", 'z-index': 20});
     }
 	
	// hover 
   $("div#carousel div.box").hover(function() {
    	var e = $(this).find("div.carousel_image");
    	var b = $(this);
    	var c =  $(this).find("div.carousel_content");
    	
        $(e).find("a").stop().animate({ marginTop: "-14px" }, 250, function() {
        	$(e).find("a").animate({ marginTop: "-10px" }, 250);
        });
        if ($.browser.msie == true)
        {
	        $(e).find("img.shadow").stop().animate({ width: "80%", height: "20px", marginTop:"12px", marginLeft: "10px"}, 250);
	        $("div#carousel div.box p.author, div#carousel div.box p.title").css({position: "relative", 'z-index': 20});
        } else
	        {
	        	 $(e).find("img.shadow").stop().animate({ width: "80%", height: "20px", marginTop:"12px", marginLeft: "10%", opacity: 0.5 }, 250);
	        }
    },function(){
    	var e = $(this).find("div.carousel_image");
    	var b = $(this);
    	var c =  $(this).find("div.carousel_content");
    	
    	// shadow
    	$(e).find("a").stop().animate({ marginTop: "4px" }, 250, function() {
        	$(e).find("a").animate({ marginTop: "0px" }, 250);
        });
        if ($.browser.msie == true)
        {
        	$(e).find("img.shadow").stop().animate({ width: "100%", height: "27px", marginTop:"0px", marginLeft: "0px"}, 250);
        } else
	        {
	        	$(e).find("img.shadow").stop().animate({ width: "100%", height: "27px", marginTop:"0px", marginLeft: "0px", opacity: 1 }, 250);
	        }  
    }); 
  
   // klikanie
   		$("div#carousel div.box div.carousel_image a").click(function(event)
       		{
       		event.preventDefault();
        	var e = $(this).parent(); // carousel image
        	var b = $(this).parent().parent();  // box
        	var c =  $(this).parent().parent().find("div.carousel_content");
			
        	if ($.browser.msie == true)
	        {
	    		$("div#carousel div.box p.author, div#carousel div.box p.title").hide().css({position: "static"});
	        };
        	$("div#carousel div.box").stop().animate({width:$("div#carousel div.box div.carousel_image").width()+"px"}, 500, function()
        			{	
        		$("div#carousel div.box div.carousel_content").hide();
		        // zwiekszam szerokosc wewnatrz funkcji aby sie pierwsza wykonala zanim zrobie fadeIn		
		        			$(b).stop().animate({width:$(e).find("img").width()+240+"px"}, 500, function()
		        					{
				        				if ($.browser.msie == true)
				        		        {
				        					$(c).css({width:"200px"}).show("slow");
				        					$("div#carousel div.box p.author, div#carousel div.box p.title").css({position: "relative", 'z-index': 20}).show();;
				        		        } else
					        		        {
			        				 			$(c).css({width:"200px"}).fadeIn("slow");
					        		        };
		        					});		
        			});
       		});
       
// REGULATIONS POP UP
    var box = 'div#regulation-popup';
    $('a#regulation-up').click(function(event)
	{
       event.preventDefault(); // zeby nie przejsc na strone z href
       $(box).fadeOut().hide();
	   $(box).fadeIn().one('click', function()
	   {
		   $(box).fadeOut();
	   }); 
				
	});
    
// AUTHORS RANDOM CLICK    
    $('li#footer-next-author a').click(function(event)
	{
      event.preventDefault(); // zeby nie przejsc na strone z href
    //  $('div#authors').load('/erica/author_reloads/info'); // wyrzucic folder erica, jesli na serwer
      $('div#authors').load('/author_reloads/info'); // wyrzucic folder erica, jesli na serwer
       return false;				
	});
    
// ORIGINAL PICTURE

    $('a#link-to-image').click(function(event)
    		{
    		event.preventDefault();
    		$("div#original-image").css({marginLeft: $(this).find("img").width()+"px"}).hide().fadeIn()
    		.one('click', function()
				{
				$(this).fadeOut();
				});
			$("span#original-image").click(function() // dodatkowe klikniecie na $image czyli chowanie
				{
				$("div#original-image").click();
				}) ;
    		});
 
// AUTHOR ROLLOVER
    $("div.author_rollover_info, div#authors-content div.other_books").css({display:"none"});
    $("div#authors-content strong.author_rollover a").click(function(event)
    		{
    			event.preventDefault();
    			$(this).parent().parent().find("div:first").slideToggle("slow", function()
    					{
    					$(this).parent().find("div.other_books").slideToggle("slow");
    					});
    		});
    
// LINKI W NOWYM OKNIE
    
    $('a.blank').attr('target', '_blank');
    
// End jQuery 
 
});
