var Global={PATH:'/'};
Global.GetDocWidth=function(d){
	d=d||document;
	return Math.max(this.GetClientWidth(d),d.body.offsetWidth);
};
Global.GetDocHeight=function(d){
	d=d||document;
	return Math.max(this.GetClientHeight(d),d.body.offsetHeight);
};
Global.GetScrollLeft=function(d){
	d=d||document;
	return(d.documentElement?d.documentElement.scrollLeft:d.body.scrollLeft);
};
Global.GetScrollTop=function(d){
	d=d||document;
	return(d.documentElement?d.documentElement.scrollTop:d.body.scrollTop);
};
Global.GetClientWidth=function(d){
	d=d||document;
	return(window.innerWidth||d.documentElement&&d.documentElement.clientWidth||d.body.clientWidth);
};
Global.GetClientHeight=function(d){
	d=d||document;
	return(window.innerHeight||d.documentElement&&d.documentElement.clientHeight||d.body.clientHeight);
};
Global.GetOffsetTop=function(el,p){
	var _t=el.offsetTop;
	while(el=el.offsetParent){
		if(el==p)break;
		_t+=el.offsetTop;
	}
	return _t;
};
Global.GetOffsetLeft=function(el,p){
	var _l=el.offsetLeft;
	while(el=el.offsetParent){
		if(el==p)break;
		_l+=el.offsetLeft;
	}
	return _l;
};
Global.Random=function(){
	return(new Date().getTime()+'_'+Math.floor(Math.random()*10000000));
};


$(function(){
	$(document).bind("click", function(){ setTimeout(function() { $("#autoAutomatic").addClass('displayNone'); }, 200) });
	$("#autoAutomatic").bind('click', function(e) { e.stopPropagation() } );
    $('#searchBox > input').bind('click', function(e) { e.stopPropagation() });
	$("#keyword").bind('click', function() { $('#autoAutomatic').removeClass('displayNone'); });
	$(".hotimg img").each(function (){
        changeImgSize(this,75,75);
    });	
	Misc.showTime("time");
});

//栏目标签开关
function switchTab(identify,index,count) {
	for(var i=0;i<count;i++) {
		if (i != index) {
			$("#Tab_" + identify + "_" + i).removeClass('upH3');
			$("#List_" + identify + "_" + i).removeClass('upBox');
		}
	}
	$("#Tab_" + identify + "_" + index).addClass('upH3');
	$("#List_" + identify + "_" + index).addClass('upBox');
	if(identify == 'map'){
		if(index == 0){
			newmap.window.location.reload();
		}else if(index == 1){
			hitsmap.window.location.reload();
		}else if(index == 2){
			remarkmap.window.location.reload();
		}
	}
}

//栏目标签开关
function switchTab2(identify,index,count) {
	for(var i=0;i<count;i++) {
		if (i != index) {
			$("#Tab_" + identify + "_" + i).removeClass('upH3');
			$("#List_" + identify + "_" + i).removeClass('upBox');
		}
	}
	$("#Tab_" + identify + "_" + index).addClass('upH3');
	$("#List_" + identify + "_" + index).addClass('upBox');
	if(identify == 'map'){
		if(index == 0){
			newmap.window.location.reload();
		}else if(index == 1){
			hitsmap.window.location.reload();
		}else if(index == 2){
			remarkmap.window.location.reload();
		}
	}
	$(".slide_item img").each(function (){
	    changeImgSize(this,170,160);
		setTimeout("changeImgSize(this,170,160)",2000);
	});
}


function switchTabSlide(identify,index,count) {
	for(var i=0;i<count;i++) {
		if (i != index) {
			$("#Tab_" + identify + "_" + i).removeClass('upH3');
			$("#List_" + identify + "_" + i).removeClass('upBox');
		}
	}
	$("#Tab_" + identify + "_" + index).addClass('upH3');
	$("#List_" + identify + "_" + index).addClass('upBox');
	if(index == 1){
		$.get('ajaxphoto.php?action=getRecommendsList&rand='+Math.random(),function(result){
			$("#List_" + identify + "_" + index).html(result);
		});
	}else if(index == 2){
		$.get('ajaxphoto.php?action=getHitsList&rand='+Math.random(),function(result){
			$("#List_" + identify + "_" + index).html(result);
		});
	}else if(index == 3){
		$.get('ajaxphoto.php?action=getRemarksList&rand='+Math.random(),function(result){
			$("#List_" + identify + "_" + index).html(result);
		});
	}
	$(".slide_item img").each(function (){
	    changeImgSize(this,170,160);
		setTimeout("changeImgSize(this,170,160)",2000);
	});
}

