function stopPlayers(id){
	$('div.audio_thumb').each(function(i,currItem){
		currID = $(this).find('object').attr('id');
		if (('player_'+id) != currID){
			document.getElementById(currID).onStop();
			console.log(currID);
		}
	})
}



$(document).ready(function(){
	$('#sectionNav li a.main_section').corner("top 10px cc:#737373");
	$('#sectionNav li a.main_section').each(function(e,i){
		$(this).hover(
			function(p){
				if ($(this).parent().hasClass('selected')){
					//it does nothing;
				}else{
					$('div.subsection:visible').hide();
					$('#submenus').css("left",this.offsetLeft+40);		
					$('div.subsection').eq(e).show();
					$('#sectionNav li:not(li.selected) a.main_section').css({"background-color":"#c00","color":"yellow"});
					$(i).css({"background-color":"#f00","color":"#fff"});
				}
			},
			function(){}
		);
	});

	$('div.subsection').each(function(e,i){
		$(this).hover(
			function(){},
			function(){
				$('div.subsection').hide();
				$('#sectionNav li:not(li.selected) a.main_section').css({"background-color":"#c00","color":"yellow"});
			}
		);
	});

	$('body p.mailOnly').remove();

	$('#goPopup').click(function(e){
		window.open("/popup", "Popup", "width=740,height=510,toolbar=no,location=no,directories=no,status=no,menubar=no, scrollbars=no,resizable=no,copyhistory=no");
		return false;
	});
/*
	$('#slideshow').cycle({ 
		fx:    'fade', 
		timeout: 5000,
		next:  '.next', 
		prev:  '.prev'
	});	

*/
	//Slideshow on homepage
	/*$('#sectionPromo-special > script').ready(function() {
		$c = $('#sectionPromo-special > iframe').contents();
		var ps = {};
		ps.title = $c.find('#nume_produs');
		ps.head = $c.find('#nume_mic');
		console.dir(ps);
	});*/
	if($('body').hasClass('homepage')) {
		$('#wide > .s-nav > .s-infos > .domainInfo:eq(0)').addClass('current').show();
		$('#slideshow').cycle({
			fx: 'scrollHorz',
			pause: 1,
			timeout: 5000,
			next: '#wide > .s-nav > .s-next',
			prev: '#wide > .s-nav > .s-prev',
			prevNextClick: function() {
				return false;
			},
			pager: '#wide > .s-nav > .s-pager',
			pauseOnPagerHover: 1,
			before: function(currSlideElement, nextSlideElement, opts, forwardFlag) {
				var $i = $('iframe', currSlideElement);
				if($i.size() == 1) {
					$i.hide();
				}
				if(currSlideElement.id != nextSlideElement.id) {
					$('#wide > .s-nav > .s-infos > .current').fadeOut(100).removeClass('current');
					$('#domainInfo'+nextSlideElement.id.replace('sectionPromo', '')).addClass('current').fadeIn(500);
				}
			},
			after: function(currSlideElement, nextSlideElement, opts, forwardFlag) {
				var $i = $('iframe', nextSlideElement);
				if($i.size() == 1) {
					$i.fadeIn(100);
				}
			}
		});
	}

	$('div.boxNewsSlideshow').each(function() {
			$(this).find('ol.slideshow li').each(function(i, currentItem) {
					if(i == 0) {
							$(this).addClass('current');
					}
					$(this).mouseover(function() {
							if(!$(currentItem).hasClass('current')) {
									$(currentItem).parent().children('.current').removeClass('current');
									$(currentItem).addClass('current');
							}
							return false;
					});
			});
	});
	
        
	if(!$('body').hasClass('homepage')) {
		$('#slideshow').each(function() {
			rdxBoxesCounter = 0;
			$('#slides').each(function() {
				$(this).children('div').each(function(i, currentDiv) {
					rdxBoxesCounter++;
				});
				if(rdxBoxesCounter == 0) {
					//
				}
				else { 
					$('#slideshow').show();
					if(rdxBoxesCounter > 1) {
						$('#slideshow .prev').show();
						$('#slideshow .next').show();
						$(this).cycle({
								fx:			'fade',
								pause:		1,
								timeout:	5000,
								next:		'#slideshow .next',
								prev:		'#slideshow .prev'
							});
					}
				}
			});
		});
	}


	// Modify FontSize	
	$('#primary p.fontSize').each(function() {
		var fontSizes = {
			head: ['12px', '13px', '14px', '15px', '16px'],
			body: ['12px', '13px', '14px', '15px', '16px']/*,
			observations: ['12px', '13px', '14px', '15px', '16px']*/
		}
		var currentSize = 0;
		$(this).children('a').each(function() {
			var modifyFontSize = function(a) {
				if(a == 'plus' && currentSize + 1 < fontSizes.body.length) {
					var newFontSize = currentSize + 1;
				}
				else if(a == 'minus' && currentSize - 1 >= 0) {
					var newFontSize = currentSize - 1;
				}
				if(a && newFontSize) {
					$('#article #head *').css({fontSize: fontSizes.head[newFontSize]});
					$('#article #body *').css({fontSize: fontSizes.body[newFontSize]});
					/*$('#article #observations *').css({fontSize: fontSizes.observations[newFontSize]});*/
					currentSize = newFontSize;
				}
			}
			$(this).click(function() {
				var action = null;
				if($(this).hasClass('minus')) {
					action = 'minus';
				}
				else if($(this).hasClass('plus')) {
					action = 'plus';
				}
				if(action != null) {
					modifyFontSize(action);
				}
				return false;
			});
		});
	});
});


