var carousel, title, source;


function carousel() {
	// Get the image link from within its (parent) container.
	
	
	
	
	function getImage(parent, s) {
		var el = parent.firstChild;
		
		source = el.getAttribute('source');
		title = el.getAttribute('text');
		
		//alert(source);
		
		while (el) { // walk through till as long as there's an element
			if (el.nodeName.toUpperCase() == "IMG") { // found an image
				// flickr uses "_s" suffix for small, and "_m" for big
				// images respectively
				if (s == 1 ) {
					return source;
				} else {
					return el.src.replace(/_s\.jpg$/, "_m.jpg");
				}
							}
			el = el.nextSibling;
		}
		
		return "";
	}
			
	YAHOO.util.Event.onDOMReady(function (ev) {
		var el, item,
			spotlight   = YAHOO.util.Dom.get("spotlight"),
			carousel    = new YAHOO.widget.Carousel("container",
			{
				numVisible : 10
			
			}); 

			//alert(carousel.get("numVisible"));
			
			carousel.render(); // get ready for rendering the widget
			carousel.show();   // display the widget
							
		// display the first selected item in the spotlight
		
		item = carousel.getElementForItem(carousel.get("selectedItem"));
		
		var link_length = getImage(item, 1).length;
				
		if (item) {
			spotlight.innerHTML = "<img src=\"" + getImage(item) + "\">";
			x = document.getElementById('title-pict');
			x.innerHTML = title;
						
			if (getImage(item, 1).charAt(link_length-1) == 'v') {
				var s1 = new SWFObject('flv/player.swf','ply','546','409','9','#5F5746');
				s1.addParam('allowfullscreen','true');
				s1.addParam('allowscriptaccess','always');
				s1.addParam('wmode','opaque');
				s1.addParam('flashvars','file=../'+getImage(item, 1)+'&image='+getImage(item)+'&backcolor=5F5846&frontcolor=F5F7C9&lightcolor=32210A&screencolor=5F5746&controlbar=none&autostart=false&displayclick=play');
				s1.write('spotlight');
			}
		}
				   
		carousel.on("itemSelected", function (index) {
			// item has the reference to the Carousel's item
			item = carousel.getElementForItem(index);
			
			var link_length = getImage(item, 1).length;

			if (item) {
			
				spotlight.innerHTML = "<img src=\""+ getImage(item) +"\">";
				
				x = document.getElementById('title-pict');
				x.innerHTML = title;
				
				//alert(getImage(item, 1));
				
				if (getImage(item, 1).charAt(link_length-1) == 'v') {		
					var s1 = new SWFObject('flv/player.swf','ply','546','409','9','#5F5746');
					s1.addParam('allowfullscreen','true');
					s1.addParam('allowscriptaccess','always');
					s1.addParam('wmode','opaque');
					s1.addParam('flashvars','file=../'+getImage(item, 1)+'&image='+getImage(item)+'&backcolor=5F5846&frontcolor=F5F7C9&lightcolor=32210A&screencolor=5F5746&controlbar=none&autostart=false&displayclick=play');
					s1.write('spotlight');		
				}
			}
		});
	});
};
