var lastgoodnum=0;
var jshow=false;
function scrolling(obj){
	var targetOffset = $(obj).offset().top;
	var tag;
	if ($.browser.safari) tag='body'; else tag='html';
	$(tag).animate({scrollTop: targetOffset},500);
}
function telproc(n,mover){
	if (!mover) $('#header #tel1,#header #tel2').fadeOut(100); 
	else {
		var tmp='';
		if ($('#header #tel1').is(':hidden')) tmp='tel1'; else tmp='tel2';
		$('#header #'+tmp).css({"backgroundPosition":"0px "+((-20)*(n-1))+"px"}).fadeIn(100);
		if ((n-1)==lastgoodnum) lastgoodnum++; else lastgoodnum=0;
		if (lastgoodnum==7&&!jshow) {
			lastgoodnum=0;
			$("<div/>")
				.attr("id","jiraf")
				.css({position:'fixed',bottom:'0',right:'0',zIndex:20})
				.appendTo("body");
			showJiraf("true","false");
			$('#jiraf').css({position:'fixed',bottom:'0',right:'0',zIndex:20})
			jshow=true;
			setTimeout(function() {
				$('#jiraf').remove();
				jshow=false;
				
			}, 3000)
		}
	}
}
function attachTelEvent(){
	$("#tel").empty();
	$("<map/>")
		.attr({	id: "telmap",
			name: "telmap"})
		.appendTo("#tel");
	var crd='';
	for (var i=0; i<7; i++){
		switch (i) {
			case 0: crd='43,13,54,32'; break;
			case 1: crd='57,13,68,32'; break;
			case 2: crd='70,13,81,32'; break;
			case 3: crd='89,13,100,32'; break;
			case 4: crd='103,13,114,32'; break;
			case 5: crd='116,13,127,32'; break;
			case 6: crd='129,13,140,32'; break;
		}
		$("<area/>")
			.attr({	shape: "rect",
				coords: crd})
			.appendTo("#telmap");
	}
	$("#telmap > area","#tel")
		.mouseover(function() { 
			telproc($(this).index()+1,1); 		
		})
		.mouseout(function() { 
			telproc($(this).index()+1,0); 		
		})
	$("<div/>")
		.attr({	id: "tel1"})
		.appendTo("#tel");
	$("<div/>")
		.attr({	id: "tel2"})
		.appendTo("#tel");
	$("<img/>")
		.attr({	src: "/img/blank.gif", usemap:"#telmap"})
		.appendTo("#tel");
	$("<img/>")
		.attr({	src: "/img/tel_top.png", id:"telimg"})
		.appendTo("#tel");
}
function showJiraf(animPlay,animLoop){
	var params = {
		menu: "false",
		wmode: "transparent",
		loop: animLoop,
		play: animPlay
	};
	swfobject.embedSWF("/img/flash/jiraf.swf", "jiraf", "550", "400", "9.0.0", "",{},params,{});
}
$(document).ready(function() {
	if(typeof attachTelEvent == 'function') {
		attachTelEvent();
	}
	$("#sitemap .sm-content").hide();
	$("#sitemap .sm-title a").click(function () {
		$("#sitemap .sm-content").animate({opacity: 'toggle', height: 'toggle'}, 'fast');
		scrolling('#sitemap');
		return false;
	});
	$("#sitemapbtn").click(function () {
		if ($("#sitemap .sm-content").is(":hidden")) {$("#sitemap .sm-content").animate({opacity: 'show', height: 'show'}, 'fast');}
		scrolling('#sitemap');
		return false;
	});
});
