var VideoObj = Class.create({
	initialize: function(name){
		this.name = name;
		this.lastClickedItem = false;
		this.topVideoCurrentPage = 1;
		this.topVideoNextButton = 1;
		this.topVideoPrevButton = 0;
	},
	Click: function(oParams){
		var baner = $('baner');
		if(oParams.producent){
			var gdzie_kupic = $('gdzie_kupic');
			new Ajax.Updater('gdzie_kupic','/ajaxx/gdzie_kupic/'+oParams.producent+'/1');
		} else {
			$('gdzie_kupic').update('');
		}
		new Ajax.Request('/video/getVideoLink/'+oParams.video,{
			onSuccess: function(transport){
				$('input_video_link').value = transport.responseText;
			}
		});
		new Ajax.Updater('baner','/ajaxx/inwokacja/iframe_video300x250',{evalScripts:'true'});

		$('video_title').update(oParams.title);
		new Ajax.Request('/video/counter',{method: 'post',parameters: {video_id: oParams.video}});

		ytplayer.loadVideoById(oParams.videoId,0,'large');
	},
	Page: function(oParams){
		var baner = $('baner');
		var unique = oParams.type + oParams.query + oParams.category + oParams.page;
		if(this.lastClickedItem == unique) return true;
		else {
			new Ajax.Updater(
				'videos',
				'/video/videos/'+oParams.type+','+oParams.query+',' + oParams.category+','+oParams.page,
				{
					asynchronous:true
//					onLoading: $('videos').update("<img src=\"/img/loading2.gif\" alt=\"ładuje...\" />")
				}
			);
			if(oParams.type=='producent'){
				new Ajax.Updater('gdzie_kupic','/ajaxx/gdzie_kupic/'+oParams.query+'/1');
			}
			this.lastClickedItem = unique;
		}
	},
	Producent: function(){
		new Ajax.Updater('videos','/video/producent/all');
	},

	Top: function(num){
		if(num == 1){
			if(this.topVideoNextButton == 0) return true;
			this.topVideoCurrentPage += 1;
			if(this.topVideoCurrentPage == 10) {
				this.topVideoNextButton = 0;
				$('video_top_next').select('img').each(function(obj){obj.src='/img/btn_next_off.gif'});
				new Ajax.Updater('video_top','/video/top/3/'+this.topVideoCurrentPage+"/0");
				return true;
			}
			this.topVideoPrevButton = 1;
			if(Element.readAttribute($('video_img_top_prev'),'src') == '/img/btn_prev_off.gif') $('video_img_top_prev').src='/img/btn_prev.gif';

			new Ajax.Updater('video_top','/video/top/3/'+this.topVideoCurrentPage+"/0");
		}
		else if(num == -1){
			if(this.topVideoPrevButton == 0) return true;
			this.topVideoCurrentPage -= 1;
			if(this.topVideoCurrentPage == 1) {
				this.topVideoPrevButton = 0;
				$('video_top_prev').select('img').each(function(obj){obj.src='/img/btn_prev_off.gif'});
				new Ajax.Updater('video_top','/video/top/3/'+this.topVideoCurrentPage+"/0");
				return true;
			}
			this.topVideoNextButton = 1;
			if(Element.readAttribute($('video_img_top_next'),'src') == '/img/btn_next_off.gif') $('video_img_top_next').src='/img/btn_next.gif';
			new Ajax.Updater('video_top','/video/top/3/'+this.topVideoCurrentPage+"/0");
		}
	}
});
var Video = new VideoObj('Video');

// menu
var MenuObj = Class.create({
	initialize: function(id){
		this.id = id;
		this.element = $(this.id);
		this.lastVisibleItem = false;
		//this.Hide();
	},
	Item: function(oParams){
		var item = $(oParams.id);
		if(item){
			if(this.lastVisibleItem == oParams.id) (item.visible()) ? item.setStyle({display:'none'}) : item.setStyle({display:'block'});
			else {
				this.Hide();
				item.setStyle({display: 'block'});
				this.lastVisibleItem = oParams.id;
			}
		} else {
			this.Hide();
		}
	},
	Hide: function(){
		$(this.id).select('.menu_sub').invoke('hide');
	},
	Click: function(obj){
		var str='';
		$(this.id).select('li').each(
			function(ob){
				ob.className = 'video_inactive';
			}
		);
		if(Prototype.Browser.IE) {
			if(obj.up().id == 'main_menu') obj.className = 'video_active_ie';
			else obj.className = 'video_active';
			event.cancelBubble = true;
		} else {
			obj.className = 'video_active';
		}
	}
});
var Menu = new MenuObj('main_menu');