function switchTabMap(identify,index,count) {
	for(var i=0;i<count;i++) {
		if (i != index) {
			$("#Tab_" + identify + "_" + i).removeClass('upH3');
			$("#List_" + identify + "_" + i).removeClass('upBox');
		}
	}
	$("#Tab_" + identify + "_" + index).addClass('upH3');
	$("#List_" + identify + "_" + index).addClass('upBox');
	if(index == 1){
		$.get('ajaxphoto.php?action=getMapHitsList&rand='+Math.random(),function(result){
			$("#List_" + identify + "_" + index).html(result);
		});
	}else if(index == 2){
		$.get('ajaxphoto.php?action=getMapRemarksList&rand='+Math.random(),function(result){
			$("#List_" + identify + "_" + index).html(result);
		});
	}
}

//免激活方式显示FLASH
function insertFlash(url, w, h) { 
	var str = ''; 
	str += '<object width="'+ w +'" height="'+ h +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">'; 
	str += '<param name="movie" value="'+ url +'">'; 
	str += '<param name="wmode" value="transparent">'; 
	str += '<param name="quality" value="autohigh">'; 
	str += '<embed width="'+ w +'" height="'+ h +'" src="'+ url +'" quality="autohigh" wmode="transparent" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>'; 
	str += '</object>'; 
	document.write(str); 
}

//图片载入大小限制
function changeImgSize(obj,maxImageWidth,maxImageHeight){
	//alert($(obj).attr("src"));
	$(obj).attr("resized","1");
	if($(obj).attr("width") > $(obj).attr("height")){
		if($(obj).attr("width") > maxImageWidth){
			$(obj).attr("width",maxImageWidth);
			$(obj).css("width",maxImageWidth);
		}
	}else{
		if($(obj).attr("height") > maxImageHeight){
			$(obj).attr("height",maxImageHeight);
			$(obj).css("height",maxImageHeight);
		}
	}
}

function more(id){
	var height = $("#nlist"+id).find("table").height();
	if ($("#nlist" + id).height() == 60) {
		$("#nlist" + id).animate({
			height: height + 'px'
		}, "slow");
	}else{
		$("#nlist" + id).animate({
			height: '60px'
		}, "slow");
	}
	//alert(height);
}

//显示提示结果
var tips_window = null;
var timer=null;
function palert(tempStr,autoOut)
{
	var timeOut=3000;
	if(autoOut){
		timeOut=999999;
	}
	if (!tips_window){
		var tempDiv = document.createElement('div');
			tempDiv.id = 'tipsdiv';
			tempDiv.style.display = 'block';
			tempDiv.style.zIndex = 10001;
			tempDiv.style.position = 'absolute';
			tempDiv.style.left="41%";
			tempDiv.style.top= document.documentElement.scrollTop + 270;
		var tipsdiv_HTML = "<ul><li style='float:left;background: url(images/tips-left.gif) no-repeat left top; height:60px;'><a style='display:block;padding:22px 10px 19px 60px;background: url(images/tips-right.gif) no-repeat right top;color:#FFFFFF;font-weight:bold;font-size:15px;' id='tipsdivcontent'>"+tempStr+"</a></li></ul>";
			tempDiv.innerHTML = tipsdiv_HTML;
			document.body.appendChild(tempDiv);
			tips_window = $('#tipsdiv');
			timer=setInterval(HiddenTips,timeOut);
	}else{
		clearInterval(timer);
		$("#tipsdivcontent").html(tempStr);
		$("#tipsdiv").css('top',document.documentElement.scrollTop + 270);
		$("#tipsdiv").show();
		timer=setInterval(HiddenTips,timeOut);	
	}
}
function HiddenTips(){
	$("#tipsdiv").hide();
	clearInterval(timer);
}
//重写setTimeout使其可以传递参数
var _setTimeout=setTimeout;
window.setTimeout=function(f,c,d){
	var b=Array.prototype.slice.call(arguments,2);
	var a=function(){
		f.apply(null,b);
	};
	return _setTimeout(a,c);
};
var Misc={};

