	
var wHeight;
var imgs = new Array();
var cImgNum;


$(document).ready(function() {	
	
	wHeight = $(window).height();
						 
	// ------------------------------------------------------ PRELOAD BIG IMGs from THUMBS
	$('#lookable-thumbs a').preload({
		onRequest:function(data) {
		}
	});
	
	
	// ------------------------------------------------------ IMG WITH ATTRIBUTE orgSrc
	checkResizeableImage();
	
	
	
	
	// ------------------------------------------------------ VIDEO CLIPS
	$(".clip-thumb").click(function() {			
		//var oldsrc = $("#player-wrapper a").attr("href");
		var newsrc = $(this).attr("clip");
		$("a#player").width(500);
		$("a#player").height(281);

		$("a#player").attr('href', newsrc);
		$("#player-wrapper").fadeIn(300);		
		flowplayer("player", "functions/flowplayer-3.1.5.swf"); 
		centerClip();
	}); // end click Video Thumb
	

	// ------------------------------------------------------ MP3s
	$("ul.ring-list a").click(function() {	
		var mp3src = $(this).attr("href");
		//var coversrc = $(this).attr("cover");
		//var cWidth = $(this).attr("cwidth")+"px";
		//var cHeight = $(this).attr("cheight")+"px";
		//$("a#player").css({'width': cWidth, 'height': cHeight});
		$("a#player").attr('href', mp3src);
		$("#player-wrapper").fadeIn(300);
		$f("player", "functions/flowplayer-3.1.5.swf", {
 			playlist: [{url: mp3src, image: false} ]
		}); 
		centerClip();
	}); // end click Video Thumb
	
	

	// ------------------------------------------------------ KLINGELTON
	/*
	$("ul.mp3-list a").click(function() {	
		var mp3src = $(this).attr("mp3");
		var coversrc = $(this).attr("cover");
		var cWidth = $(this).attr("cwidth")+"px";
		var cHeight = $(this).attr("cheight")+"px";
		$("a#player").css({'width': cWidth, 'height': cHeight});
		$("a#player").attr('href', mp3src);
		$("#player-wrapper").fadeIn(300);
		$f("player", "functions/flowplayer-3.1.5.swf", {
			playlist: [coversrc, mp3src]
		}); 
		centerClip();
	}); // end click Video Thumb
	*/
	
	
	
	
	// ------------------------------------------------------ IMAGES
	$("#lookable-thumbs a").click(function() {
		var newsrc = $(this).attr("href");
		var i=0;
		$("#lookable-thumbs a").each(function() {
			imgs[i] = $(this).attr("href");	
			if (imgs[i]==newsrc) {
				cImgNum = i;	
			}
			i++;
		});
		$("#image-wrapper").fadeIn(300);
		$("#goLeft").show();
		$("#goRight").show();
		placeImage();
		centerImage();
	}); // end click Img Thumb
	
	
	$("#player-close").click(function(){
		$("#player-wrapper").fadeOut(300);			 
	});

	$("#image-close").click(function(){
		$("#image-wrapper").fadeOut(300);	
	});
	
	$("#goRight").click(function(){
		if (cImgNum<imgs.length-1) {
			cImgNum++;		 
			placeImage();
		}
	});
	
	$("#goLeft").click(function(){
		if (cImgNum>0) {
			cImgNum--;		 
			placeImage();
		}
	});
	

}); // end document ready



function placeImage() {
	var info = $("#lookable-thumbs a[href="+imgs[cImgNum]+"] img").attr("title");
	var copy = $("#lookable-thumbs a[href="+imgs[cImgNum]+"] img").attr("by");
	var meta = info+"<br>"+copy;
	//alert (meta);
	$("#image-meta").html("");
	$("#image-meta").html(meta);

	$("#img-placeholder").attr('src', imgs[cImgNum]);


}



$(window).resize(function() {
 wHeight = $(window).height();
 //alert (wHeight);
 centerImage();
});


function centerImage() {	
	$("#img-placeholder").height(wHeight-60);
	$("#img-placeholder").css("margin-top", 30);
} // center image


function centerClip() {
	var cHeight = $("a#player").height();
	$("a#player").css('margin-top', (wHeight-cHeight)/2);
}




function checkResizeableImage() {
	// ------------------------------------------------------ IMG WITH ATTRIBUTE orgSrc
	$("img[orgsrc]").mouseover(function() {
		$(this).css("cursor", "pointer");
	});
	
	$("img[orgsrc]").click(function() {
		//alert($(this));
		$("#image-wrapper").fadeIn(300);
		$("#img-placeholder").attr('src', $(this).attr("orgsrc"));
		$("#goLeft").hide();
		$("#goRight").hide();
		centerImage();
	});

}








