// 城市层标志位
var cityFlag = 0;
//我的哈票层标志位
var myhpFlag = 0

function dplayMhList(){
	if ($('#myhplist').css('display')=='none')
		$('#myhplist').show();
	else
		$('#myhplist').hide();
}
function dplayCity(){
	if ($('#dvcity').css('display')=='none')
		$('#dvcity').show();
	else
		$('#dvcity').hide();
}

// 根据域名和目录将频道突出显示
var setDefaultChannelClass = function(){

	$('#header_menu_ul > li').attr('class','');
	var curDomain=document.domain;	
	var domainUrl = document.location.href;
	var score = domainUrl.split( "/" )[3];
	switch(curDomain){
		case 'news.hipiao.com':
			break;
		case 'hilinker.hipiao.com':			
			break;
		case 'cinema.hipiao.com':
			$('#header_menu_ul > li').eq(2).attr('class','menu_a');
			break;
		case 'movie.hipiao.com':
			$('#header_menu_ul > li').eq(1).attr('class','menu_a');
			break;
		case 'member.hipiao.com':
			if(score=="score")
				$('#header_menu_ul > li').eq(3).attr('class','menu_a');
			break;
		case 'www.hipiao.com':
		default:
			$('#header_menu_ul > li').eq(0).attr('class','menu_a');
			break;
	}	// end switch
}	// end function setDefaultChannelClass

// 换城市代码操作
var changeCityId = function(cityId, cityName){
	var isCinema = false;
	if($.cookie('HIPIAOCITYID')!=cityId)
		isCinema = true;
	$.cookie('HIPIAOCITYID', cityId, {path: '/', domain: 'hipiao.com', secure: false });
	$('#default_city').html( cityName+'市' );
	$('#dvcity').hide();

	// 如果是哈票网首页www.hipiao.com或cinema下首页或film.php则刷新
	var thispage = document.location.href;
	var pageArray = thispage.split("=");
	if(thispage.match('^http://cinema.hipiao.com/')&&isCinema)
		document.location.href='http://cinema.hipiao.com/';
	else if(pageArray[0]=="https://member.hipiao.com/buy/selseat.php?planid")
		document.location.href='http://movie.hipiao.com/film.php?pixnumber='+pageArray[1]+'#f4';
	else
		document.location.reload();
	/*if ( thispage.match('^http://www.hipiao.com/$') || thispage.match('^http://cinema.hipiao.com/$') || thispage.match('^http://cinema.hipiao.com/film.php') ){
		document.location.reload();
	} else {	// 只更新页首弹出层
		ajaxChangeHeaderPopUpDiv(cityId, cityName);
	}*/
}

// 鼠标效果函数：在link移入移出时div隐藏或显示，flag为逻辑标识变量
var showHideDiv = function (linkId, divId, flag){
	var jqLinkId = '#' + linkId;
	var jqDivId = '#' + divId;
	// 鼠标在隐藏层移入移出的效果
	$(jqDivId).live("mouseover", function(){
		flag = flag | 1;
	}).live("mouseout", function(){
		flag = flag & 2;
	});


	// 鼠标在初始点移入移出的效果
	$(jqLinkId).hover(function(){
		flag = flag | 2;
	},function(){
		flag = flag & 1;
	});

	// 如果点击非弹出层其他任何地方，弹出层消失
	$("*").mouseup(function(){		
		if (flag == 0 ){
			$(jqDivId).hide();
		}
	});

}	// end function showHideDiv

// 设置默认频道凸显
setDefaultChannelClass();

$(function(){	// 读完DOM后才执行的函数
	// 设置弹出层关联的动作	
	showHideDiv('cityLink', 'dvcity', cityFlag);
	showHideDiv('myhpLink', 'myhplist', myhpFlag);
	//首页公告
	$(".notice img").click(function(){
		$(".notice").hide();
	});
	// 设置默认城市cookie
	var hpcityidval = $('#ajaxhpcityid').val();
	$.cookie('HIPIAOCITYID', hpcityidval, {expires: 3650, path: '/', domain: 'hipiao.com', secure: false });
})


