Cufon.replace('h2, .content .posts_header h3, .content .posts_header strong, .labelSubjects, .labelPosts, .content .new_post p label, .fckeditor_box label, .newThread label, .content .previewBox label');

function nextElem(elemObj, elemObjNav){
   var index = $(elemObj).filter('.active').index();
   
   if(elemObjNav){
       var indexNav = $(elemObjNav).filter('.active').index();
       
       $(elemObjNav).eq(index).removeClass('active');
       if(index < $(elemObjNav).length - 1){            
          $(elemObjNav).eq(index+1).addClass('active');            
       } else{
          $(elemObjNav).eq(0).addClass('active');
       }
    }     
   
   $(elemObj).eq(index).removeClass('active');
   if(index < $(elemObj).length - 1){            
      $(elemObj).eq(index+1).addClass('active');            
   } else{
      $(elemObj).eq(0).addClass('active');
   }     
}

function prevElem(elemObj){
   var index = $(elemObj).filter('.active').index();     
   
   $(elemObj).eq(index).removeClass('active');
   if(index <= $(elemObj).length - 1){            
      $(elemObj).eq(index-1).addClass('active');            
   } else{
      $(elemObj+':last').addClass('active');
   }     
}

function loginPanelShow(){
    if ($('.header .logged').length < 1) {
        CheckCookie('lyteboxAction', 500);
        var offset = $('.LinkLogIn').offset();
        $('body').append('<div class="layerBox"></div>');
        $('.layerBox').height($('body').height());
        $('.header #loginFrame').css({
            'display':'block',
            'left': offset.left-140+'px',
            'top': offset.top+19+'px'
            }); 
        $('html').animate({scrollTop:0}, 'slow');     
    }
}

function openpopup(url, width, height) {
		var theURL=url;
		var winName='popup_coke_ccl';
		if(width == null) var width=499;
		if(height == null) var height=546;
		var topY=(screen.height-height)/2;
		var leftX=(screen.width-width)/2;
		var features='innerWidth=' + width+',innerHeight='+height+',width=' + width+',height='+height+',top='+topY+',left='+leftX+',resizable=0,srollbars=0';

	    var popup=window.open(theURL,winName,features);
		popup.focus();
}

function pageCenter(){  
    var height = 0;  
    if($('body').height() < $(window).height()){ 
        height =  $(window).height() - $('body').height();
        if(height > 181){
            $('.container').height($(window).height() - 181);
            height = 181;
        }
         
        $('body').css({
            'paddingTop': height,
            'background-position': '50% ' + (height - 181)+'px'
        });
    }     
}

function addQuizBoxWrapper (){
    $('.quizy .box5').wrap('<div class="box5Wrapper"></div>');
}
function removeQuizBoxWrapper (){
    $('.quizy .box5').unwrap('<div class="box5Wrapper"></div>');
}

$(document).ready(function(){        
    
    // dodanie klasy last
    $('.newPosts li:last').addClass('last');
    
    // box partnerzy       
    if($('ul.partners li').length > 1) setInterval("nextElem($('ul.partners li'), $('ul.partnersNavi li'))", 5000);
    
	/* galeria w fashion week*/
	if($('.fashion_week_galeria .galeria').length > 0) $('.fashion_week_galeria .galeria').FWGaleria();	
    
    // warstwa do logowania
    $('.LinkLogIn').bind('click', function(){                        
		loginPanelShow();
        return false;   
    });	
    
    $('.layerBox').live('click', function(){
        $('.layerBox').remove();
        $('.header #loginFrame').hide();
    });
    
    // gorace tematy
    $('.hotTopic li:first').addClass('active');
    $('.hotTopic').before('<a href="#" class="prevTopic topicBtn"><span>poprzedni</span></a>');
    $('.hotTopic').after('<a href="#" class="nextTopic topicBtn"><span>nastepny</span></a>');
    
    $('.nextTopic').live('click', function(){
        nextElem('.hotTopic li');
        return false;
    });
    $('.prevTopic').live('click', function(){
        prevElem('.hotTopic li');
        return false;
    });
    
    if($('.hotTopic').length > 0) setInterval("$('.hotTopicBox .nextTopic').trigger('click')", 4000);
    
    
    // popup
    $('.popup').bind('click', function(){ 
        openpopup($(this).attr('href'));
        return false;
    });
    
    // popup do coke.pl (mniejszy)
    $('.popup2').bind('click', function(){ 
        openpopup($(this).attr('href'), 500, 580);
        return false;
    });
    
    // tooltip
    var toolTipText;
    $('.toolTip, .btnNieInformujMnie, .btnInformujMnie').hover(function(){     
        toolTipText = $(this).attr('title');   
        var offset = $(this).offset();
                      
        $('body').append('<div class="toolTip">'+toolTipText+'</div>');
        $(this).css('position', 'relative').attr('title', '');  
        $('.toolTip').css({
            'left': offset.left+'px',
            'top': offset.top-110+'px'
            }); 
        $('.toolTip').ifixpng('/_images/_layout/pixel.gif');  
    }, function(){
        $('.toolTip').remove(); 
        $(this).attr('title', toolTipText).css('position', 'inherit');           
    });    
            
});

$(window).load(function(){
     
    pageCenter();
    
    // wyrownana wysokosc box-ow
    if($('.frontBoxWrapper > div').not('.quizy .frontBoxWrapper > .newQuiz').length > 1) {
        var maxBoxHeight = 0;
        $('.frontBoxWrapper > div').each(function(){
            if($(this).outerHeight() > maxBoxHeight) maxBoxHeight = $(this).outerHeight();            
        });                    
        
        $('.frontBoxWrapper > div').each(function(){
            $(this).height(maxBoxHeight - parseInt($(this).css('padding-top')) - parseInt($(this).css('padding-bottom')));
        });
    }   
        
});

$(window).resize(function(){
     
    pageCenter();

});

function alert_box() {
    alert("I am displayed by a function te");
    setTimeout("window.location.href=window.location.href", 2000);
}

function showQuizRanking(isVisible) {
    if (isVisible)
    {
        $('#divRanking').removeClass('hide');
        $('#divNewQuiz').removeClass('box5');
        $('#divNewQuiz').addClass('box3');
        
    }
    else
    {
        $('#divRanking').addClass('hide');
        $('#divNewQuiz').removeClass('box3');
        $('#divNewQuiz').addClass('box5');
    }
        
}