$(document).ready(function() {
	/*$(".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);
	*/
/*
  // 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
  });*/


	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);
}