/**
* Master 3.0 : 2011.08.20
* © Copyright S.A.Hashemi, All Right Reserved.
*/
//------------------Master
$(document).ready(function(){
	//------------------html-error-log
	/*$(window).error(function(msg,url,line){
		$.post("./?",{a:"error.log",msg:msg,url:url,line:line});
		return true;
	});*/
	//------------------ajax-setup
	$.ajaxSetup({cache:false});
	//------------------loading
	var l = $('#loading').ajaxStart(function(){
		l.show();
	}).ajaxSend(function(evt,request,settings){
		l.show();
	}).ajaxComplete(function(request,settings){
		l.hide();
	}).ajaxStop(function(request,settings){
		l.hide();
	}).ajaxSuccess(function(evt,request,settings){
		l.hide();
	}).ajaxError(function(event,request,settings){
		l.hide();
	});
	//------------------add-favorite
	$('#add-favorite').click(function(){
		window.external.AddFavorite(window.location.href,window.location.hostname);
	});
	//------------------
});
//------------------Menu
$.fn.menu = function(o){
	var o = $.extend({
		vertical:false
		,child:true
		,effect:1
		,speed:'fast'
	},o?o:{});
	var t = $(this);
	if($.browser.msie && parseInt($.browser.version)<7){
		t.find('ul li:first-child').css({'border-width':'0','border-style':'none'});
		if($('html').attr('dir')=='ltr'){
			t.find('li').css({'float':'left','text-align':'left'})
		}
	}
	if(o.child){
		t.find('li:has(ul) > a').not(':has(span)').append(' <span>&raquo;</span> ');
	}
	t.find('ul > li').hover(function(){
		var ul = $(this).find(' > ul');
		ul.css('display','none');
		if(o.effect==1){
			ul.slideDown(o.speed);
		}else if(o.effect==2){
			ul.fadeIn(o.speed);
		}else{
			ul.show();
		}
	},function(){
		var ul = $(this).find(' > ul');
		if(o.effect==1){
			ul.slideUp(o.speed);
		}else if(o.effect==2){
			ul.fadeOut(o.speed);
		}else{
			ul.hide();
		}
	});
	return this;
};
//------------------emergency
$.fn.emergency = function(o){
	var o = $.extend({delay:5000},o?o:{});
	var t = $(this).find('li'), i = 1, s;
	s = setTimeout(function(){
		t.hide().eq(i).fadeIn();
		i = i+1>=t.length?0:i+1;
		clearTimeout(s);
		s = setTimeout(arguments.callee,o.delay);
	},o.delay);
	return this;
};
//------------------Highlight
$.fn.highlight = function(h){
	function findText(a,b){if(a.nodeType==3)return searchText(a,b);else if(a.nodeType==1&&a.childNodes&&!(/(script|style)/i.test(a.tagName))){for(var i=0;i<a.childNodes.length;++i){i+=findText(a.childNodes[i],b)}}return 0;};
	function searchText(a,b){var c=a.data.toUpperCase().indexOf(b);if(c>=0)return highlight(a,c,b);else return 0;};
	function highlight(a,b,c){var d=document.createElement('mark');var e=a.splitText(b);var f=e.splitText(c.length);var g=e.cloneNode(true);d.appendChild(g);e.parentNode.replaceChild(d,e);return 1;};
	return this.each(function(){if(typeof h=='string')findText(this,h.toUpperCase());else for(var i=0;i<h.length;++i)findText(this,h[i].toUpperCase())});
};
//------------------