function showPromo(promo){
	clearTimeout(wait);
	if(!promo){
			var i = 1+ Math.round((totalpromos-1) * Math.random());
			promo=i;
			promoname="promo"+i;
			promonavname="promonav"+promo;
	} else {
			promoname="promo"+promo;
			promonavname="promonav"+promo;
	}
	currentpromoname='promo'+currentpromo;
	document.getElementById(currentpromoname).style.display='none';
	if(totalpromos > 1){
			currentpromonavname='promonav'+currentpromo;
			document.getElementById(currentpromonavname).className="";
	}
	document.getElementById(promoname).style.display='block';
	if(totalpromos > 1) { document.getElementById(promonavname).className='selected'; }
	currentpromo=promo;
	wait=setTimeout("nextPromo()",5000);
} 	 

currentpromoname="promo1";
currentpromonavname="promonav1";
currentpromo=1;
totalpromos=1;
wait=0;
  	 
  	 
function nextPromo(){ 	 
	if(currentpromo < totalpromos) {
		showPromo(currentpromo+1); 	 
	} else {
		showPromo(1);
	}
}
  	 
slideshow=0; 	 
wait2=0; 	 
nexturl=""; 


var ifCN = 'focused'; 	 
function focusableInput() { 	 
        for(var i=0, j=arguments.length; i<j; i++) { 	 
                var obj = document.getElementById(arguments[i]); 	 
                obj.onfocus = inputFocus; 	 
                obj.onblur = inputBlur; 	 
        } 	 
} 	 
function inputFocus() { 	 
        if (this.value == this.defaultValue) this.value = ''; 	 
        if (this.className.length > 0) this.className += ' ' + ifCN; 	 
        else this.className = ifCN; 	 
} 	 
function inputBlur() { 	 
        if (this.value == '') this.value = this.defaultValue; 	 
        var reCN = this.className.match(new RegExp(' ?' + ifCN + ' ?')); 	 
        if (reCN) this.className = this.className.replace(reCN, ''); 	 
} 	 
  	 
  	 
function registerFocus(objId) { 	 
        var theLinks = document.getElementById(objId).getElementsByTagName('a'); 	 
        for (var i=0; i<theLinks.length; i++) { 	 
                theLinks[i].onclick = function() { 	 
                        var linkHref; 	 
                        if (linkHref = this.getAttribute('href').match(uriRE)) { 	 
                                document.getElementById(linkHref[1]).scrollIntoView(); 	 
                                document.getElementById(linkHref[1]).focus(); 	 
                                return false; 	 
                        } 	 
                } 	 
        } 	 
} 	 

function playSong(str,tit,swfID){
	var me;
	if(navigator.appName.indexOf("Microsoft") != -1){
          me = window[swfID];
     }else{
          me = document[swfID];
     } 
	 if ($('body').hasClass('domain')) {
		 tit = 'Jurnal ' + tit;
	 } 
     me.onChange(str,tit);
	 showEmbedSong(str,tit);
}

