///////////////////////////////////////// SLIDE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
(function($) {

$.effects.slide = function(o) {

	return this.queue(function() {

		// Create element
		var el = $(this), props = ['position','top','left'];

		// Set options
		var mode = $.effects.setMode(el, o.options.mode || 'show'); // Set Mode
		var direction = o.options.direction || 'up'; // Default Direction

		// Adjust
		$.effects.save(el, props); el.show(); // Save & Show
		$.effects.createWrapper(el).css({overflow:'hidden'}); // Create Wrapper
		var ref = (direction == 'up' || direction == 'down') ? 'top' : 'left';
		var motion = (direction == 'up' || direction == 'left') ? 'pos' : 'neg';
		var distance = o.options.distance || (ref == 'top' ? el.outerHeight({margin:true}) : el.outerWidth({margin:true}));
		if (mode == 'show') el.css(ref, motion == 'pos' ? -distance : distance); // Shift

		// Animation
		var animation = {};
		animation[ref] = (mode == 'show' ? (motion == 'pos' ? '+=' : '-=') : (motion == 'pos' ? '-=' : '+=')) + distance;

		// Animate
		el.animate(animation, { queue: false, duration: o.duration, easing: o.options.easing, complete: function() {
			if(mode == 'hide') el.hide(); // Hide
			$.effects.restore(el, props); $.effects.removeWrapper(el); // Restore
			if(o.callback) o.callback.apply(this, arguments); // Callback
			el.dequeue();
		}});

	});

};

})(jQuery);

////////////////////////////////////////Blind\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

(function($) {

$.effects.blind = function(o) {

	return this.queue(function() {

		// Create element
		var el = $(this), props = ['position','top','left'];

		// Set options
		var mode = $.effects.setMode(el, o.options.mode || 'hide'); // Set Mode
		var direction = o.options.direction || 'vertical'; // Default direction

		// Adjust
		$.effects.save(el, props); el.show(); // Save & Show
		var wrapper = $.effects.createWrapper(el).css({overflow:'hidden'}); // Create Wrapper
		var ref = (direction == 'vertical') ? 'height' : 'width';
		var distance = (direction == 'vertical') ? wrapper.height() : wrapper.width();
		if(mode == 'show') wrapper.css(ref, 0); // Shift

		// Animation
		var animation = {};
		animation[ref] = mode == 'show' ? distance : 0;

		// Animate
		wrapper.animate(animation, o.duration, o.options.easing, function() {
			if(mode == 'hide') el.hide(); // Hide
			$.effects.restore(el, props); $.effects.removeWrapper(el); // Restore
			if(o.callback) o.callback.apply(el[0], arguments); // Callback
			el.dequeue();
		});

	});

};

})(jQuery);

/////////////////////////////////////// Modal \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
document.write(
	'<div id="faraModalDiv" class="faraABSDIV">' +
	'	<div class="faraModalContent" id="Modal">' +
	'		<div class="faraModalTitle">' +
	'			<div class="faraCloseModal">' +
	'				<img src="images/close.jpg" width="20" height="20" alt="close" style="cursor: pointer;" onclick="hideModal();" />' +
	'			</div>' +
	'			<div class="faraTitBar" id="ModalTitle"></div>' +
	'			</div>' +
	'		<div id="faraINNER"></div>' +
	'	</div>' +
	'</div>'
	);
function tModal() {
	$('#faraModalDiv').toggle('slide',{},600);
}
function showModal(width, title, address) {
	document.getElementById('ModalTitle').innerHTML = title;
	document.getElementById('Modal').style.width = width + 'px';
	$.blockUI({ 
		//theme:     true, 
        //title:    'This is your title', 
        message:  null
	});
	var waitMsg = '<div class="pbLoadingDiv"><img src="images/loading.gif" alt="loading" /><br />در حال بارگذاری</div>';
	$('#faraINNER').html(waitMsg);
	success: $.post(address, { id: "most" },
		function(data){
			document.getElementById('faraINNER').style.display= 'none';
			$('#faraINNER').html(data);
			$('#faraINNER').toggle('blind',{},800);
		}
	);
	setTimeout(tModal, 600);
	//setTimeout($('.blockUI').toggle('slide',{},600), 3000);
}
function unblock() {
	$.unblockUI();
}
function hideModal() {
	$('#faraModalDiv').toggle('slide',{},600);
	setTimeout(unblock, 600);
}

