var excludeCount = 0;
var flg_y = false;
var flg_z = false;
var cls_video_search = function(){
	this.youtube_video = new cls_youtube_video(5);//amebaうまく取れないのでとりあえず4→5に変更
	this.ameba_video = new cls_ameba_video(3);
	this.zoome_video = new cls_zoome_video(5);//amebaうまく取れないのでとりあえず3→5に変更
};

//メソッド定義
cls_video_search.prototype = {
	//画像検索メソッド
	search : function(word) {
		//youtube画像検索
		youtubeRet = this.youtube_video.search(yt_word ? yt_word : word);
//		amebaRet = this.ameba_video.search(word);
		zoomeRet = this.zoome_video.search(zm_word ? zm_word : word);
//		if(youtubeRet && amebaRet && zoomeRet){
		if(youtubeRet && zoomeRet){
			return true;
		}
		return false;
	},
	//次のページを検索
	nextpage: function(word){
		this.search(word);
	},
	//画像リスト取得メソッド
	get : function(){

		var tmpData = null; //除外リスト判定用一時変数
		if(movie_take_count > 0){
			var maxCount = per_page - movie_take_count;
			//抽出件数指定がある＝追加リクエスト
			var api = this.getMostResultAPI();
			data = api.getImages();
			dataCount = api.length;
			var list = new Array();

//			var count = 0;
			for(var i=0; i<maxCount; i++){
				if(data.length == 0) {
					break;
				}
				tmpData = data.shift();
/*
				if(movie_excludeList.indexOf(tmpData['id']) === false){
						list.push(tmpData);
					}else{
						excludeCount++;
					}
*/
				var is_match = false;
				for(index in movie_excludeList){
					if(movie_excludeList[index]['vid'] == tmpData['id']){
						is_match = true;
						excludeCount++;
						break;
					}
				}
				if(is_match == false){
					list.push(tmpData);
//					if(api.per_page <= count){
//						api.setImages(data);
//						break;
//					}
				}
			}
			if (data.length) api.setImages(data);

			return list;
		}

		youtubeData = this.youtube_video.getImages();
		youtubeCount = youtubeData ? youtubeData.length : 0;
		amebaData = this.ameba_video.getImages();
		amebaCount = amebaData ? amebaData.length : 0;
		zoomeData = this.zoome_video.getImages();
		zoomeCount = zoomeData ? zoomeData.length : 0;
		var list = new Array();

		var count = 0;
		for(var i=0; i<youtubeCount; i++){
			tmpData = youtubeData.shift();

			var is_match = false;
			for(index in movie_excludeList){
				if(movie_excludeList[index]['site'] == 'yt' && movie_excludeList[index]['vid'] == tmpData['id']){
					is_match = true;
					excludeCount++;
					break;
				}
			}
			if(is_match == false){
				count++;
				list.push(tmpData);
				if(this.youtube_video.per_page <= count){
					this.youtube_video.setImages(youtubeData);
					break;
				}
			}
		}

		var count = 0;

		for(var i=0; i<amebaCount; i++){
			tmpData = amebaData.shift();

			var is_match = false;
			for(index in movie_excludeList){
				if(movie_excludeList[index]['site'] == 'am' && movie_excludeList[index]['vid'] == tmpData['id']){
					is_match = true;
					excludeCount++;
					break;
				}
			}
			if(is_match == false){
				count++;
				list.push(tmpData);
				if(this.ameba_video.per_page <= count){
					this.ameba_video.setImages(amebaData);
					break;
				}
			}
		}

		var count = 0;
		for(var i=0; i<zoomeCount; i++){
			tmpData = zoomeData.shift();

			var is_match = false;
			for(index in movie_excludeList){
				if(movie_excludeList[index]['site'] == 'zm' && "http://zoome.jp/" + movie_excludeList[index]['vid'] == tmpData['video']){
					is_match = true;
					excludeCount++;
					break;
				}
			}
			if(is_match == false){
				count++;
				list.push(tmpData);
				if(this.zoome_video.per_page <= count){
					this.zoome_video.setImages(zoomeData);
					break;
				}
			}
		}

		return list;
	},
	//結果件数の一番多いAPIを返す
	getMostResultAPI : function(){
		var cntY = this.youtube_video.total - this.youtube_video.get_count;
		var cntA = this.ameba_video.total - this.ameba_video.get_count;
		var cntZ = this.zoome_video.total - this.zoome_video.get_count;

		if(cntY >= cntA && cntY >= cntZ){
			return this.youtube_video;
		}

		if(cntZ >= cntA){
			return this.zoome_video;
		}

		return this.ameba_video;
	},
	//検索総画像数を取得
	getResultCount : function(){
		var cntY = parseInt(this.youtube_video.total);
		var cntA = parseInt(this.ameba_video.total);
		var cntZ = parseInt(this.zoome_video.total);
		return cntY + cntA + cntZ;
	},
	//検索可否メソッド
	is_request : function() {
			return this.youtube_video.requestFlg  || this.ameba_video.requestFlg || this.zoome_video.requestFlg;
	},
	//プール存在チェック
	is_poolData : function() {
		var yp = this.youtube_video.youtube_pool_data ? this.youtube_video.youtube_pool_data.length : 0;
		var ap = this.ameba_video.ameba_pool_data ? this.ameba_video.ameba_pool_data.length : 0;
		var zp = this.zoome_video.zoome_pool_data ? this.zoome_video.zoome_pool_data.length : 0;

		if(yp > 0 || ap > 0 || zp > 0){
			return true;
		}

		return false;
	}
};

//配列関数の拡張 配列内の検索
Array.prototype.indexOf = function(s){
	for(var i = 0; i < this.length; i++){
		if(this[i] == s){
			return i;
		}
	}
	return false;
};

//
function movie_org_stop(){
	if(flg_y == true && flg_z == true){
		movie_loadOk = true;
		if(movie_first) {
			$j("#movie_list .more2 a").click();
		}
	}
}