function showEmbedSong(str,tit){
	 var embedCode = "<object type='application/x-shockwave-flash' data='http://www.europafm.ro/&amp;res/swf/podcast/podcastEmbed.swf' width='410' height='75' id='podcast' menu='false'><param name='allowScriptAccess' value='always' /><param name='movie' value='http://www.europafm.ro/&amp;res/swf/podcast/podcastEmbed.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='scale' value='noscale' /><param name='allowFullScreen' value='true' /><param name='menu' value='false' /><param name='flashVars' value='songFile="+str+"&songText="+tit+"' /></object>";
	 document.getElementById('embedTxt').value = embedCode;
}

function playMovie(swfID,file,title){
	var me;
	if(navigator.appName.indexOf("Microsoft") != -1){
          me = window[swfID];
     }else{
          me = document[swfID];
     }
     me.PlayMovie(file);
	 document.getElementById("movieTitle").innerHTML = title;
	 document.getElementById('embedTxt').value = "<object type='application/x-shockwave-flash' data='http://www.europafm.ro/&amp;res/swf/ngxplayer/ngxplayerEmbed.swf' width='542' height='407' id='ngxPlayer'><param name='allowScriptAccess' value='always' /><param name='movie' value='http://www.europafm.ro/&amp;res/swf/ngxplayer/ngxplayerEmbed.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='scale' value='noscale' /><param name='allowFullScreen' value='true' /><param name='flashVars' value='stream="+file+"'/></object>";
}




$(document).ready(function(){

	$('div.boxFunction ul.related li div.audio_thumb').each(function(i,el){
		var myTitle =  $(el).prev();
		myTitle.css('width', (myTitle.width() - 25) +'px');
		myTitle.css('float', 'left');
		return true;
	});

	$('#podcaster ul li a').click(function (e) {
		playSong(this.href.replace('&files','%26files'),$(this).text(), 'podcast');
		e.preventDefault();
		return false;
	});

	$('#audio ul li div.audioFile a').click(function (f) {
		playSong(this.href.replace('&files','%26files'),$(this).text(), 'podcast','audio');
		f.preventDefault();
		return false;
	});
	
	$('#video_playlist li a').click( function (e) { 
		playMovie('ngxPlayer',this.href,$(this).text());
		e.preventDefault();
	})
});

/**
 * Podcast
 */
$(function() {
	$('#podcasterFormDate').datepicker({
		showOn: 'button',
		buttonText: 'Arhiva',
		mandatory: true,
		changeFirstDay: false,
		firstDay: 1,
		dateFormat: 'yy-mm-dd',
		onSelect: function (dateText) {
			$('#podcasterForm').submit();
		}
	});
});

/**
* Link-uri cu blank in footer si service
*/
$(function(){
	$("#services ul li.service a,#copylinks li a").attr("target","_blank");
});



/**
* Icon top-uri
*/
$(function(){
	$("ul.topuri li.new div.audio_file p.podcast").text("NOU").css({"padding-top":"4px","width":"30px","font-weight":"bold","color":"#0566FF"});
	$("ul.topuri li.new div.audio_file ").css("width","55px");
});

/**
* Link-uri din comments
*/

$(function(){
	if ($("body.article #article div.comments ol").hasClass("comments")){
		$("body.article #article div.comments ol div.message p").each(function(i,e){
			var currText = $(this).text();
			currText = linkify_plain(currText);
			$(this).html(currText);
		});
	}
});

function linkify_plain(text){
	if( !text ) return text;
	text = text.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
		function(url){
			nice = url;
			if( url.match('^https?:\/\/') ){
				nice = nice.replace(/^https?:\/\//i,'');
			}
			else url = 'http://'+url;
			return '<a target="_blank" rel="nofollow" href="'+ url +'">'+ nice.replace(/^www./i,'') +'</a>';
		});
	return text;
}

$(function() {
	$('<span/>', {
		id: 'efm-10ani',
		css: {
			width: '81px',
			height: '87px',
			position: 'absolute',
			top: '80px',
			left: '50%',
			marginLeft: '-568px',
			zIndex: '499',
			background: 'url("/&res/img/backgrounds/efm-10ani.png") no-repeat'
		}
	}).appendTo('body');
});