function popup(url, windowname, width, height, scrollbars, features) {
	
	width=(width)?width:screen.width/2;
	height=(height)?height:screen.height/2;
	scrollbars=(scrollbars)?scrollbars:'yes';
	var screenX = (screen.width/2 - width/2);
	var screenY = (screen.height/2 - height/2);
	var features= "width=" + width + ",height=" + height +",scrollbars=" + scrollbars + ",status=no";
	features += ",screenX=" + screenX + ",left=" + screenX;
	features += ",screenY=" + screenY + ",top=" + screenY;
	
	var mywin=window.open(url, windowname, features);
	if (mywin)
	mywin.focus();
	return mywin;
	
}


/* --------------------------------------------------------------------
	jCarousel
 -------------------------------------------------------------------- */
	
	/*  frases  */
	function mycarousel_initCallback(carousel)
	{
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});
	
		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});
	
		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	};

	jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	};
	
	/*  llibres home  */
	function checkSubMenu(){
		$('#mycarousel a').each(function(){
			$('#jc-l' + $(this).attr('class') + ' .fletxa img').attr('src', 'img/submenu-triat-off.gif');
			$('#jc-l' + $(this).attr('class')).attr('class', 'item');
			
		});
		
		
		return true;
	}
	
	function clickCarouselHome(id_llibre){
		
		//var id_llibre = $(this).attr('class');
		//var href = $(this).attr('href');
		
		$.ajax({
		  url: 'load-llibre-info.php',
		  type: "GET",
		  data: 'lid='+id_llibre,
		  cache: false,
		  beforeSend: function(){
			  $("#info-llibre").html('<div style=" height: 120px;"><div style=" text-align:center; margin-top: 70px;"><img src="img/ajax-loader.gif"></div></div>');
		  },
		  success: function(html){
			$("#info-llibre").hide();
			$("#info-llibre").html(html);
			$("#info-llibre").fadeIn('slow');
		  }
		});
		
		checkSubMenu();
		
		$('#jc-l' + id_llibre + ' .fletxa img').attr('src', 'img/submenu-triat.gif');
		$('#jc-l' + id_llibre).attr('class', 'item triat');
		$('#jc-vincle-com a').attr('href', 'titulos.php?lid=' + id_llibre + '#reg');
		
		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, mycarousel_itemList.length);
		carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
	};
	 
	function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
	{
		carousel.remove(i);
	};
	 
	/**
	 * Item html creation helper.
	 */
	function mycarousel_getItemHTML(item)
	{
		html = '<li><div class="item" id="jc-l' + item.lid + '" style=" display:block; height:1%;"><div class="fletxa"><img src="img/submenu-triat-off.gif" alt="' + item.foto_llibre + '" title="' + item.foto_llibre + '"></div><div class="llibre"><a href="load-llibre-info.php" class="' + item.lid + '" title="' + item.foto_llibre + '" onClick="return clickCarouselHome('+item.lid+');"><img src="image.redimensio.php?img=usuaris/llibres/' + item.foto_llibre + '&w=74&h=125" alt="libro" title="libro"></a></div></div></li>';
		
		return html;
		
	};
	
	jQuery(document).ready(function() {
		
		//frases
		jQuery('#salta-frases').jcarousel({
			vertical: true,
			scroll: 1,
			auto: 6,
			wrap: 'last',
			initCallback: mycarousel_initCallback,
			easing: 'BounceEaseOut',
			animation: 1000
		});
		
		//popup
		$('.popup').click(function(){
			
			url = $(this).attr('href');
			popup(url, 'popup', 500, 560);
			
			return false;
			
		});
		
		//valoració
		function checkValoracio(){
			for(i=1; i<5; i++){
				$('#form-comentari-titulos #valoracio #'+i).attr('class', 'image down');
			}
		}
		
		$('#form-comentari-titulos #valoracio .image').click(function(){
			
			checkValoracio();
			var id = $(this).attr('id');
			$('#form-comentari-titulos #input-valoracio').attr('value', id);
			
			for(i=1; i<=id; i++){
				$('#form-comentari-titulos #valoracio #'+i).attr('class', 'image up');
			}
			
		});
		
	});
	