﻿var p = 1;
var x = 1;
loca = " ";
sendb = " ";
var tt =1;
$(document).ready(function(){
	$('a[rel="category tag"]').each(function(){
		$(this).attr('title', ' ');
	});
	//alert(loca);
	txt = "<div class='postCaptionImageBottom'></div>";
	$(".wp-caption").each(function(){
		curwi = $(this).width();
		if(curwi < 220) {
			$(this).width(220);
		}
		$(this).html($(this).html()+txt);

	});
	$("#topBlogMenu").click(function() {
			$("#topBlogMenuContent").toggle('slow');
			p = p*(-1);
			showF(p);
	});

	$("#showTotalLinks").click(function(){
		
		if(x==1) {
			$("#blogroll").hide();
			txt = "";
			for(i=0; i<oldCounter; i++)
				txt = txt+code[i];
			$("#blogroll").html(txt);
			$("#blogroll").toggle('show');
			$(this).html('<li style="cursor:pointer!important;" class="liLeft">پنهان کردن</li>');
			x = 0;
			return;
		}
		else {
			$("#blogroll").hide();
			txt = "";
			for(i=0; i<10; i++)
				txt = txt+code[i];
			$("#blogroll").html(txt);
			$("#blogroll").toggle('show');
			$(this).html('<li style="cursor:pointer!important;" class="liLeft">ادامه</li>');
			x = 1;
			return;
		}
	});

	$(".sendToLink").click(function(){
		//alert($(this).attr('sendback'));
		if($(this).attr('sendback')==undefined){
			sendb = "sendto";
			//alert('ddd');
		}
		else
			sendb = $(this).attr('sendback');
		red('topp');
		jQuery("html").css("overflow","hidden");
		ur = $(this).attr('nav');
		ti = $(this).attr('ti');
		//alert(ur+ti);
		$(".sendtolinkss").each(function(){
			//alert(ur+ti);
			str = $(this).attr('href');
			//alert(str);
			str = str.replace('[wevrioturl]',ur)
			str = str.replace('[webriottitle]',ti)
			$(this).attr('href',str);
		});
		var de = document.documentElement;
		var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
		var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;	
		
		$("#freezer").height(h);
		$("#freezer").width(w);
		$("#freezer").show();
//		$("#sendText").text('salan');
		$("#sendText").show('slow');
		$("#sendToBox").show('slow');
//		alert(w+":"+h);
	});
		$("#sendToC").click(function(){
			$("#freezer").hide();
			$("#sendToBox").hide();
			jQuery("html").css("overflow","");
			red(sendb);
			
		});
});
function setLoca(x){
		loca = x;
}
function no(){
	return false;
}
function red(x) {
		//alert(loca);
		window.location=loca+"#"+x;
}
function showF(p){
	if(p==-1) {
		$("#topBlogMenu").removeClass("topBlogMenuVisited");
		$("#topBlogMenu").addClass("topBlogMenuHover");
	}
	if(p==1) {
		$("#topBlogMenu").removeClass("topBlogMenuHover");
		$("#topBlogMenu").addClass("topBlogMenuVisited");
	}
}

	var oldurl = new Array();
	var oldCounter = 0;
	var code= new Array();
	var codeCount=0;
	
function buildContent(blog) {
	var txt="";
	if (!blog || !blog.value) return;
	//var container=document.getElementById("blogroll");
	//alert(blog.count);
	
	for (var i = 0; i < blog.count; i++) {
		var item = blog.value.items[i];
		//alert(item.blogTitle);
		if (oldurlCheck(item.blogUrl)) {
			code[codeCount]="<li class='liLeft'><a href='"+item.blogUrl+"'>"+item.blogTitle+"</a></li>";
			if(codeCount<10)
				txt=txt+code[codeCount];
			codeCount++;
			
			//alert(codecode);
		}
		oldurl[oldCounter]=item.blogUrl;
		oldCounter++;
	}
	$("#blogroll").html(txt);
	
}
function oldurlCheck(url){
	for(var i=0; i<oldCounter; i++){
		if(oldurl[i]==url)
			return false;
	}
	return true;
}