﻿//==========================================TOGGLE AND FOOTER DETAILES==========================================================//
$(document).ready(function(){

	$(".toggle_container").show();
	$(".trigger").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});
	$(".trigger").click(function(){
		$(this).next(".toggle_container").slideToggle("slow,");
	});
	
	$(".mbody_recent_comments").show();
	$(".trigger2").toggle(function(){
		$(this).addClass("active"); 
		}, function () {
		$(this).removeClass("active");
	});
	$(".trigger2").click(function(){
		$(this).next(".mbody_recent_comments").slideToggle("slow,");
	});

	
	
	$("img", ".footerdetails").fadeTo(10000, 1);
	$("img", ".footerdetails").hover(function() {
		$(this).stop().animate({ opacity: 0.6 }, 1);
		}, function() {
		$(this).stop().animate({ opacity: 1 }, 600);
	});
	
	$("img", ".postdetails").fadeTo(10000, 1);
	$("img", ".postdetails").hover(function() {
		$(this).stop().animate({ opacity: 0.6 }, 1);
		}, function() {
		$(this).stop().animate({ opacity: 1 }, 600);
	});


});


//=========================================SEARCH FIELD=========================================================//
this.searchfield = function(){
	
	var id = "searchfield";
	var defaultText = "جستجو...";	

	var field = document.getElementById(id);	
	var classInactive = "sf_inactive";
	var classActive = "sf_active";
	var classText = "sf_text";
	this.safari = ((parseInt(navigator.productSub)>=20020000)&&(navigator.vendor.indexOf("Apple Computer")!=-1));
	if(field && !safari){
		field.value = defaultText;
		field.c = field.className;		
		field.className = field.c + " " + classInactive;
		field.onfocus = function(){
			this.className = this.c + " "  + classActive;
			this.value = (this.value == "" || this.value == defaultText) ?  "" : this.value;
		};
		field.onblur = function(){
			this.className = (this.value != "" && this.value != defaultText) ? this.c + " " +  classText : this.c + " " +  classInactive;
			this.value = (this.value != "" && this.value != defaultText) ?  this.value : defaultText;
		};
	};
		
	this.getKeyCode = function(e){
		var code;
		if (!e) var e = window.event;
		if (e.keyCode) code = e.keyCode;
		return code;
	};
	
};

// script initiates on page load. 

this.addEvent = function(obj,type,fn){
	if(obj.attachEvent){
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event );}
		obj.attachEvent('on'+type, obj[type+fn]);
	} else {
		obj.addEventListener(type,fn,false);
	};
};
addEvent(window,"load",searchfield);