KinoTrailer= function(){
	
	//private vars
	var defaults={basePath:'/',
				  path:'/kino/',
				  jsonPath:'json/',
				  pathTemplate:'template/',
				  pathTrailer:'trailers/'
				  }
	
	
	this.kinoTrailerIndex = new Array();
	
	var _this=this;

	_init=function(){	
	//reads the json file
		readJson=function(data) { 
			_this.kinoTrailerIndex=data;
			//get the template
			var _templateTrailerIndex=new TemplateReader();
				_templateTrailerIndex.read(defaults.path+defaults.pathTemplate+"kinotrailer-index.html","#kinoTrailerIndexContainer");
				
			//update template with dates
			chainParams={container:'#kinoTrailerIndex'};
			_templateTrailerIndex.update(data,"#kinoTrailerIndexContainer", chainParams);
			_cnt=0;
			
			//update tempalte with trailers in each date
			jQuery('#kinoTrailerIndex .item').each(function(){	
								 
				 //adds tempalte fro updating with trailers 
				
				clickEvent='';
				 if(document.location.href.indexOf("/kino/")>-1){clickEvent='return false';}
				$(this).append('<ul id="'+_cnt+'"><li class="item"><a class="linkTrailer"  onclick="'+clickEvent+'" ><span class="name"></span></a></li></ul>')
				chainParams={container:"#"+_cnt,'.linkTrailer':{href: defaults.path+'trailers.php?group='+_cnt+'&id={id}&name={name}'},title:'{name}'};
				 _templateTrailerIndex.removeOldItems=false;
				 //update with trailers
				_templateTrailerIndex.update(data[_cnt].trailer,"#kinoTrailerIndex", chainParams);
				 _cnt++;
			 }); 
		};
		
		jQuery.ajax({
  		url: defaults.path+defaults.jsonPath+'kinoTrailer.json',
  		dataType: 'json',
  		success: readJson,
		async:false
		});
	}
	

//show the trailer
	this.showTrailer=function(group,id){
		_group=this.kinoTrailerIndex[group];
		for(i=0;i<_group.trailer.length;i++){
			if(_group.trailer[i].id==id){
				_trailer=_group.trailer[i];
				break;
			}
		}
		jQuery('#video').html( ' <object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="374">'+
					  '<param name="movie" value="/videoplayer.swf?moviepath='+defaults.path+defaults.pathTrailer+_trailer.flvFile+'&autoPlay=true&autoStart=true " />'+
                      '<param name="quality" value="high" />'+
					  '<param name="wmode" value="opaque" />'+
                      '<param name="swfversion" value="8.0.35.0" />'+
                      <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
                      '<param name="expressinstall" value="Scripts/expressInstall.swf" />'+
                      <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
                      <!--[if !IE]>-->
                      '<object type="application/x-shockwave-flash" data="/videoplayer.swf?moviepath='+defaults.path+defaults.pathTrailer+_trailer.flvFile+'" width="480" height="374">'+
                        <!--<![endif]-->
                        '+<param name="quality" value="high" />'+
						'<param name="wmode" value="opaque" />'+
                        '<param name="swfversion" value="8.0.35.0" />'+
                        '<param name="expressinstall" value="Scripts/expressInstall.swf" />'+
                        <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
                        '<div>'+
                          '<h4>Content on this page requires a newer version of Adobe Flash Player.</h4>'+
                          '<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>'+
                        '</div>'+
                        <!--[if !IE]>-->
                      '</object>'+
                      <!--<![endif]-->
                    '</object>'+
					'<a href='+_trailer.url+' target="_blank">'+_trailer.description +'</a>');

	}


	this.addClickEvent=function(){jQuery("#kinoTrailerIndex ul li a.linkTrailer").live('click',function(event){
		//read url 
		
		get_url=this.href;
		//split url by "?"
		get_url=get_url.split("?")
		get_url_string=get_url[1];
		//split string by "&"
		get_group=get_url_string.split("&")
		get_group_no=get_group[0]
		get_id=get_group[1]
		//get group portion and split by =
		get_group_no=get_group_no.split("=")
		get_group_no=get_group_no[1]
		//get id portion and split by =
		get_id_no=get_id.split("=")
		get_id_no=get_id_no[1];
		_this.showTrailer(get_group_no,get_id_no);

	});
	}
	_init();// initialize the object, creates dates and trailers from json
	this.addClickEvent();
}

