$(function(){
	init();
	rollover("menu","gif");
	rollover("rollover","png");
	$(".menu a").mouseout(function(){
		$(this).children("img").attr("src", imgsrc);
	});
});
init=function(){
	$(".thumbs").fadeTo("fast", 0.8);
	$(".thumbs").hover(
		function(){
			$(this).fadeTo("fast", 1);
		},
		function(){
			$(this).fadeTo("slow", 0.8);
		}
	);
	$(".zoom").hover(
        function(){
			$(this).css({'position':'absolute'}).animate({'width':'185px','marginTop':'-15px'}).animate({'width':'175px','marginTop':'-15px'});
        },
        function(){
			$(this).css({'position':'relative'}).animate({'width':'100px','marginTop':'0px'});
        }
	);
	$(".cycle").cycle({
		fx:"fade",
		timeout:6000,
		speed:1000
	});
	$(".lightbox").lightbox();
}
rollover=function(clas,ext){
	//Preload all rollovers
	$("."+clas+" img").each(function() {
		// Set the original src
		rollsrc = $(this).attr("src");
		if(ext=="gif"){
			rollON = rollsrc.replace(/.gif$/ig,"2."+ext);
		}else{
			rollON = rollsrc.replace(/.png$/ig,"2."+ext);
		}
		$("<img>").attr("src", rollON);
	});
	//Navigation rollovers
	$("."+clas+" a").mouseover(function(){
		imgsrc = $(this).children("img").attr("src");
		matches = imgsrc.match(/_over/);
		//Don't do the rollover if state is already ON
		if (!matches) {
			if(ext=="gif"){
				imgsrcON = imgsrc.replace(/.gif$/ig,"2."+ext);
			}else{
				imgsrcON = imgsrc.replace(/.png$/ig,"2."+ext);
			}
			//Strip off extension
			$(this).children("img").attr("src", imgsrcON);
		}
	});
	$("."+clas+" a").mouseout(function(){
		$(this).children("img").attr("src", imgsrc);
	});
}
var lastpage;
var lastobj;
var load_html="<img src='js/loading.gif' align='absmiddle' />";
prepares=function(url, obj, fn, fx){
	prepare(url, obj, fn, fx, load_html);
}
prepare=function(url, obj, fn, fx, loader){
	lastpage=url;
	if(!obj){obj="content"};
	lastobj=obj;
	if(!loader){
		load_gif_='<div style="height:180px;"></div>'+load_html; //"<div style='margin:30px;width:90px;background:#fff;border:1px solid #aaaaaa;padding:10px;' align='center'><img src='js/loading.gif' align='absmiddle' style='padding-right:5px;' /> Loading..</div>";
	}else{
		load_gif_=loader;
	}
	if(fx!=null){
		$.get(url,function(res_data){
			$("#"+obj).html(res_data);
			init();
			if(fn!=null){fn();}
		})
	}else{
		if($("#"+obj).html()==""){
			$("#"+obj).html(load_gif_).fadeIn("normal",function(){
				$.get(url,function(res_data){
					$("#"+obj).fadeOut("fast",function(){
						$("#"+obj).html(res_data).fadeIn("normal",function(){
							init();
							if(fn!=null){fn();}
						});
					});
				});
			});
		}else{
			$("#"+obj).fadeOut("fast",function(){
				$("#"+obj).html("");
				$("#"+obj).html(load_gif_).fadeIn("normal",function(){
					$.get(url,function(res_data){
						$("#"+obj).fadeOut("fast",function(){
							$("#"+obj).html(res_data).fadeIn("normal",function(){
								init();
								if(fn!=null){fn();}
							});
						});
					});
				});
			});
		}
	}
}
clearobj=function(obj){
	$("#"+obj).hide("fast",function(){
		$("#"+obj).html("");
	});
}
setForm=function(form,target,fn){
	$("#"+form).ajaxForm({
		target:"#"+target,
		beforeSubmit:function(){
			$("#"+target).html(load_html);
		},
		success:function(){
			$("#"+target).fadeIn("slow");
			init();
			if(fn!=null){fn();}
		}
	});
}
logoff=function(){
	if(confirm("Are you sure want to log off?")){
		location.href="?a=q";
	}
}

