// JavaScript Document
function getDocumentSize(val)
{
	var xScroll,yScroll,value;
	var hasInner = typeof(window.innerWidth) == 'number';
	var hasElement = document.documentElement && document.documentElement.clientWidth;
	var numShiftY = hasInner?pageYOffset:hasElement?document.documentElement.scrollTop:document.body.scrollTop;
	var numShiftX = hasInner?pageXOffset:hasElement?document.documentElement.scrollLeft:document.body.scrollLeft;
	if(window.innerHeight&&window.scrollMaxY)
	{
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight)
	{
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	}
	else{
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}
	var windowWidth,windowHeight;

	if(self.innerHeight)
	{
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight)
	{
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;

	}
	else if(document.body)
	{
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;

	}
	if(yScroll<windowHeight){
		pageHeight=windowHeight-20;
	}
	else{
		pageHeight=yScroll
	}

	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth-20;
	}
	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight,numShiftY,numShiftX)
	return arrayPageSize[val]
}
/*-------------------------------------------------------*/
(function($) {
		$.fn.mdtTooltip = function()
		{
			function _initialize(e) {
				$('#tooltipcontainer').html($(this).attr('msghtml'));
				var tipw=300;
				var sh=getDocumentSize(4);
				var wh=getDocumentSize(3);
				var ww=getDocumentSize(2);
				var sw=getDocumentSize(5);
				var tiph=Math.round($('#mytooltip').height()/2);
				var ttop=0;
				var tleft=0;
				if((e.pageX+(tipw/2))>ww){
					tleft=ww+sw-tipw-30;
				}
				else{
					tleft=e.pageX-Math.round(tipw/3);
				}
				if((e.pageY+2*tiph)>(sh+wh))
				{
					ttop=e.pageY-(2*tiph);
				}
				else{
					ttop=e.pageY+10;
				}
				$('#mytooltip').css('top',ttop);
				$('#mytooltip').css('left',tleft);
				$('#mytooltip').show();
				return false;
			};
			function _finish(){
				$('#mytooltip').hide();
			};
			if($(this).attr('msghtml') && $(this).attr('msghtml')!=''){
				this.mousemove(_initialize);
				this.mouseout(_finish);
			}
		};
})(jQuery);
function addPanel(){
	$('body').append('<div id="mytooltip"><div id="contbox"><div id="tooltipcontainer" class="select-free"><!--[if lte IE 6.5]><iframe></iframe><![endif]--></div><div id="tooltipconnector"></div></div></div>');
	return false;
};
/*----------------------------------------------------*/
var gMsgHtml=null;
var ym2msgbox = {
	intWidth:1,
	dialogcommon:"#dialogcommon",
	msgcontain:"#msgcontain",
	dialogbacklayer:"#dialogbacklayer",
	show:function(boxId,msgWidth)
	{

		if(gMsgHtml!=null) jQuery('body').append(gMsgHtml);
		this.intWidth=msgWidth;
		this.init();
		gMsgHtml=jQuery("#"+boxId);
		jQuery(this.msgcontain).html(jQuery("#"+boxId).html());
		jQuery("#"+boxId).remove();
		var dialogTop=Math.round(getDocumentSize(4)+(getDocumentSize(3)-jQuery(this.dialogcommon).height())/2);
		jQuery(this.dialogcommon).css({left: Math.round(getDocumentSize(2)/2-this.intWidth/2) +"px"});
		jQuery(this.dialogcommon).css({top:dialogTop +"px"});
		jQuery(this.dialogcommon).fadeIn(300, function()
		{
			jQuery("#dialogbacklayer").show();
			 jQuery(this.dialogcommon).css({display:'block'});
		});
		jQuery("#dialogbacklayer").click(function(){
			ym2msgbox.hide();
		});
		window.onresize=this.getpos;
		//window.onscroll=this.getpos;
	},
	hide:function(){
		jQuery(this.dialogbacklayer).hide();
		jQuery(this.dialogcommon).hide();
		jQuery('body').append(gMsgHtml);
		gMsgHtml=null;
		//window.onscroll=null;
		window.onresize=null;
	},
	getpos: function(){
		var dialogTop=Math.round(getDocumentSize(4)+getDocumentSize(3)-jQuery(this.dialogcommon).height()/2);
		jQuery(ym2msgbox.dialogcommon).css({left: Math.round((getDocumentSize(2)-ym2msgbox.intWidth)/2)+"px"});
		jQuery(ym2msgbox.dialogcommon).css({top: dialogTop+"px"});
	},
	init:function()
	{
	 	var backobj=document.getElementById('dialogbacklayer');
		if (backobj == null || backobj == 'undefined'){
			jQuery('body').append('<div id="dialogbacklayer">&nbsp;</div><div id="dialogcommon" class="select-free"><!--[if lte IE 6.5]><iframe></iframe><![endif]--><div class="rowtop"><div class="lb_top_border_cl"></div><div class="wdialog"></div><div class="lb_top_border_cr"></div></div><div class="rowmid"><div class="wdialog"><div id="msgcontain"></div></div></div><div class="rowbot"><div class="lb_bot_border_cl"></div><div class="wdialog"></div><div class="lb_bot_border_cr"></div></div></div>');
		}
		jQuery('#dialogcommon').css('width',this.intWidth+20+'px');
		jQuery('#msgcontain').css('width',this.intWidth+'px');
		jQuery('#dialogcommon .wdialog').css('width',(this.intWidth)+'px');
	}
}

