$(document).ready(function() {
	// var gallery = $('#mask').galleriffic({
	// 	        delay:                     3000, // in milliseconds
	// 	        numThumbs:                 20, // The number of thumbnails to show page
	// 	        preloadAhead:              -1, // Set to -1 to preload all images
	// 	        enableTopPager:            false,
	// 	        enableBottomPager:         true,
	// 	        maxPagesToShow:            7,  // The maximum number of pages to display in either the top or bottom pager
	// 	        imageContainerSel:         '#artist_big_image', // The CSS selector for the element within which the main slideshow image should be rendered
	// 	        controlsContainerSel:      '', // The CSS selector for the element within which the slideshow controls should be rendered
	// 	        captionContainerSel:       '', // The CSS selector for the element within which the captions should be rendered
	// 	        loadingContainerSel:       '', // The CSS selector for the element within which should be shown when an image is loading
	// 	        renderSSControls:          false, // Specifies whether the slideshow's Play and Pause links should be rendered
	// 	        renderNavControls:         false, // Specifies whether the slideshow's Next and Previous links should be rendered
	// 	        playLinkText:              'Play',
	// 	        pauseLinkText:             'Pause',
	// 	        prevLinkText:              'Previous',
	// 	        nextLinkText:              'Next',
	// 	        nextPageLinkText:          'Next &rsaquo;',
	// 	        prevPageLinkText:          '&lsaquo; Prev',
	// 	        enableHistory:             false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes
	// 	        enableKeyboardNavigation:  true, // Specifies whether keyboard navigation is enabled
	// 	        autoStart:                 true, // Specifies whether the slideshow should be playing or paused when the page first loads
	// 	        syncTransitions:           false, // Specifies whether the out and in transitions occur simultaneously or distinctly
	// 	        defaultTransitionDuration: 1000, // If using the default transitions, specifies the duration of the transitions
	// 	        onSlideChange:             undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
	// 	        onTransitionOut:           undefined, // accepts a delegate like such: function(slide, caption, isSync, callback) { ... }
	// 	        onTransitionIn:            undefined, // accepts a delegate like such: function(slide, caption, isSync) { ... }
	// 	        onPageTransitionOut:       undefined, // accepts a delegate like such: function(callback) { ... }
	// 	        onPageTransitionIn:        undefined, // accepts a delegate like such: function() { ... }
	// 	        onImageAdded:              undefined, // accepts a delegate like such: function(imageData, $li) { ... }
	// 	        onImageRemoved:            undefined  // accepts a delegate like such: function(imageData, $li) { ... }
	// 	    });
	
	/*$(".thumb").find("img").click(function(){
		var thumbImage = $(this).prev().attr("src").replace("/artists/thumbs/", "/artists/");
		var bigImage = $(".big").attr('src').replace("/artists/", "/artists/thumbs/");
		$(this).prev().attr("src", bigImage);
		$(".big").attr('src', thumbImage);
		return false;
	})
	// slide show
	//time_out = setInterval(slide_show, 5000);
	*/
	
	$("#mask").jCarouselLite({
		btnNext: ".next_bolinhas",
		btnPrev: ".prev_bolinhas",
		visible: 3,
		scroll: 1,
		speed: 400,
		circular: false
	});
/*
  // scroll bolinhas
  $("#bolinhas").jCarouselLite({
    btnNext: ".next_bolinhas",
    btnPrev: ".prev_bolinhas",
    visible: 22,
    scroll: 1,
    speed: 400,
    circular: false
  });
*/
	// scroll
/*  $("#scroller_artits").jCarouselLite({
    btnNext: ".next_artist",
    btnPrev: ".prev_artist",
    visible: 5,
    scroll: 1,
    speed: 400,
    circular: false
  });*/
	
	$("#mask a.thumb").click(function(e){
		e.preventDefault();
		$("#artist_big_image").html("<img src='"+$(this).attr("rel")+"'/>").hide().fadeIn("slow");
	});

	$("#artist_big_image").cycle({
		fx: 'fade',
		speed: 2000,
		timeout: 4000,
	});

	//setTimeout("slide_show();", 500); 
	
	$('.lightbox').lightBox({
			imageLoading: "img/lightbox-ico-loading.gif",
			imageBtnClose: "img/lightbox-btn-close.gif",
			imageBtnPrev: "img/lightbox-btn-prev.gif", 
			imageBtnNext: "img/lightbox-btn-next.gif",
			txtImage: "Photo"
		});
  
});

