var currentPopup;

$(function(){
	cicleTweet(1);
});

function cicleTweet(showTweet){
	var $class 		= '#toontweetbox ul li';
	var $speed 		= 7000;
	var $slide		= 500;
	var $nextTweet 	= showTweet+1;
	
	$($class).hide($slide);
	setTimeout(function(){},$slide);
	
	if($($class+'#tweet'+showTweet).length > 0){
		$($class+'#tweet'+showTweet).show($slide);
	}else{
		$($class+'#tweet1').show($slide);
		$nextTweet = 2;
	}
		
	setTimeout('cicleTweet('+$nextTweet+')',$speed);
}

function resizeSwf(id, width,height)
{			
	$('#'+id).css('width',width);
	$('#'+id).css('height',height);
}

function changeBalloonText() {
	limitText($('#balloon_text'),140); 
	
	var text = document.getElementById("balloon_text").value.replace(/\s/g,' ').replace(/  ,/g,',');	
	getFlashMovie("analist_flash").changeBalloonText(text);	
	document.getElementById("balloon_text").value = text;
}

function limitText(limitField, limitNum) {
	if (limitField.attr('value').length > limitNum) {
		var newValue  = limitField.attr('value').substring(0, limitNum);		
		limitField.attr('value',newValue);		
	} 
	else {
		var size = parseFloat(limitField.attr('value').length); 		
		$('#balloonSize').html(size+'/140 tekens');
	}
}


function changeTopText() {
	var size = parseFloat($('#top_text').attr('value').length); 		
	$('#top_text_size').html(size+'/60 tekens');	
	
	getFlashMovie("analist_flash").changeTopText(document.getElementById("top_text").value);
}

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function submitMyKnudde() {
	if (document.getElementById("balloon_text").value == '' || document.getElementById("mynaam").value == '' || document.getElementById("mywoonplaats").value == '' || document.getElementById("myemail").value == '') {
		alert('Niet alle velden zijn ingevoerd');
		return false;
	}
	return true;
}

$(document).ready(function (){
	$(".rating").stars({
		inputType: "select",
		callback: function(ui, type, value) {
			$.ajax({
				url: '/extra/stem.php?stem='+value
			});
		}
	});
	
	$()
	
	$('input, textarea').placeholder();
});


function likeOrDislike(id, likeType) {
	
	//alert('Like it? '+likeType);
	
	var value= id+'-'+likeType;
	
	$.ajax({
		url: '/extra/stem.php?stem='+value,
		success: function(data){
			//alert('vote added now'+data+"%");
			$('#percentage-module-'+id).empty();			
			$('#percentage-module-'+id).append('<span class="like-label">'+data+'%</span>');		
		}
	});
	
	
}

function openPopup(id) {
	$('.black_overlay').show();
	$('#'+id).show();
	
	currentPopup = '#'+id;
}

function closePopup() {
	$('.black_overlay').hide();
	$(currentPopup).hide();
}

window.fCopyToClipboard = function(rSource){ 
	rSource.select(); 
	if(window.clipboardData) { 
		var r = clipboardData.setData('Text',rSource.value); 
		return 1; 
	} 
	else return 0; 
} 

function filterBeoordeling(element, url) {
	if($(element).is(':checked')) {
		window.location.href = url+'goed-beoordeeld';
	}
	else {
		window.location.href = url;
	}
}
