/*
$j(document).ready(function() {
	var blubrotator = $j('#blub').rotator({ 'textContainerId': 'blub_text'});
	$j('#button1').click(function(){
		blubrotator.rotator('previous');
	});
	$j('#button2').click(function(){
		blubrotator.rotator('next');
	});
});
*/

var list;
var control;
var pc;
$j(document).ready(function() {
	pc = $j('.pc5');
	
	list =  $j('#mycarousel .item').removeClass('hide');
	$j('#mycarousel .jcarousel-control').removeClass('hide');
	control =  $j('#mycarousel .jcarousel-control').children();
	$j('#mycarousel').jcarousel({wrap: 'circular',
									 scroll:1,
									 initCallback: mycarousel_initCallback,
									 itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
									 itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
									});
	
	$j('.jcarousel-prev')
	.css( {backgroundPosition: "0px 0px"} )
	.mouseover(function(){
		$j(this).stop().animate({backgroundPosition:"(-20px 0px)"}, {duration:200})
	})
	.mouseout(function(){
		$j(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:200, complete:function(){
			$j(this).css({backgroundPosition: "0px 0px"})
		}})
	})
	
	$j('.jcarousel-next')
	.css( {backgroundPosition: "-20px 0px"} )
	.mouseover(function(){
		$j(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:200})
	})
	.mouseout(function(){
		$j(this).stop().animate({backgroundPosition:"(-20px 0px)"}, {duration:200, complete:function(){
			$j(this).css({backgroundPosition: "-20px 0px"})
		}})
	})

	
	var article = $j('#article').paginator({articleControlId: 'articleControl', articleControlContainerId: 'articleControlContainer', paginationControlId: 'paginationControl'});
	$j('#fullArticle').click(function(){
		if($j(this).html() == 'show full article') {
			$j(this).html("show pagination");
		} else {
			$j(this).html("show full article");
		}
		article.paginator("showFullArticle");
		return false;
	});	
	
	//console.log($j('.pc').attr('title', 'premium content').parent().parent());
	$j('.pc,.pc1,.pc2,.pc3,.pc5').attr('title', 'premium content').tooltip({
		fixPNG: true,
		top: -40, 
		showURL: false,
		left: -110
	});
	
	$j('a.top').click(function(){
		$j.scrollTo($j('#top'), 1000);
		return false
	});
	
});





function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
	
	var idx = carousel.index(i, list.length);
	if($j(list[idx - 1]).find('.pc4').size() > 0 ) {
		var link = $j(list[idx - 1]).find('a').attr('href');
    	pc.fadeIn('slow');
    	pc.attr('href', link);
    } else {
    	pc.fadeOut('slow');
    	pc.attr('href', '##');
    }
	
    carousel.add(i, $j(list[idx - 1]).html());
    $j(control).each(function(){
    	$j(this).removeClass("active");
    });
    $j(control[idx-1]).addClass("active");
	
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);    
    
};

function mycarousel_initCallback(carousel) {
	
	
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

function expandComic(id) {
	hs.expand(document.getElementById(id));
	//console.log(document.getElementById(id));
}

