function open_radio() {
	newwindow=window.open('/radio','name','height=358,width=369');
	if (window.focus) {newwindow.focus()}
	
	return false;
}

$(document).ready(function(){
	
	if(jQuery.fn.jScrollPane) {
		number = $('.scrollin .hentry').length;
		$('.scrollin').width(165 * number);
		$('.scroll-pane').jScrollPane({
			horizontalDragMinWidth: 30,
			horizontalDragMaxWidth: 30
		});
	}
	
	
	$(".open_radio").click(open_radio);
	
	$('.gallery li a').fancybox();
	// $(".carusel").scrollable({  
	//    	speed:1000,
	// 	circular:true
	// 	});
	$('.switcher a').click(function() {
		$('.switcher a').removeClass('here');
		$(this).addClass('here');
		return false;
	});
	
	$('input[title!=""],textarea[title!=""]').hint();
	
	$(".tracks_highlight .playlist").find("li").click(function() { 
		var index = parseInt($(this).attr("rel"));
		
		$(".tracks_highlight .playlist").find("a").removeClass("here");
		$(this).find("a").addClass("here");
		
		var items = $(".mediaholder").children();
	    
		items.filter(':visible').hide();
		items.eq(index).fadeIn('slow');
		
		return false;
	});
	
	
	// -----------------------------------PAGI
	function paginate_prev(o, next_class) {
		if ($(o).hasClass("disabled")) {
			return false;
		}

		var $pager_container = $(o).parents(".pager_container");						
		var $current_page = $pager_container.find(".pagetolist.current");

		if ($current_page.hasClass("first")) return false;

		$current_page.hide().removeClass("current");

		var $prev = $current_page.prev();

		$prev.fadeIn('slow').addClass("current");

		var $page_number_container = $pager_container.find(".currentpage");
		var page_number = parseInt($page_number_container.text());

		$page_number_container.html(page_number-1);

		if ($prev.hasClass("first")) {
			$(o).addClass("disabled");
		}

		$pager_container.find("p.pagi > span." + next_class).removeClass("disabled");

		return false;
	}

	function paginate_next(o, prev_class) {
		if ($(o).hasClass("disabled")) {
			return false;
		}

		var $pager_container = $(o).parents(".pager_container");
		var $current_page = $pager_container.find(".pagetolist.current");

		if ($current_page.hasClass("last")) return false

		$current_page.hide().removeClass("current");

		var $next = $current_page.next();

		$next.fadeIn('slow').addClass("current");

		var $page_number_container = $pager_container.find(".currentpage");
		var page_number = parseInt($page_number_container.text());

		$page_number_container.html(page_number+1);

		if ($next.hasClass("last")) {
			$(o).addClass("disabled");
		}

		$pager_container.find("p.pagi > span." + prev_class).removeClass("disabled");

		return false;
	}
	
	
	$(".pagi .prev").live("click", function() {
		return paginate_prev(this, "next");
	});

	$(".pagi .next").live("click", function() {
		return paginate_next(this, "prev");
	});
	
	
    });



	jQuery.fn.hint = function () {
	  return this.each(function (){
	    var t = jQuery(this);
	    var title = t.attr('title');
	    if (title) {
	      t.blur(function (){
	        if (t.val() == '') {
	          t.val(title);
	          t.addClass('blur');
	        }
	      });
	      t.focus(function (){
	        if (t.val() == title) {
	          t.val('');
	          t.removeClass('blur');
	        }
	      });
	      t.blur();
	    }
	  });
	}
	
	function resizeEmbed(objects, width, height) {	
		for (var i=0; i<objects.length; i++) {
			var obj = objects[i];

			var code = obj['video']['code'];
			var source_width_blocks = code.match(/width=\"?(\d+)\"?/gi);
			var source_height_blocks = code.match(/height=\"?(\d+)\"?/gi);

			if (source_width_blocks.length != source_height_blocks.length) {
				continue;
			}

			for (var j=0; j < source_width_blocks.length; j++) {
				var source_width = source_width_blocks[j].match(/\d+/);
				var source_height = source_height_blocks[j].match(/\d+/);

				if (source_width.length == 0 || source_height.length == 0)  {
					continue;
				}

				if (parseInt(source_width) == width) {
					continue;
				}

				if (height == null || height == undefined) {
					height = Math.floor(width * parseInt(source_height[0]) / parseFloat(source_width[0]));
				}

				obj['video']['code'] = obj['video']['code'].replace(source_width_blocks[j], 'width="' + width + '"');
				obj['video']['code'] = obj['video']['code'].replace(source_height_blocks[j], 'height="' + height + '"');
			}
		}

		return objects

	}


