
function console_log(a){
	if(console && console.log)console.log(a);
}


rx=new RegExp(/http:\/\/[a-zA-Z0-9\.\-]*\/(.*)/);
if(rx){
	rs=rx.exec(document.location);
	if(rs){
		rs=rs[1];
		rx=new RegExp(/[a-z]*\.php\/(.*)/);
		document.route=rx.exec(rs)
		//console_log('common.js, 8');console_log(document.route);
		if(document.route){
			document.route=document.route[1];
		}
	};
}



function include(destination) {
	var e=window.document.createElement('script');
	e.setAttribute('src',destination);
	window.document.body.appendChild(e);
}
/*
document.write('<script type="text/javascript" src="/js/tinymce/jquery.tinymce.js"></script>');
document.write('<script type="text/javascript" src="/js/jquery_contextmenu.js"></script>');
document.write('<script type="text/javascript" src="/js/jquery_uploadify.js"></script>');
document.write('<script type="text/javascript" src="/js/swfobject.js"></script>');
document.write('<script type="text/javascript" src="/js/jquery_resourcehandler.js"></script>');
/**/
//some basic site-initalizing functions----------------------------------------
$(document).ready(function(){
	a=document.getElementsByTagName('textarea');
	if(a.length){	
		$('textarea[wysiwyg=1]').tinymce({
			script_url : '/js/tinymce/jscripts/tiny_mce/tiny_mce.js',
			theme : "advanced",
			elements : 'absurls',
			theme : "advanced",
			plugins : 'advlink,advimage',
			relative_urls : false,			
			plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",
			// Theme options
			theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
			theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
			//theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,
			content_css : "/css/content.css",
			// Drop lists for link/image/media/template dialogs
			template_external_list_url : "lists/template_list.js",
			external_link_list_url : "lists/link_list.js",
			external_image_list_url : "lists/image_list.js",
			media_external_list_url : "lists/media_list.js",
		});			
		var jqreshandler=new JQueryResourceHandler('resources');
	};
	jqdtfix=new jquerydivvedtablefix();
	
	$('td.topmenu').hover(
			function() { $('div', this).stop(0,1).fadeIn(300); },
			function() { $('div', this).stop(0,1).fadeOut(300); }
		);	
});

jquerydivvedtablefix=function(){
	var triggertimer=0;
	jquerydivvedtablefix.prototype.apply();
	//triggertimer=setInterval('jquerydivvedtablefix.prototype.apply()',1);
}

jquerydivvedtablefix.prototype.apply=function(){
	$('.table').each(function(){
		var widths=new Array();
		$(this).children('.table_row').each(function(){
			i=0;
			$(this).children('.table_cell').each(function(){
				if(!widths[i])widths[i]=0;
				if(widths[i]<$(this).width()){
						widths[i]=$(this).width();
						if(widths[i]>200)widths[i]=200;
				}
				i++;
			});
		});		
		$(this).children('.table_row').each(function(){
			i=0;
			$(this).children('.table_cell').each(function(){
				$(this).css('width',widths[i]+2);
				i++;
			});			
		});		
	});		
};


fetchonchange=function(source,dest,uri){
	var pubAPI={
		loaded:function(data){
			o='';
			active=$(''+dest).attr('value');
			for(i=0;i<data.length;i++){
				id='';caption='';
				for(j in data[i])if(!id)id=data[i][j];else caption=data[i][j];
				o+="<option value='"+id+"' "+ ((id==active)?'SELECTED':'') +" >"+caption+"</option>";				
			}
			$(''+dest).html(o);
		},	
		sourcechanged:function(){
			url=uri+this.value;
			$.getJSON(url,0,pubAPI.loaded);
		}
	}
	var source=source;
	var dest=dest;
	var uri=uri;
	$(document).ready(function(){
		$(''+source).bind('change',pubAPI.sourcechanged);		
		$(''+source).trigger('change');
	});
};

/* scrolling div */
dir='left';
function scroll_right(){
	inner=document.getElementById('scrolldiv_inner');
	outer=document.getElementById('scrolldiv_outer');
	dir='right';
	$(inner).animate({marginLeft:0},10000,function(){
		scroll_left();		
	})
}


function scroll_left(){
	inner=document.getElementById('scrolldiv_inner');
	outer=document.getElementById('scrolldiv_outer');
	if(!inner)return;
	to=-inner.clientWidth
	$(inner).animate({marginLeft:to},10000,function(){
		scroll_right();		
	});
	dir='left';
}

$(document).ready(function(){
	$('#scrolldiv_outer').bind('mouseenter',function(){
		$('#scrolldiv_inner').stop();		
	});
	$('#scrolldiv_outer').bind('mouseleave',function(){
		if(dir=='left')scroll_left();else scroll_right();	
	});
	scroll_left();	
});

