	var imgArray = new Array();
	imgArray[0] = 'home_1.jpg';
	imgArray[1] = 'home_2.jpg';
	imgArray[2] = 'home_3.jpg';
	imgArray[3] = 'home_4.jpg';
	imgArray[4] = 'home_1.jpg';
	imgArray[5] = 'home_1.jpg';
	imgArray[6] = 'home_1.jpg';
	var images = new Array();
	//images[0] = new Image(749, 383);
	//images[0].src= '/images/home_1.jpg';
	var loading = new Image(32,32);
	var imgIndex = 0;
	var timeout_id = 0;
	var msg = '';
	$(document).ready(function(){
		if($('#gallery').html()){
			init();
		}
		search();
		ajax_form();
	});
	function init(){
		images[0] = new Image(749, 383);
		images[0].src= '/images/home_1.jpg';
		loading.src='/images/img_loading.gif';
		imgIndex = 0;
		$('#inner').css('backgroundImage', 'url('+images[imgIndex].src+')');
		
		//uncomment the next two lines to enable rotating images.
		//change(0);
		//timeout_id = setTimeout('rotate()', 2000);
	}
	//auto rotate
	function rotate(){
		clearTimeout(timeout_id);
		imgIndex = imgIndex+1;
		if(imgIndex >= imgArray.length){
			imgIndex = 0;
		}
		if(images[imgIndex] == undefined){
			$('#inner').css('backgroundImage', 'url('+ loading.src +')');
			images[imgIndex] = new Image(749,383);
			images[imgIndex].src = '/images/'+imgArray[imgIndex];
		}
		var background_url = 'url('+images[imgIndex].src+')';
	/*	if($.browser.msie && $.browser.version<7.0){
			$('#inner').css('backgroundImage', background_url);
			clearTimeout(timeout_id);
			change(imgIndex);
			timeout_id = setTimeout('rotate()', 5000);
		}else{*/
			$('#inner').fadeOut(1000, function(){
				clearTimeout(timeout_id);
				$('#inner').css('backgroundImage', background_url);
					change(imgIndex);
					$('#inner').fadeIn(2000, function(){
					clearTimeout(timeout_id);
					
					timeout_id = setTimeout('rotate()', 2000);
				});
			});
	//	}
	}
	//show image
	function show(index){
		clearTimeout(timeout_id);
		imgIndex = index;
		if(imgIndex >= imgArray.length){
			imgIndex = 0;
		}
		change(index);
		if(images[imgIndex] == undefined){
			$('#inner').css('backgroundImage', 'url('+loading.src+')');
			images[imgIndex] = new Image(749,383);
			images[imgIndex].src = '/images/'+imgArray[imgIndex];
		}
		$('#inner').css('backgroundImage', 'url(/images/'+imgArray[imgIndex]+')');
		clearTimeout(timeout_id);
		timeout_id = setTimeout('rotate()', 2000);
	}
	//change the thumb_list
	function change(index){
		html = '';
		for(var i=0;i<imgArray.length;i++){
			if(i==index){
				html += '<div><span></span></div>';
			}else{
				html += '<a href="" title="" onclick="show('+i+');return false;"></a>';	
			}
		}
		$('#thumb_list').html(html);
	}
	function pause(ms){
		var date = new Date(); 
		curDate = null;
		do { var curDate = new Date(); }
		while ( curDate - date < ms);
	}
	function search(){
		$('#search .text').click(function(){
			$(this).select();
		});
		$('#search form').submit(function(){
			$('#search :image').trigger('click');
			return false;
		});
		$('#search :image').click(function(){
			self.location.href = '/search/'+escape($(this).prev().val())+'/';
			return false;
		});
	}
	function ajax_form(){
		if($('#submit').val() != undefined){
			$('.content form').ajaxForm({
				beforeSubmit:function(){
					$('#submit').attr('disabled','disabled');
					$('#status').html('<img src="/images/admin/loading.gif" /><span class="success">Processing your request, please wait...</span>');
				},
				dataType:'json',
				success:function(res){
					if(res.status==1){
						for(var i=0;i<res.message.length;i++){
							$('#'+res.message[i].id).next().html(res.message[i].error);
						}
						$('#status').html('');
						$('#submit').removeAttr('disabled');
					}else if(res.status==0){
						$('#status').html('<span class="success">'+res.message+'</span>');
						msg = res.html;
						setTimeout("$('.content').html('<h2 class=\"default\">'+msg+'</h2>');", 1500);
					}else{
						$('#status').html('<span class="error">'+res.message+'</span>');
					}
				}
			});
		}
	}