var gallery = new Array();

function renderGalleries(){
		
	$('.gallery').each(function(){
		
		var target = $(this).find('.placeholder');
		var id = $(this).attr('id').replace("gallery_","");
				
		if(gallery[id][1] == "0"){
		
		// get images and display
		$.ajax({
			type: "GET",
			url: gallery[id][0],
			dataType : 'json',
			success: function(data){

				var num = data.length-1;
				
				for (i = 0; i <= num; i++) {
					
					$(target).append('<img src="' + data[i].link + '" width="929" height="301" alt="' + data[i].alt + '" class="" />');
				
				}
				
				$(target).cycle({ 
					fx:     'fade',
					timeout: 5000,
					delay: -2000,
				});


			}
		});
			
			

			
		} else if(gallery[id][1] == "1"){
			
	var noCache = new Date().getTime();
	
	$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=46992512@N02&lang=en-us&format=json&jsoncallback=?", { "noCache": noCache }, function(data){
		$.each(data.items, function(i,item){
	
			$("<img/>").attr({ 
			src: item.media.m.replace("_m.","_s."),
			alt: item.title,
			class: 'thumb',
			}).appendTo(target).wrap("<a href=\""+item.media.m.replace("_m.",".")+"\" target=\"_blank\" class=\"thumb_gallery\" rel=\"gallery_fancy\"></a>")  ;
					
		});
		
			 $('a[rel="gallery_fancy"]').fancybox({ });
	
	});
			
		}
		
								
	});
	
	
}

function getOnAir(){
	
	 var startDate = new Date(2010, 03, 16);

//alert(startDate);

	var c = new Date().getTime();
	
	$.getJSON('../data/on_air.json', { "c": c }, function(data){
										 
			// add show to page
		$('.show .name').html(data['name']);
		$('.show .email').html('<strong>E-Mail:</strong> '+data['email']);
		$('.show .air').html('<strong>On Air:</strong> '+ data['time']);
		$('.show .presenter').find('img').attr("src", data['image']);
	
	});
	
	setTimeout('getOnAir()', 30000);
	
};

function getShows(){
	
	$('.showcar').each(function(){

	var c = new Date().getTime();
	
	var a = $(this).attr('title');
		
	switch (a){ case 'showall': var feed = '../data/scripts/all_shows.php'; break; case 'showcome': var feed = '../data/coming_up.json'; break; }
	
	$.getJSON(feed, { "c": c }, function(data){
											 
		if(data.length != 0){
			$.each(data, function(i, item){
		
				$('.archive_items .show').append(	'<li class=\"posRelative info\">'
								  + '<a href=\"' + item.link + '\">'
								  + '<div class=\"title\">'
								  +	'<strong>' + item.title + '</strong><br/>'
								  +	'<span class=\"slogan hide\">' + item.slogan + '</span>'
								  +	'</div>'
								  +	'<img src=\"../assets/show/' + item.thumb + '\" alt=\"' + item.title + '\" width=\"165\" height=\"165\" border=\"0\" />'
								  +	'</a>'
								  + '</li>');		
			
			});
			
			$('.carousel').carousel(); showHover();
		} else { $('#presenter_gallery').hide(); };
		
										
			
	}); });
	
};

function showHover(){

	$("li.info").hover( function () {
			$(this).find('.title').animate({top:100}, 400);
			$(this).find('.slogan').fadeIn(400);
	}, 
		  function () {
			$(this).find('.title').animate({top:120}, 400);
			$(this).find('.slogan').fadeOut(400);
	});

};



$(document).ready(function(){

	 getOnAir();
	 
	 getShows();
	 
	 renderGalleries();	
	 
	try {
		
		$('.audio').fancybox({
				  onStart : function() {
				//alert("AUDIO: " + $(".audio")[0].rel); // it's OK for the first link
                }, 
		'autoScale'		: true,
		'centerOnScroll': true, 
		'swf' : {flashvars: 'file='+$(".audio")[0].rel+'&type=sound&wmode=opaque&image=assets/images/radio-caley-player.jpg'}
		});

	 $('a[rel="gallery_fancy"]').fancybox({ });
	
	} catch (e) {}
	 
	 $(".popout").popupwindow(profiles);


});







// #################################################################### \\
// # SCRIPTING FOR VIDEO POPOUT WINDOW (START)						  # \\                    
// #################################################################### \\

var profiles =
{
	player:
	{
		height:210,
		width:470,
		top:0,
		left:0,
		resizable:0,
		location:0

	},
	webcam:
	{
		height:356,
		width:450,
		top:0,
		left:0,
		resizable:0,
		location:0

	}

};

// #################################################################### \\
// # SCRIPTING FOR VIDEO POPOUT WINDOW (END)						  # \\                    
// #################################################################### \\