Misc.switchTab=function(identify,index,count,func){
	for(var i=0;i<count;i++) {
		if (i != index) {
			$("Tab_" + identify + "_" + i).removeClassName('upH3');
			$("List_" + identify + "_" + i).removeClassName('upBox');
		}
	}
	$("Tab_" + identify + "_" + index).addClassName('upH3');
	$("List_" + identify + "_" + index).addClassName('upBox');
	if(func){
		func(index);
	}
};
Misc.more = function(id){
	var height = $("nlist" + id).$T("table")[0].clientHeight;
	if ($("nlist" + id).clientHeight == 60) {
		$("nlist" + id).changeHeight(60,height);
	}else{
		$("nlist" + id).changeHeight(height,60);
	}
};
Misc.showTime=function(str){
	today=new Date(); 
	var year=today.getYear();
	var month=today.getMonth()+1;
	var day=today.getDate();
	var hours = today.getHours(); 
	var minutes = today.getMinutes(); 
	var seconds = today.getSeconds(); 
	var timeValue= hours;
	timeValue += ((minutes < 10) ? ":0" : ":") + minutes+""; 
	timeValue+=((seconds < 10) ? ":0" : ":") + seconds+"";
	var timetext=year+"-"+month+"-"+day+" "+timeValue
	$("#"+str).html(timetext);
	setTimeout(function(){
		Misc.showTime(str);
	},1000); 
};

function Marquee(){
    this.Content = [];    //显示内容
    this.Speed = 20;    //上移速度
    this.Object = {};    //marquee容器对象
    this.Pause = true;    //是否停留
    this.Start = function(){
        var o = this.Object;
        var Pause = this.Pause;
        var Stop = false;
        var Stop2 = false;
        o.onmouseover = function(){
            Stop = Stop2 = true;
        }
        o.onmouseout = function(){
            Stop = Stop2 = false;
        }
        var BodyHtml = [];
        for(var i in this.Content){
            BodyHtml.push(this.Content[i].text);
        }
        var Dv = document.createElement("div");
        Dv.innerHTML = BodyHtml.join("<br />");
        o.appendChild(Dv);
        var DvHeight = Dv.offsetHeight;
//        while(Dv.offsetHeight /2 < o.offsetHeight){
//            Dv.innerHTML += "<br />" + Dv.innerHTML;
//        }
        Dv.innerHTML += "<br />" + Dv.innerHTML;
        setInterval(function(){
            if(!Stop){
                o.scrollTop ++;
                if(o.scrollTop == o.scrollHeight - o.offsetHeight){
                    o.scrollTop = DvHeight - o.offsetHeight;
                }
                if(Pause){
                    if(o.scrollTop % o.offsetHeight == 0){
                        Stop = true;
                        setTimeout(function(){
                            Stop = Stop2;
                        }, 3000);
                    }
                }
            }
        }, this.Speed);
    }
}
function favorites(pid){
	$.get('ajax.php?action=favorites&id='+pid+'&rand='+Math.random(),function(result){eval(result);});
}
function report(pid){
	$.get('ajax.php?action=report&id='+pid+'&rand='+Math.random(),function(result){eval(result);});
}
function time()
{
	var timeStr, dateStr;
	now = new Date();
	hours = now.getHours();
	minutes = now.getMinutes();
	seconds = now.getSeconds();
	if(hours < 10)
		timeStr = "0"+hours;
	else timeStr=hours;
	if(minutes < 10)
		timeStr+=":0"+minutes;
	else timeStr+=":"+minutes;
	if(seconds < 10)
		timeStr+=":0"+seconds;
	else timeStr+=":"+seconds;
	//date
	year=now.getYear();
	month=now.getMonth()+1;
	date=now.getDate();
	dateStr=year;
	if(month<10)
		dateStr+="-0"+month;
	else dateStr+="/"+month;
	if(date<10)
		dateStr+="-0"+date;
	else dateStr+="-"+date;
	document.write(dateStr+" "+timeStr);
}