/*--------------------------------------------------------*/
function mdtactiveTab(){
	$('.tabitem').click(function(){
		var tabID=$(this).attr('rel');
		var obj=$(this);
		$(this).parents('.boxtop').parent().find('.boxcontent').children('.active').fadeOut(300,function(){
			$(this).removeClass('active');
			$('#'+tabID).fadeIn(50,function(){
				$(this).addClass('active');
				$(obj).parent().parent().children('.active').removeClass('active');
				$(obj).parent().addClass('active');
			});
		});
		return false;
	})
}
$(document).ready(function(){
	mdtactiveTab();
	mdtslideEven();
});

mdtslideEven = function()
{
	var tsec;
	var curindex=0;
	var maxindex=0;
	$(".piclist li").click(function(index){
		clearTimeout(tsec);
		$(".piccontainer .pictxt").stop(true,true);
		$(".piccontainer .picframe").stop(true,true);
		$(".piclist .active").removeClass('active');
		curindex=$(".piclist li").index(this);
		autochange($(".piclist li:eq("+curindex+")"));
	});
	maxindex=$(".piclist li").length;
	autochange($(".piclist li:eq("+curindex+")"));
	function autochange(obj){
		clearTimeout(tsec);
		$(".piclist .active").removeClass('active');
		$(obj).addClass("active");
		$(".piccontainer .pictxt").animate({marginTop:"90px"},500,function(){
			$(".piccontainer .pictxt").text("");
			$(".piccontainer .underframe").css("background","url("+$(obj).attr("picurl")+") no-repeat top center");
			$(".piccontainer .picframe").fadeOut(1000,function(){
				$(".piccontainer .picframe").attr("href",$(obj).attr("piclink"));
				$(".piccontainer .picframe").css("background","url("+$(obj).attr("picurl")+") no-repeat top center").fadeIn("fast",function(){
					$(".piccontainer .pictxt").html($(obj).attr("pictext")).animate({marginTop:"0px"}, 500,function(){

					tsec=setTimeout(function(){
							$(".piclist li:eq("+(curindex)+")").removeClass('active');
							curindex++;
							if(curindex==maxindex) curindex=0;
							autochange($(".piclist li:eq("+curindex+")"));
						},5000);
					});
				});
			});
		});
	}
};