var time_out = 0;
var pice_actual = 0;
var first = 0;

function slide_show() {
	
	if (pice_actual == $(pieces).size()){
		pice_actual = 0;		
	}
	else if (pice_actual == -1 ) {
		pice_actual = $(pieces).size() - 1;
	}
	
	$("#artistCont h2").html(pieces[pice_actual].name);
	
	
	var media_id = pieces[pice_actual].Gallery.media_id;
	if (media_id == 0)
		media_id = pieces[pice_actual].Gallery.Media[0].id;
	 
	
	$("#pieces_pics").attr("src", webroot+"images/get/567x440/"+media_id+"/"+pieces[pice_actual].slug+".jpg");
	
	//alert(media_id);
	
	
	$("#pieces_pics").error(function(){
		
		var conteudo = "<a href='"+webroot+"images/get/full/"+pieces[pice_actual].Gallery.Media[0]+"/"+pieces[pice_actual].slug+".jpg' rel=\"disableAutoStart: true; zoom-color:#6e8c0e; size:200px; linkUrl:"+webroot+"pieces/"+pieces[pice_actual].slug+"\" class='MagicMagnify'><img src='"+webroot+"files/medias/567x440/mask.png' class='mask' alt='' /></a>";
		$("#magic_div").html(conteudo);
	
		$(this).attr("src", $("#pieces_pics").attr("src", webroot+"images/get/567x440/"+pieces[pice_actual].Gallery.Media[0].id+"/"+pieces[pice_actual].slug+".jpg"));
		//alert("apos erro: "+pieces[pice_actual].Gallery.Media[0].id+".jpg");			
		if(FlashDetect.installed){
			setTimeout("MagicMagnify_findMagnifiers();", 500);
		}
				
		$("#pieces_pics").error(function(){
			
			$(this).attr("src", $("#pieces_pics").attr("src", "/files/medias/567x440/0.jpg"));
			
			if(FlashDetect.installed){
				setTimeout("MagicMagnify_findMagnifiers();", 500);
			}
			
			$("#pieces_pics").error(function(){});
		});
	});
			
	var conteudo = "<a href='"+webroot+"images/get/full/"+media_id+"/"+pieces[pice_actual].slug+".jpg' rel=\"disableAutoStart: true; zoom-color:#6e8c0e; size:200px; linkUrl:"+webroot+"pieces/"+pieces[pice_actual].slug+"\" class='MagicMagnify'><img src='"+webroot+"files/medias/567x440/mask.png' class='mask' alt='' /></a>";
	$("#magic_div").html(conteudo);	
	//$("#magic_div").attr("style", "margin-left: 0px; margin-top: -305px; z-index:100");
	//$("#magic_div").attr("style", "position:absolute; right:20px; top:13px; z-index:100");	
	$("#magic_div").css("position", "absolute");
	$("#magic_div").css("right", "20px");
	$("#magic_div").css("top", "13px");
	$("#magic_div").css("z-index", "100");
	
	//alert('sas');
	
	//$(".circle").attr("src", $(".circle").attr("src").replace(/circle_selected2.png/, "circle_not_selected2.png"));
	//$("#circle"+pice_actual).attr("src", $("#circle"+pice_actual).attr("src").replace(/circle_not_selected2.png/, "circle_selected2.png"));
	
	//if (first != 0)
		if(FlashDetect.installed){
			setTimeout("MagicMagnify_findMagnifiers();", 500);
		}
		
	first = 1;
}

function open_piece() {
	document.location.href = webroot+"pieces/"+pieces[pice_actual].slug;
}

function GetThis(T, C, U, L)
{
	var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T) + '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + L;
	window.open(targetUrl);
}