///////////////////////////////////////////////////////// Float Modal
$(document).ready(main);
function main()
{
    $("#faraModalDiv").makeFloat({x:"current",y:"current",speed: 'fast'});
}
////////////////////////////////////////////////////////// Load Modules
window.onload = loadall;
function loadCommenting() {
	var waitMsg = '<div class="pbLoadingDivB"><img src="images/loading.gif" /><br />در حال بارگذاری اطلاعات.</div>';
	$('#pbLinkBox').html(waitMsg);
	success: $.post("commenting.php", { started: 'show' },
		function(data){
			document.getElementById('pbLinkBox').style.display= 'none';
			$('#pbLinkBox').html(data);
			$('#pbLinkBox').toggle('blind',{},800);
			loadComments(1);
		}
	);
}
function sendComment() {
	var waitMsg = '<div class="pbLoadingDivC" style="width: 340px; margin: auto;"><img src="images/loading.gif" /><br />در حال بررسی اطلاعات.</div>';
	$('#pbResult').html(waitMsg);
	$('#pbResult').toggle('blind',{},800);
	success: $.post("sendcomment.php", { name: $('#sName').val(), email: $('#sEmail').val(), blog: $('#sBlog').val(),msg: $('#sMsg').val() },
		function(data){
			document.getElementById('pbResult').style.display= 'none';
			$('#pbResult').html(data);
			$('#pbResult').toggle('blind',{},800);
			loadComments(1);
		}
	);
}
function loadComments(startp) {
	var waitMsg = '<div class="pbLoadingDivB"><img src="images/loading.gif" /><br />در حال بارگذاری نظرات.</div>';
	$('#pbIdeaDiv').html(waitMsg);
	success: $.post("comments.php", { start: startp },
		function(data){
			document.getElementById('pbIdeaDiv').style.display= 'none';
			$('#pbIdeaDiv').html(data);
			$('#pbIdeaDiv').toggle('blind',{},800);
		}
	);
}
function loadFreeLinks(startP) {
	var waitMsg = '<div class="pbLoadingDivB"><img src="images/loading.gif" alt="loading" /><br />در حال بارگذاری</div>';
	$('#pbLinkBox').html(waitMsg);
	success: $.post("linklist.php", { start: startP },
		function(data){
			document.getElementById('pbLinkBox').style.display= 'none';
			$('#pbLinkBox').html(data);
			$('#pbLinkBox').toggle('blind',{},800);
		}
	);
}
function loadSearchQuery(startP, queryP) {
	var waitMsg = '<div class="pbLoadingDivB"><img src="images/loading.gif" alt="loading" /><br />در حال بارگذاری</div>';
	$('#pbLinkBox').html(waitMsg);
	success: $.post("linklist.php", { start: startP, q: queryP, pid: 'Search' },
		function(data){
			document.getElementById('pbLinkBox').style.display= 'none';
			$('#pbLinkBox').html(data);
			$('#pbLinkBox').toggle('blind',{},800);
		}
	);
}
function loadall() {
	var waitMsg = '<div class="pbLoadingDivB"><img src="images/loading.gif" alt="loading" /><br />در حال بارگذاری</div>';
	$('#pbLinkBox').html(waitMsg);
	success: $.post("linklist.php", { name: "farabitActionLibraryForJquery" },
		function(data){
			document.getElementById('pbLinkBox').style.display= 'none';
			$('#pbLinkBox').html(data);
			$('#pbLinkBox').toggle('blind',{},800);
			loadReport();
			loadSearch();
		}
	);
}
function loadSearch() {
	success: $.post("search.php", { name: "farabitActionLibraryForJquery" },
		function(data){
			document.getElementById('pbSearchFormCover').style.display= 'none';
			$('#pbSearchFormCover').html(data);
			$('#pbSearchFormCover').toggle('blind',{},800);
		}
	);
}
function loadReport() {
	var waitMsg = '<div class="pbLoadingDiv"><img src="images/loading.gif" alt="loading" /><br />در حال بارگذاری</div>';
	$('#pbReport').html(waitMsg);
	success: $.post("report.php", { name: "farabitActionLibraryForJquery" },
		function(data){
			document.getElementById('pbReport').style.display= 'none';
			$('#pbReport').html(data);
			$('#pbReport').toggle('blind',{},800);
			loadSpecial();
		}
	);
}
function loadSpecial() {
	var waitMsg = '<div class="pbLoadingDiv"><img src="images/loading.gif" alt="loading" /><br />در حال بارگذاری</div>';
	$('#pbSpecial').html(waitMsg);
	success: $.post("list.php", { id: "spc" },
		function(data){
			document.getElementById('pbSpecial').style.display= 'none';
			$('#pbSpecial').html(data);
			$('#pbSpecial').toggle('blind',{},800);
			loadRand();
		}
	);
}
function loadRand() {
	var waitMsg = '<div class="pbLoadingDiv"><img src="images/loading.gif" alt="loading" /><br />در حال بارگذاری</div>';
	$('#pbRand').html(waitMsg);
	success: $.post("list.php", { id: "random" },
		function(data){
			document.getElementById('pbRand').style.display= 'none';
			$('#pbRand').html(data);
			$('#pbRand').toggle('blind',{},800);
			loadMost();
		}
	);
}
function loadMost() {
	var waitMsg = '<div class="pbLoadingDiv"><img src="images/loading.gif" alt="loading" /><br />در حال بارگذاری</div>';
	$('#pbMost').html(waitMsg);
	success: $.post("list.php", { id: "most" },
		function(data){
			document.getElementById('pbMost').style.display= 'none';
			$('#pbMost').html(data);
			$('#pbMost').toggle('blind',{},800);
			loadADS();
		}
	);
}
function loadADS() {
	var waitMsg = '<center><img src="images/loading.gif" alt="loading" /><br />در حال بارگذاری</center>';
	$('#pbADSA').html(waitMsg);
	success: $.post("news.php", { id: "most" },
		function(data){
			$('#pbADSA').html(data);
		}
	);
}
function sendNewLink() {
	var waitMsg = '<center><br \/><img src="images/loading.gif" \/><br \/>در حال ثبت لینک، شکیبا باشید<\/center>';
	$('#pbError').html(waitMsg);
	success: $.post("sendnow.php", { 
			tit:  $('#name').val(), 
			url:  $('#address').val(), 
			cat:  $('#categ').val(), 
			date: $('#date').val()
		},
		function(data){
			document.getElementById('pbError').style.display= 'none';
			$('#pbError').html(data);
			$('#pbError').toggle('blind',{},800);
		}
	);
}