jQuery(document).ready(function(){

	jQuery('.thebutton').each(function(){
		var icon = jQuery(this).attr('icon');
		var opt = {};

		if( icon )
			opt = {
				icons:{
					primary:'ui-icon-'+icon
					}
				}

	jQuery(this).button(opt);
	});

	jQuery('.thebutton_small').each(function(){
		var icon = jQuery(this).attr('icon');
		var opt = {};

		if( icon )
			opt = {
				icons:{
					primary:'ui-icon-'+icon
					}
				}

	jQuery(this).button(opt).css({
		'margin':'0px 2px'
	});
	jQuery(this).find('.ui-button-text').css({
		'padding-left':'1.1em'
	});
	});

	jQuery('.theprogressbar').each(function(){
		var p = parseInt(jQuery(this).attr('progress'),10);
		jQuery(this).progressbar({
			value:p
		})
	});
	
	var sinput = jQuery('#top_search').find('input');
	if(sinput)
	{
		sinput.keypress(function(evt){
			if(evt.which == 13)
				jQuery('#top_search').find('a').trigger('click');
		})
	}

	
/*
	var container = jQuery('#site_container3');
	jQuery('body').mousemove(function(event){
		var m = event.pageX;
		var w = jQuery(this).width();
		var wo = w * 0.01;
		var half = 50 * wo;
		var ho = half * 0.01;
		var dir = 1;
		var pos = m;
		var step = 0.1;
		var speed = 2000;

		if( m > half )
		{
			pos = m - half;
			dir = -1;
		}

		container.animate({
			backgroundPosition: (50 + (dir * ho)) + '% 0%'},{
				duration:speed,
				queue:false
			}
		);
	});*/
});


function jsonPost(url,data,callback){
	jQuery.ajax({
		url:url,
		type:'POST',
		cache:false,
		data:data,
		dataType:'json',
		timeout:5000,
		success:function( resp ){
			if( typeof callback == 'function' )
				callback(resp);
		},
		error:function(xnr,status,e){

		}
	});
}

function jsonGet(url,data,callback){
	jQuery.ajax({
		url:url,
		type:'GET',
		cache:false,
		data:data,
		dataType:'json',
		timeout:5000,
		success:function( resp ){
			if( typeof callback == 'function' )
				callback(resp);
		},
		error:function(xnr,status,e){

		}
	});
}

function templateRender( template, data )
{
	if(!template)
		return;
	
	if( typeof(data) != 'object' )
		data = {};
	
	data.template = template;
	
	try
	{
		return jQuery('#site-templates').tmpl( data );
	}catch(e){
		return;
	}
}

