gallery_idx=0;
function addGallery(t,src,num,w,h){
	document.write('<div align="center"><div id="galleryholder'+gallery_idx+'" >&nbsp;</div></div>');
	var fo = new SWFObject("/swf/gallery.swf", "gallery", w+50 ,h+100 , "7", "#333333", true);
	fo.addParam("allowScriptAccess", "always");
	fo.addVariable("galleryName",t);
	fo.addVariable("img_dir",src);
	fo.addVariable("maxImg",num);
	fo.addVariable("width",w+50);
	fo.addVariable("height",h+100);
	fo.addVariable("jump",10);
	fo.write("galleryholder"+gallery_idx);
	gallery_idx++;
}

function addFancyMovie(vid){
	//
	document.write('<div align="center"><img src="/images/fancyVideo.gif" onclick="showFancyVideo('+vid+',$(this))"/><br /><br /><div rel="fancyMovie" class="fancyMovie"></div></div>');
}

function showFancyVideo(vid,j){
	mo={};
	$.getJSON(
		"http://hbd.just.edu.cn/video/fancyMovie.php?vid="+vid,
		function(json){
			mo.url = "http://v.hbd.just.edu.cn:81/"+json.url;
			mo.t = json.title;
			mo.w = json.width;
			mo.h = json.height;
			mo.hdurl = json.hdurl==null?null:"http://v.hbd.just.edu.cn:81/"+json.hdurl;
			mo.mid = json.mid;
			jbox = j.parent().find('div.fancyMovie');
			addMovie2(mo.url,mo.t,mo.w-0,mo.h-0,mo.hdurl,mo.mid,j.parent().find('div.fancyMovie'));
			j.parent().find('div[rel=fancyMovie]').fancybox();//{'transitionIn':'elastic','transitionOut':'elastic','speedIn':600,'speedOut':200,'overlayShow':false}
			//jbox=null;
		}
	); 
}

var movie_idx=0;

function addVideo(url,hdurl,t,w,h){
	addMovie(url,t,w,h,hdurl);
}
function addMovieList(mid,url,t,w,h,hdurl){
	addMovie(url,t,w,h,hdurl,mid);
}
function addMovie(url,t,w,h,hdurl,mid){
	addMovie2(url,t,w,h,hdurl,mid,null);
}
function addMovie2(url,t,w,h,hdurl,mid,jq){
	if(mid==null||mid==1)mid=0;
	var isMp4 = (url.indexOf(".mp4")==url.length-4);
	if(IP=="campusO"){
		//url = url.replace("http://v.hbd.just.edu.cn:81/", "http://202.195.195.143:81/");
		//url = url.replace("http://hbd.just.edu.cn:81/", "http://202.195.195.143:81/");
		try{
			hdurl = hdurl.replace("http://v.hbd.just.edu.cn:81/", "http://202.195.195.143:81/");
		}catch(e){
		}
	}
	rd  = '<div align="center"><div><div id="jwplayer'+movie_idx+'" >&nbsp;</div><div rel="h"></div></div>';
	if(jq==null){
		document.write(rd);
	}else{
		jq.replaceWith(rd);
	}
	//if(IP.indexOf("campus")!=0&&(url.indexOf(':81/public/')||url.indexOf(':81/news/'))==-1){
	//	$("#jwplayer"+movie_idx).hide();
	//	document.write('<a href="javascript:playVideo(\''+url+'\')" style="font-size:16px">点击播放</a><br />');
	//}
	var lw = 0;
	var ls ="";
	// need this next line for local testing, it's optional if your swf is on the same domain as your html page
	var params = {
		allowScriptAccess:"always",
		allowFullScreen: "true",
		menu: "false"
	};
	var flashvars = {
		file:url,
		//streamer:'lighttpd',
		fullscreen:'true',
		//provider:'http',
		//'http.startparam':'starttime',
		stretching:'none'
	};
	if(mid!=0){
		flashvars.file='http://hbd.just.edu.cn/video/playlist.php?c='+mid;
	}else{
		flashvars.provider='http';
		flashvars['http.startparam']='starttime';
	}
	if(mid!=0){
		lw=300;
		//playlistsize=lw;
		flashvars.playlist='right';
		flashvars.playlistsize=lw;
	}
	flashvars.plugins='';
	//校外加登录
	if(IP!="campus"&&url.indexOf(':81/public/')==-1&&url.indexOf(':81/news/')==-1){
		flashvars.plugins = 'http://hbd.just.edu.cn/swf/hbd_login.swf';
		flashvars.sID = $.cookie('JAccount');
		flashvars.handle_url = 'http://hbd.just.edu.cn/JAccount/mlogin.php';
	}
	//高清
	isHD=false;
	if(hdurl!=null&&hdurl.length>0){
		isHD=true;
		if(flashvars.plugins!='')flashvars.plugins+=',';
		flashvars.plugins +='http://hbd.just.edu.cn/swf/hbd_hd.swf';
		params.flashvars="hd.file="+hdurl;//escape(escape())
		if(IP=="campus"||IP=="campusO"){
			params.flashvars+="&hd.state=true";
		}else{
			params.flashvars+="&hd.state=false";
		}
	}
	var attributes = {id:"jwplayer"+movie_idx,name: "jwplayer"+movie_idx };
	htmldiv = $("#jwplayer"+movie_idx).next();
	//	initialScale: 'scale',\
	if(!isMp4||swfobject.hasFlashPlayerVersion("9.0.115")){
		//10.2bug问题
		/*
		if(/msie/i.test(navigator.userAgent)&&swfobject.hasFlashPlayerVersion("10.2")){
			if(/[\u4E00-\u9FA5]/.test(url)){
				$("#jwplayer"+movie_idx).before("<div style='color:#f00;font-size:18px' >您的的flash版本是10.2,在IE浏览器中该影片不能播放</div>");
				return;
			}
			if(!/\.mp4|\.flv/i.test(url))
				$("#jwplayer"+movie_idx).before("<div style='color:#f00;font-size:18px' >您的的flash版本是10.2,在IE浏览器中部分影片不能播放</div>");
		}//10.2bug问题结束
		*/
		swfobject.embedSWF("http://hbd.just.edu.cn/swf/player.swf","jwplayer"+movie_idx , w+lw, h+23, "8.0.0", "expressInstall.swf", flashvars, params, attributes);
	}else{
		htmldiv.append("对不起，航标灯视频H.264格式需要flash 9.0.115 以上的版本才可以收看，请升级flashplayer<br />");
		if(/msie/i.test(navigator.userAgent)){
			htmldiv.append("<a href=\"http://get.adobe.com/flashplayer/\">Adobe官方下载</a> <a href=\"/swf/Install Flash Player 10 ActiveX.exe\">校内下载</a><br /><br />");
		}else{
			htmldiv.append("<a href=\"http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player.exe\">Adobe官方下载</a> <a href=\"/swf/install_flash_player.exe\">校内下载</a><br /><br />");
		}
	}
	htmldiv.append("<div class='videoTitle' rel='movie'>"+t+"</div>");
	if(isMp4)htmldiv.append("<span style=\"color:#ff0000\">H.264格式试播，影片缓冲时间较长，请耐心等待</span>");
	if(isHD)htmldiv.append("<div>该片含有高清片源，请在播放窗口的右上角选择切换。</div>");
	htmldiv.append("</div>\
	<style>\
	.videoTitle{line-height:40px;font-size:18px;font-family:\"黑体\";color:#333}\
	</style>\
	");
	movie_idx++;
}



jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

$(document).ready(function($) {
	//$(document).pngFix();
	//$(document).minmax();
});


