var btn = null; 
function popular(el,id) {
    if($('popular').hasClass('on')) { return false; } 
    var ajx = new Ajax(af_uri+'a/popular/',{method:'get',update:'fla',evalScripts:true}).request();
    activate(id)
    return false; 
}
function recent(el,id) {
    if($('recent').hasClass('on')) { return false; } 
    var ajx = new Ajax(af_uri+'a/recent/',{method:'get',update:'fla',evalScripts:true}).request();
    activate(id)
    return false; 
}
function school(el) {
    var ajx = new Ajax(af_uri+'a/school/'+$(el).value,{method:'get',update:'fla',evalScripts:true}).request();
    return false; 
}
function activate(id) {
    rate.reset(id);
    $('btns').getElements('a').each(function(item,index){
        item.toggleClass('on') 
    }); 
}

function fSetCurrent(){
	vid = VideoId;
	title = VideoTitle;
	getVideoViews(vid);
	getVideoRanks(vid);

	$('share_title').innerHTML = '"'+title+'"';
	$('u_code').value = '<a href="'+af_uri+'video/'+vid+'">Watch my Mashup: '+title+'</a>';
	
	if (!$('u_share_id')){
		var eShareId = new Element('input', {
			'name':'u_share_id',
			'id':'u_share_id',
			'type':'hidden',
			'value':vid
		});
		eShareId.inject('fShare','top');
	} else {
		$('u_share_id').value = vid;		
	}

	if (!$('u_share_title')){
		var eShareTitle = new Element('input', {
			'name':'u_share_title',
			'id':'u_share_title',
			'type':'hidden',
			'value':title
		});
		eShareTitle.inject('fShare','top');
	} else {
		$('u_share_title').value = title;		
	}	
}

function getVideoViews(vid){
	ajx = new Ajax(af_uri+'a/views/'+vid,{method:'get',update:'video_views'}).request();
}

function getVideoRanks(vid){
	ajx = new Ajax(af_uri+'a/ranks/'+vid,{method:'get',update:'video_ranks'}).request();
}

function copy(inElement) {
	if (inElement.createTextRange) {
		var range = inElement.createTextRange();
		if (range) range.execCommand('Copy');
	} else {
		var flashcopier = 'flashcopier';
		if(!document.getElementById(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		document.getElementById(flashcopier).innerHTML = '';
		var divinfo = '<embed src="scripts/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}
}

/**
 * Throw a message to the flash class in runtime.
 * If the flash div/slider does not exist, this function creates it.
 */
function throwMessage(type,msg,slideout){
	//If the flash message has already displayed and is a part of the dom
	if(slider && $('flash')){
		$('flash').addClass(type); 
		$('flash').getFirst().innerHTML = msg;
	//Create a new flash message and slider object
	} else {
		//create element
		var elFlash = new Element('div', {
			'id' : 'flash',
			'class' : type
		});	
		
		elFlash.inject($('s').getFirst(),'after');	
		var slider = new Fx.Slide('flash', {duration: 500}).hide();
		$('flash').innerHTML = '<span>'+msg+'</span>';
	}
	slider.slideIn();
	if(slideout) (function(){slider.slideOut();}).delay(5000);		
}

