/*
*	Written By S.A.Rahman Mousavian ( Mousavian.rahman@gmail.com , vhr-design.com)
*	@ Rahnema Co
*	Finished @ 1387/06/30  2008/25/08
*/
var _loadedHash=null;
var lockLink=false;
$(document).ready(function(){
	var m=$("#content");
	if(typeof loading_text=="undefined"||loading_text=='undefined'||loading_text=='')loading_text='Loading...';
	$('<div id="loading" style="position:fixed;  _position:absolute;  _top:expression(eval(document.body.scrollTop));  font-family:tahoma;  z-index:100;  top:0px;  height:28px;  width:100px;  background:#666666;  color:#FFFFFF;  font-size:10px;  opacity:0.9;  '+loading_align+':15px;  "><img src="templates/theme1/images/loading13.gif">&nbsp; '+loading_text+'</div>').appendTo("body");
	$("#loading > img").css({'width':'25px','float':'right'});
	$("#loading").ajaxStart(function(){	lockLink=true;	$(this).show(); })
	.ajaxStop(function(){ lockLink=false; $(this).hide(); });
	if(location.hash){ n(location.hash); }
	$("a").livequery('click',function(){
		var h=$(this).attr("href");
		if(exceptionLinks($(this))==1) return true;
		if(exceptionLinks($(this))==0)return false;
		if(!lockLink){
			$.get(h,{'ajax_check':'true'},function(a){
				m.hide().empty().append(a).show();
				try{$.scrollTo("BODY",2000);}catch(e){}
			});
			q(h);
		}return false;
	});
	$('form').livequery('submit',function(){
		var b=$(this)[0].method.toUpperCase();
		var c=$(this).attr('action');
		var d=$(this).attr('name');
		var f=$(this).find('input').serialize();
		if($(this).find('textarea').serialize()!='')
			f+='&'+$(this).find('textarea').serialize();
		f+='&ajax_check=true&'+$(this).find('select').serialize();
		if(b=='') b='POST';
		switch(b){
			case'POST':
				$.post(c,f,function(a){
					m.fadeOut().empty().append(a).fadeIn();
					try{$.scrollTo("BODY",1200)}catch(e){}
					if(typeof check4update!="undefined")check4update(c)
				});
			break;
			case'GET':
				$.get(c,f,function(a){
					m.fadeOut().empty().append(a).fadeIn();
					try{$.scrollTo("BODY",1200)}catch(e){}
					if(typeof check4update!="undefined")check4update(c)
				});
			break
		}
		return false
	});
	function n(b){
		h=b;
		if(h.indexOf(':')>0)
			h=h.replace(/^#/,'').replace(':','.php?').replace('/','&');
		else{
			h=h.replace(/^#/,'');
			h+='.php';
		}
		$.get(h,{'ajax_check':'true'},function(a){
			m.html(a)
		});
		if($.browser.msie)
			_loadedHash=o.contentWindow.document.location.hash;
		else _loadedHash=b
	};
	
	if($.browser.msie){
		var o=$('<iframe style="display: none"></iframe>').appendTo("BODY").get(0);
		var p=o.contentWindow.document;
		p.open();
		p.close();
		setInterval(function(){var h=o.contentWindow.document.location.hash;
		if((_loadedHash!=null)&&(_loadedHash!=h)) n(h)},500)}else if($.browser.mozilla){
			setInterval(function(){
				if((_loadedHash!=null)&&(_loadedHash!=location.hash))n(location.hash)},500)
		}
		function q(b){
			var c=(b.indexOf('?')>0)?b.indexOf('?')+1:b.length+1;
			var d=b.length; var e=b.indexOf('.php')+1; var f=(c>1)?c-1:b.length;
			var g=b.substring(c,d); var h='';
			var k=b.substring(b.substring(0,f).lastIndexOf('/')+1,f).replace('.php','');
			if(g.length>0){
				var a=explodeArray(g,"&");
				for(var i=0,j=a.length; i<j; i++)
					h+=a[i]+'/';
				h='#'+k+':'+h
			}else{h='#'+k}
			if($.browser.msie){
			var l=o.contentWindow.document; l.open(); l.close(); l.location.hash=h}location.hash=h; _loadedHash=h
		}
});


$(window).load(function(){$("#loading").css({'display':'none'}); });

function explodeArray(a,b){tempArray=new Array(1); var c=0; var d=new String(a); while(d.indexOf(b)>0){tempArray[c]=d.substr(0,d.indexOf(b)); d=d.substr(d.indexOf(b)+1,d.length-d.indexOf(b)+1); c=c+1}tempArray[c]=d; return tempArray}



































