// CHANGE
var rooturl = 'http://focus.mynews.bg/';
var locale = 'bg';
var webroot = 'http://focus.mynews.bg/';


var mytooltip = {
	elId: '.article-author-picture',
	videoId: '.video-title',

	show: function(id) {

		if (id) {
			el = mytooltip.elId + '-' + id;
		} else {
			el = mytooltip.elId;
		}

		author_pic = $$(el)[0] || false;
		if (author_pic) {
			author_pic.show();
		}
	},

	hide: function(id) {

		if (id) {
			el = mytooltip.elId + '-' + id;
		} else {
			el = mytooltip.elId;
		}

		author_pic = $$(el)[0] || false;
		if (author_pic) {
			author_pic.hide();
		}
	},

	video: function(text) {
		video_title = $$(mytooltip.videoId)[0] || false;
		if (video_title) {
			video_title.update(text);
		}
	}
};

/**
 * Play video
 */
function playVideo(videoId) {
	if (videoId != '') {
		var video_object = $('video-block');

		var embed =
			'<object width="480" height="270">' +
            '<param id="video_object_el" name="movie" value="http://www.youtube.com/v/' + videoId + '"></param>' +
            '<param name="allowFullScreen" value="true"></param>'+
            '<param name="allowscriptaccess" value="always"></param>' +

            '<embed' +
            '    src="http://www.youtube.com/v/' + videoId + '"' +
            '    type="application/x-shockwave-flash"' +
            '    allowscriptaccess="always"' +
            '    allowfullscreen="true"' +
            '    width="480"' +
            '    height="270"' +
            '    id="video_embed_el"'+
            '></embed>' +
			'</object>'
		;

		video_object.update(embed);
	}
}

/*
*** Voting
*/

function vote(id, voting){
	new Ajax.Request( rooturl + locale + "/ajax/starsVote", {
		method: "get",
		parameters: {"id" : id, "voting" : voting},
		onSuccess: function(transport) {
			$("star-rating").update(transport.responseText);
			createCookie('article_' + id, id, 360);
		}
	});
}


function ratecomment(id, rate){
	new Ajax.Request( rooturl + locale + "/ajax/rateComment", {
		method: "get",
		parameters: {"id" : id, "rate" : rate},
		onSuccess: function(transport) {
			$("ratecomment_" + id).update(transport.responseText);
			createCookie('comment_' + id, id, 360);
		}
	});
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function speak(author) {
	return false;
}

window.onload = function() {
    var links = document.getElementsByTagName('a');
    for (var i=0;i < links.length;i++) {
        if (links[i].rel == 'external') {
            links[i].onclick = function() {
                window.open(this.href);
                return false;
            };
        }
    }
};
