$(document).ready(function() {

	//getCookie("hipp_popup");

	$('#contestPhotos').hide();

	$('#rollDown').click(function() {

		$('#contestPhotos').toggle(1000);
		return false;

	});
	
	$('a#closeTesco').click(function(){
	
		$('#tesco').fadeOut(1000, function(){
			
			$(this).hide();
			$(this).css('display', 'none');
		
		});
		
		
		return false;
	
	});
	
	
	
	var flag = 1;
	
	setInterval(function(){
	
		if (flag == 0){
			/*
			$('#bottom_box_1 img').fadeOut(1000, function(){
				$(this).hide();
				$(this).attr('src', '/fileadmin/template/img/home/box_konkurs.jpg');
				$(this).parent().attr('href', '/?id=14');
				$(this).fadeIn(1000);
			});
			
			$('#bottom_box_1 p').fadeOut(1000, function(){
				$(this).hide();
				$(this).html('<b>Konkursy!</b><br/>Zobacz nasze konkursy...<a class="link" href="?id=14">dalej</a>');
				$(this).fadeIn(1000);
			});
			*/
			
			$('#bottom_box_1 img').fadeOut(1000, function(){
				$(this).hide();
				$(this).attr('src', '/fileadmin/template/img/obiadki/baner.png');
				$(this).parent().attr('href', 'http://kraina.hipp.pl');
				$(this).fadeIn(1000);
			});
			
			$('#bottom_box_1 p').fadeOut(1000, function(){
				$(this).hide();
				$(this).html("Załóż drzewko w krainie HiPP!  <a class=\"link\" href=\"http://kraina.hipp.pl/\">dalej</a>");
				$(this).fadeIn(1000);
			});
			
            
                  
        
         
			
			$('#bottom_box_3 img').fadeOut(1000, function(){
				$(this).hide();
				$(this).attr('src', '/fileadmin/template/img/home/zawiera_omega3.jpg');
				$(this).parent().attr('href', '/?id=519');
				$(this).fadeIn(1000);
			});
			$('#bottom_box_3 p').fadeOut(1000, function(){
				$(this).hide();
				$(this).html('Spróbuj swoich sił i weź udział w konkursie!!<br/><a class="link" href="/?id=519">dalej</a>');
				$(this).fadeIn(1000);
			});
			
			$('#bottom_box_2 .box_content_2 img').fadeOut(1000, function(){
				$(this).hide();
				$(this).attr('src', '/fileadmin/template/img/home/hipp_sklep.jpg');
				$(this).fadeIn(1000);
			});
			
			
			flag = 1;
		}
		else if (flag == 1){
		
			/*
			$('#bottom_box_1 img').fadeOut(1000, function(){
				$(this).hide();
				$(this).attr('src', '/fileadmin/template/img/home/krhipp.gif');
				$(this).parent().attr('href', 'http://www.kraina.hipp.pl/');
				$(this).fadeIn(1000);
			});
			
			$('#bottom_box_1 p').fadeOut(1000, function(){
				$(this).hide();
				$(this).html('Załóż drzewko w krainie HiPP! <a class="link" href="http://www.kraina.hipp.pl/">dalej</a>');
				$(this).fadeIn(1000);
			});
			*/
            
			$('#bottom_box_1 img').fadeOut(1000, function(){
				$(this).hide();
				$(this).attr('src', '/dzien_dziecka/wakacje_z_hipp.jpg');
				$(this).attr('onClick', ' ');
				$(this).attr('onclick', ' ');
				$(this).parent().attr('href', 'http://hipp.pl/index.php?id=519');
				$(this).fadeIn(1000);
			});
			
			$('#bottom_box_1 p').fadeOut(1000, function(){
				$(this).hide();
				$(this).html('Spróbuj swoich sił i weź udział w konkursie!!<br /><a class="link" href="http://hipp.pl/index.php?id=519">dalej</a>');
				$(this).fadeIn(1000);
			});
			
			$('#bottom_box_3 img').fadeOut(1000, function(){
				$(this).hide();
				$(this).attr('src', '/fileadmin/template/img/home/promocje.jpg');
				$(this).parent().attr('href', '/?id=412');
				$(this).fadeIn(1000);
			});
			
			$('#bottom_box_3 p').fadeOut(1000, function(){
				$(this).hide();
				$(this).html('<div style="background: url(/fileadmin/template/img/home/button_mleko.jpg) 0 0px; padding-left: 15px;  color:white;height:16px;padding-top:0px "><b><a style="color: white; text-decoration: none;" href="http://hipp.pl/?id=412">Promocje na mleko</a></b></div>Sprawdź aktualne promocje w sklepach!<br/><a class="link" href="/?id=412">dalej</a>');
				$(this).fadeIn(1000);
			});
			
			$('#bottom_box_2 .box_content_2 img').fadeOut(1000, function(){
				$(this).hide();
				$(this).attr('src', '/fileadmin/template/img/home/hipp_przesylka_gratis.jpg');
				$(this).fadeIn(1000);
			});
			
			
			
			flag = 0;
		}

	}, 5000);
	
	$('a[rel=lightbox]').lightBox();
	
	popup();
	
});

function blockContest()
{
	$('#contestNotice').fadeIn();
	return false;
}

function popup()
{
	$('#bannerImg5').click();
	return false;
}

function showToplayer(page){
	
	$('#bannerImg'+page).click();
	
	//tb_show(null, '/fileadmin/template/img/home/bannerImg/'+page+'.jpg', false);
	
//	return false;
}

function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}



function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name);
        if (c_start!=-1)
        {
           c_start=c_start + c_name.length+1;
           c_end=document.cookie.indexOf(";",c_start);
           if (c_end==-1) c_end=document.cookie.length;
           c_value = unescape(document.cookie.substring(c_start,c_end));
           if(c_value < 2)
           {
              setCookie(c_name, parseInt(c_value) + 1 , 1000);
              window.open('index.php?id=504', 'HippPopup', 'scrollbars=yes,width=520,height=605'); return false;
           }	
        }
        else
        {
            setCookie(c_name, 1 , 1000);   
            window.open('index.php?id=504', 'HippPopup', 'scrollbars=yes,width=520,height=605'); return false;
        }
   }
   else
   {
        setCookie(c_name, 1 , 1000);   
        window.open('index.php?id=504', 'HippPopup', 'scrollbars=yes,width=520,height=605'); return false;
   }
   return "";
}
