$(document).ready(function () {
    Shadowbox.init({
        handleOversize: "drag",
        overlayOpacity: 0.9
    }, function () {
        Shadowbox.setup("#showcase a.image", {
            gallery: "art",
            continuous: true,
            counterType: "skip"
        });
    });
    $("#sites a").click(function () {
        Shadowbox.open({
            content: '<iframe src="' + $(this).attr("href") + "/single" + '" width="100%" height="100%" border="0" frameborder="0"/><\/iframe>',
            player: "html",
            width: 700,
            height: 400
        });
        return false;
    });
    $("#showcase a.video").click(function(){
		var rel = $(this).attr("rel").split(".");
		var url = "";
		var w=700;
		var h = 460;
		switch(rel[0]){
			case "vimeo":
				url = "http://vimeo.com/moogaloop.swf?clip_id="+rel[1]+"&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1";
			break;
		}
		Shadowbox.open({
			content:'<object width="'+w+'" height="'+h+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="'+url+'" /><embed src="'+url+'" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+w+'" height="'+h+'"><\/embed><\/object>',
			player:"html",
			width:w,
			height:h
		});
		return false;
	});
	var allImages = [];
	function assembleImages(){
		$("#showcase li").each(function(){
		allImages.push([$(this).position().top,$(this).find("img").attr("alt"),$(this).find("a").attr("class")]);
	});
	}
	if($("#showcase").length>0){
	assembleImages();
	scrollToRandom();
	var scrollInterval = window.setInterval(scrollToRandom,5000);
	}
	function scrollToRandom(){
		//console.log(allImages);
		if(allImages.length==0){
			assembleImages();
			}
	var random = Math.floor(Math.random()*allImages.length);
	var randomPos = allImages[random][0];
	$("#subtitle-title").text(allImages[random][1].toLowerCase());
	$("#subtitle-type").html('&nbsp;').removeClass().addClass("st-"+allImages[random][2]);
	$("#subtitle-all").html('<a href="media/'+allImages[random][2]+'s">All '+allImages[random][2]+'s</a>');
	//console.log("scrolling to "+randomPos);
	$("#showcase ol").animate({"top":0-randomPos+"px"},1000);
	//console.log("random: "+random+ " removing "+allImages[random]);
	allImages.splice(random,1)
	}
	
	
});
