﻿function showsubmenu(e) {
	var width = (e.parent('li').find('div.submenu2').attr('width')) ? e.parent('li').find('div.submenu2').attr('width') : e.parent('li').find('div.submenu2').outerWidth();
	e.parent('li').find('div.submenu2').attr('width', width);
	e.parent('li').addClass('active');
	e.parent('li').find('div.submenu2 div').css({'width':''+(width-4)+'px'});
	e.parent('li').find('div.submenu2').show('fast');
}

function hidesubmenu(e) {
	e.stop().animate({'padding-right':'15px', 'padding-left':'20px'}, 200);
	e.parent('li').removeClass('active');
	e.parent('li').find('div.submenu2').hide('fast');
	e.parent('li').find('div.submenu2 div').css({'width':'auto'});
}

function hideallsubmenus() {
	$('div.submenu ul li.active a').stop().animate({'padding-right':'15px', 'padding-left':'20px'}, 200);
	$('div.submenu2').hide('fast');
	$('div.submenu ul li').removeClass('active');
	$('div.submenu2 div').css({'width':'auto'});
}

function animateResults(t){

	$(t).find('div.bar').each(function(){
		var bar_width = $(this).find('div').css('width');
		$(this).find('div').css('width', '0').animate({ width: bar_width }, 1000);
	});
	return false;
}

function pollResults(pid,rel,task){
	var loader = $('#poll_loader');
	var pollcontainer = $(rel);
	loader.show();
	pollcontainer.html("");
	$.get('http://asosat.tv/ajax/poll.php', 'id='+pid+'&action=view&task='+task, function(data){
		pollcontainer.html(data);
		loader.hide();
		animateResults(pollcontainer);
	});
}

function closeVideoBox(){
	$('div.videobox_overlay').unbind('click');
	$('div.videobox_overlay').remove();
	$('div.videobox').remove();
}

function setVideoBoxPosition(){
	var winWidth = $(window).width();
	var winHeight = $(window).height();

	var vTop = ((winHeight-$('div.videobox').outerHeight())/2);
	var vLeft = ((winWidth-$('div.videobox').outerWidth())/2);

	$('div.videobox_overlay').css({'width': winWidth+'px', 'height': winHeight+'px', opacity:'0.6'});
	$('div.videobox').css({'top': vTop+'px', 'left': vLeft+'px'});
}

function getResults(query, width, top, left){
	$.get('http://asosat.tv/ajax/search.php', 'q='+encodeURIComponent(query), function(response){
		$('body').append('<div class="search_results" dir=rtl style="width:'+width+'px; top:'+top+'px; left:'+left+'px">'+response+'</div>');
	});
}

function removeResults(){
	$('div.search_results').remove();
}

function removeComment(offset){
	var cid = $(offset).attr('cid');
	var pid = $(offset).attr('pid');
	var type = $(offset).attr('type');
	var page = $(offset).attr('page');
	if(confirm("دڵنیای  دەتهەوێ ئەم سەرنجه بسڕێوە؟")){
		$.post('http://asosat.tv/ajax/removecomment.php', 'pid='+pid+'&cid='+cid+'&type='+type, function(){
			$(offset).parents('div.comment').remove();
		});
		$.get('http://asosat.tv/ajax/comments.php', 'page='+page+'&id='+pid+'&type='+type, function(response){
			$('div.comments').html(response);
		});
	}
}

function commentsPage(page, id, type){
	$.get('http://asosat.tv/ajax/comments.php', 'page='+page+'&id='+id+'&type='+type, function(response){
		$('div.comments').html(response);
	});
}

function moveCalendar(t, tar){
	$.get('http://asosat.tv/ajax/calendar.php', 'time='+t+'&target='+encodeURIComponent(tar), function(response){
		$(tar).html(response);
	});
}
