﻿pandora.main.menu.prototype = {
		menu : null,
		category : null,
		lang : null,
		json : null,
		orgCate_1 : null,
		orgCate_2 : null,
		selCate : null,
		prevCate : null,
		data : null,

		initialize : function(){
		},

		set : function(menu, lang){
			this.menu = menu;
			this.lang = lang;
			this.category = cMainCategoryMgr.getInstance();
			this.orgCate_1 = chInfoJson['c1'];
			this.orgCate_2 = chInfoJson['c2'];
		},

		setJson : function(json){
			this.json = json;
		},

		getJson : function(target){
			if(typeof target=="undefined") return this.json;
			else return this.json[target];
		},

		setSelCate : function(cate){
			this.selCate = cate.split("_")[1];
		},

		getSelCate : function(){
			return this.selCate;
		},

		setPrevCate : function(cate){
			this.prevCate = cate;
		},

		getPrevCate : function(){
			return this.prevCate;
		},

		//get menu name
		getMenu : function(){
			return this.menu;
		},

		//handel to category setting
		setMenu : function(){
			this.category.setCategoryList(this.getMenu(), this);
			try{this.category.toggleCate('cate_0');}catch(e){}
			if(this.orgCate_1!=0) this.mSet(this.orgCate_1);
		},

		mSet : function(cateNo){
			//this.category.toggleCate("cate_"+cateNo);
		},

		setFeaturedVideo : function(){
			var video = this.getJson('featuredVideo');
			var tmp = new pandora.util.StringBuffer();
			var list = new pandora.util.StringBuffer();
			var tmpl = new Template(html.getChild('mainFeatureA').toString());
			var tmpl2 = new Template(html.getChild('mainFeatureBList').toString());
			var scoreView = cScoreView.getInstance();

			if(parseInt(video[0]['resol']) >= 720) {
				video[0]['fvHD'] = "<img src="+variable.getChild("designHost")+"img/channel/icon_hd.gif width=32px height=15px>";
			}
			video[0]['valuation_point'] = scoreView.set(video[0]['valuation_point']);

			if(video[0]['thumbnail_path']!=''){
				video[0]['thumb'] = variable.getChild("vodThumbImg")+video[0]['thumbnail_path'];
			}else{
				video[0]['thumb'] = getVodThumbnail(video[0]['ch_userid'],video[0]['prgid']);
			}
			//video[0]['thumb'] = getVodThumbnail(video[0]['ch_userid'],video[0]['prgid']);
			video[0]['category'] = oVodCateg.getLevel1Name(video[0]['category1']) + " > " + oVodCateg.getLevel2Name(null, video[0]['category2']);

			tmp.append(tmpl.evaluate(video[0]));
			var mFeaturedCnt = (video.length > 4) ? 4 : video.length;
			for(var i=1; i<=mFeaturedCnt; i++) {
				if(parseInt(video[i]['resol']) >= 720) {
					video[i]['fvHD'] = "<img src="+variable.getChild("designHost")+"img/channel/icon_hd.gif width=32px height=15px>";
				}
				if(video[i]['thumbnail_path']!=''){
					video[i]['thumb'] = variable.getChild("vodThumbImg")+video[i]['thumbnail_path'];
				}else{
					video[i]['thumb'] = getVodThumbnail(video[i]['ch_userid'],video[i]['prgid']);
				}
				//video[i]['thumb'] = getVodThumbnail(video[i]['ch_userid'],video[i]['prgid']);
				video[i]['category'] = oVodCateg.getLevel1Name(video[i]['category1']) + " > " + oVodCateg.getLevel2Name(null, video[i]['category2']);
				list.append(tmpl2.evaluate(video[i]));
			}

			tmp.append(html.getChild('mainFeatureBBody').toString().replace(/#\{featureList\}/gi, list.toString()));

			var tt = html.getChild('mainFeature').toString().replace(/#\{featured\}/gi, tmp.toString())
			$('mainFeatured').update(tt);

			video, tmp, list, scoreView = null;

			this.setFeaturedEventListener();
		},

		evtFunc : function(evt){
			var el = Event.element(evt);

			if(el.tagName.toUpperCase() == "A" && el.id!='') {
				var arr = el.id.split('_');
				var fid = arr[0].toString();
				var pid = arr[1].toString();
				switch(fid){
					case 'c1' : {break;}
					case 'c2' : {break;}
					case 'share' : {
						shareD.set(pid, evt);
						break;
					}
					case 'playlist' : {
						var obj = this.getJson('featuredVideo')[0];
						_prgBagInstance.append(pid, obj['title'], obj['runtime'], obj['ch_name'], obj['ch_userid']);
						break;
					}
				}
			}
		},

		setFeaturedEventListener : function(){
			Event.observe($('mainFeatured'),'click',this.evtFunc.bind(this));
		},

		viewTopic : function(menu){
			var url = "/data/main_json/main_hot" + this.lang + ".js";
			new Ajax.Request(url,{
				method : 'get',
				onSuccess : function(res){
					var json = res.responseText.evalJSON();
					var topic = json.hotTopics;
					var tmp = new pandora.util.StringBuffer();
					var tmpl = new Template(html.getChild('mainTopicContent').toString());

					for(var i=0; i<topic.length; i++) tmp.append(tmpl.evaluate(topic[i]));

					$('cateTopic').update(html.getChild('mainTopic').toString().replace(/#\{topics\}/gi, tmp.toString()));
					topic, tmp = null;
					this.category.setEventListener('topic');
				}.bind(this),

				onException : function(){
					//throw new Error('main js fail');
				}
			});
/*
//			if(menu=="main"){
 				var topic = this.getJson('hotTopics');
				var tmp = new pandora.util.StringBuffer();
				var tmpl = new Template(html.getChild('mainTopicContent').toString());

				for(var i=0; i<topic.length; i++) tmp.append(tmpl.evaluate(topic[i]));

				$('cateTopic').update(html.getChild('mainTopic').toString().replace(/#\{topics\}/gi, tmp.toString()));
				topic, tmp = null;
				this.category.setEventListener('topic');

//			}else if(menu=="video"){

//			}
*/
		}

	}

var mainC = new pandora.main.menu();

