
ftcImage = {};
		
		ftcImage.items = [];
		//diashow object:
		ftcImage.diashow = null;
		//image preload switch:
		ftcImage._is_loaded = false;
		//image currently fading switch:
		ftcImage._in_fade = false;
		//how many images in album ? if none - no diashow.
		ftcImage._img_in_album = 0;
		//social bookmarking ? update links ?:
		ftcImage._update_bookmarks = false;
		
		ftcImage.init = function()
		{
			//bookmarking links at bottom of page:					
			try{				
				if(ftc_bookmark_services.length && 0 == ftcImage.data.public_password) 
					ftcImage._update_bookmarks = true;
			}catch(e){};
				
			ftcImage._filterItems();
			//if there is no image at all we disable diashow link:
			if(0==ftcImage._img_in_album){
				try{
					UTIL.element("diashow_start").style.display = "none";
				}catch(e){};
			}
			var pager = new ftcPaging(ftcImage.items.length,"image_pager",ftcImage._load);
			pager.draw();

			var active_index = ftcImage.getObject(ftcImage.actve_obj);	
			ftcPaging._select(active_index+1);	
			//comments:							
				gb.pages= [ftcImage.items[active_index].object_comments];			
				gb._navigate(1);
			
		}

    ftcImage.clean_path = function(path) {
      if(typeof(lp_view) != "undefined") {
        var new_path = path.replace(/http.*\/\/.*?\//, "/");
        return new_path;
      } else {
        return path;
      }
    }

		//==============================================
		ftcImage._filterItems = function()
		{
			var all_items = ftcImage.data.items;
			var item;
			//for diashow. if here is no image at all (only videos) we need to switch off diashow.
			var img_count = 0;
			for(var i=0;i<all_items.length;i++){
				item = all_items[i];
				if("other"!=item.media_type && "audio"!=item.media_type) ftcImage.items.push(item);
				if("image"==item.media_type) img_count++;
			}
			ftcImage._img_in_album = img_count;
		}
		//============================================
		ftcImage._getNode = function()
		{
			try{
				return document.getElementsByName("ftcPublicImage")[0];
			}catch(e){return false}
		}
		//=============================================
		ftcImage.getObject = function(object_id,in_all)
		{
			var items = (true==in_all) ? ftcImage.data.items : ftcImage.items;
			for(var i=0;i<items.length;i++){
				if(object_id== items[i].object_id) return i;
			}
			return false;
		}
		
		ftcImage.audio_icon = false;
		//==============================================
		/**
		* this is called from ftcPaging._select.
		* the diashow object triggers the same function - so thatt arrives here too.
		**/
		ftcImage._load = function(no)
		{
			ftcImage._load.no = no;
			//get item to show:
			var item = ftcImage.items[parseInt(no)-1];
			//fading only for images:
			if("image"==item.media_type){
				//start fading out of current img:
				//the current item might be a video or we're trying the first on wnidow load - that is handled in fadeOut().
				ftcImage._fadeOut(10);
				//preload image to show:
				var img = UTIL.newNode("IMG");
				
				ftcImage._in_fade = true;
				img.onload = function(){
          ftcImage._is_loaded = true;
          // special Live Pages call
          try { if (typeof parent == 'object' && typeof parent.resizeLPFrame == 'function') parent.resizeLPFrame() } catch(e) {}

        };
        img.src = ftcImage.clean_path(item.src_medium);
			}else{
				//video - no fading:
				 ftcImage._in_fade = false;									
				ftcImage._navigate(no);
			}				
		}
		//we store the current requested item here:
		ftcImage._load.no = 0;
		/**
		*fading images
		*****************************************************/
		ftcImage._fadeOut = function(trans)
		{
			//get the DOM img element:
			var img = ftcImage._getNode();
			//fading is finished or there was no img to fade at all:
			if(0==trans || false == img){
				ftcImage._navigate(ftcImage._load.no);				
				 return;	
				}		
			
			try{			 
			trans--;
			img.className = "theme_picture_frame trans_"+trans;
			window.setTimeout("ftcImage._fadeOut("+trans+")",25);
		}catch(e){ftcImage._navigate(ftcImage._load.no);};
	}
	/**
	* this is called when _navigate is done:
	**/
	ftcImage._fadeIn = function(trans)	
	{	
		//image is not loaded yet - try again later:
		if(false==ftcImage._is_loaded){
			window.setTimeout("ftcImage._fadeIn("+trans+")",100);			
			return;
		}
		//fade in is done:
			if(10==trans){
				// in diashow mode - call timer:
				if(true==dbdDiashow.is_on){
					ftcImage.diashow.timer = window.setTimeout("ftcImage.diashow.move()",ftcImage.diashow.duration);
				}
				//else just stop doing anything.
				return;
			}
			//do fade in:
		var img = ftcImage._getNode();
		try{
			trans++;
			img.className = "theme_picture_frame trans_"+trans;
			window.setTimeout("ftcImage._fadeIn("+trans+")",25);
		}catch(e){return}
	}	
		/*****************************************************/
		//=========================================
		ftcImage._navigate = function(no)
		{	
					
			var img = ftcImage.items[parseInt(no)-1];
			ftcImage.active_obj= img.object_id;
     		 ftcImage.current_obj = img;
     						
			var s, output=true;			
			if("image"==img.media_type){
        // <img src=\"/mediacenter/public_static/pix/dummy.gif\" class=\"cover_image\">
				s = "<div id=\"ftc_img_cont\"><div id=\"ftc_img_cont_inline_span\" style=\"position:relative; display:inline;\"><img id=\"i"+img.object_id+"\" class=\"theme_picture_frame trans_0\" src=\""+ftcImage.clean_path(img.src_medium)+"\" name=\"ftcPublicImage\"  onload=\"ftcImage._getSize();\" /></div></div>";
				
			}else if("video"==img.media_type){	
				//easyvideo:
				if("flv"==img.suffix){
					var video = new EasyVideo(img);
					video.obj.write("image_content");
					output = false;
				}else{	
					//regular video:		
					s= playVideo(ftcImage.clean_path(img.src_prev));
					s+= "<br><a href=\""+ftcImage.clean_path(img.src_prev)+"\" target=\"_blank\">"+txt.open_window_for_video+"</a>";
				}
			}
			if(true==output){
				UTIL.element("image_content",s);
			}
			//draw descriptions:
			s = "<span class=\"i-title\">"+img.title+"</span>";
			var changed = new dbdDate(img.unix_changed*1000,txt.public_standard_date);
			
			/*
			var month = changed.getMonth();
			var year = changed.getFullYear();
			var datum = day+"."+(month+1)+"."+year;
			*/
			s+= "<span class=\"i-changed\"><table align=\"center\"><tr><td>"+changed.toString()+"</td>";
      if(img.GPS_LATITUDE) {
        if((show_map_links && img.GEO_MAP_ON != "OFF") || img.GEO_MAP_ON == "ON") {
          s+= "<td style=\"padding-left:10px\"><img title=\""+txt.show_on_map+"\" src=\""+ map_icon.src +"\" onmouseover=\"this.src = map_icon_h.src\" onmouseout=\"this.src = map_icon.src\" style=\"cursor:pointer\" onclick=\"ftcImage.call_geo_action(" + img.GPS_LATITUDE + "," + img.GPS_LONGITUDE + "," + img.PARENT_ID + "," +img.OBJECT_ID + ")\"></td>";

        }
      }

      s+= "</tr></table></span>";
try
{
  s+= "<span class=\"i-memo\">"+UTIL.convert2Link(img.memo,true)+"</span>";
}
catch (e)
{
  s+= "<span class=\"i-memo\">" + img.memo +"</span>";
}
			//tags:
try
{
  			if(img.tags.length){
				var tags = img.tags.join(", ");
				s+= "<span class=\"memo\">Tags: "+tags+"</span>";
			}	
}
catch (e)
{
}

			UTIL.element("image_title",s);
			//comments:
			//clear:
			UTIL.element("guestbook_entry","&nbsp;");
			gb.pages= [img.object_comments];			
			gb._navigate(1);
			//attachments:
			if(img.attached_object_id){				
				var id = ftcImage.getObject(img.attached_object_id,true);	
						
				if(false!==id){
					var item = ftcImage.data.items[id];									
         			 ftcImage.drawAttachment(item);
         			 ftcImage.audio_icon = true;
				
			}else{
				 UTIL.element("audio_container","&nbsp;");
				 ftcImage.audio_icon = false;				 
      		}
		}
      // rating
      if(1==ftcImage.data.ranking_allowed) {
        ftcImage.render_ranking_value();
      }
      //fading:
      if(true==ftcImage._in_fade){
     window.setTimeout("ftcImage._fadeIn(1)",1);
      }else {
      		try{
      			ftcImage._getNode().className = "theme_picture_frame";
      		}catch(e){};
			}
			//update bookmarking links ?
			if(true==ftcImage._update_bookmarks) ftcImage.drawBookmarks(img);

  		img.onload = function(){
        ftcImage._is_loaded = true;
        // special Live Pages call
        try { if (typeof parent == 'object' && typeof parent.resizeLPFrame == 'function') parent.resizeLPFrame() } catch(e) {}

      };

		}
		//=============================================
		ftcImage._getSize = function(e)
		{
			ftcImage.img_is_loaded = true;
			if(!browser.isIE || false==ftcImage.audio_icon) return;
			//IE 8 will quit here too:
			//UTIL.showVar(browser);
			if(8>=parseInt(browser.versionMajor)) return;
			var icon = UTIL.element("ftcaudioplay");
			var id = "i"+ftcImage.active_obj;
			var img = UTIL.element(id);
			var left = img.offsetWidth-60;
			var top = img.offsetHeight-30;
			
		
			icon.style.left = left+"px";
			icon.style.top = top+"px";
		}
		//==========================================
		ftcImage.drawAttachment = function(item)
		 {		
		 	//alert("case"); 
          var container = UTIL.element("ftc_img_cont_inline_span");
          var img = UTIL.newNode("IMG","ftcaudioplay");
          var src = "/mediacenter/public_static/pix/";
          src+= ("audio"==item.media_type) ? "icon_audio.jpg" : "icon_pdf.jpg";
          img.src = src;
         // img.className = "audio_image";
          //img.src = "/mediacenter/public_static/pix/icon_audio.jpg";
          img.style.width = "59px";
          img.style.height = "30px";
          img.style.position = "absolute";
          img.style.zIndex = 100;
          img.style.bottom = "20px";
          img.style.right = "20px";
          img.style.cursor = "pointer";
          img.url = ftcImage.clean_path(item.src_prev);
          img.type = item.media_type;
          container.appendChild(img);
          Handler.add(img,"click",ftcImage._attachmentdClick);
        }
		//=========================================
		ftcImage._attachmentdClick = function(e)
		{
			e = e || window.event;
			if("audio"==e.target.type){
				ftcImage.playAudio(e.target.url);
			}else{
				window.open(e.target.url);
			}
		}
		//=============================================
		ftcImage.playAudio = function(src)
		{
			var s = playAudio(src);
			UTIL.element("audio_container",s);
		}
		//=============================================
    // IMAGE RANKING - RATING
		//=============================================
    ftcImage.display_rating = function() {
      UTIL.element("guestbook_new_entry", UTIL.element("ranking_content").innerHTML);
      try { if (typeof parent == 'object' && typeof parent.resizeLPFrame == 'function') parent.resizeLPFrame() } catch(e) {}
    }
		//=============================================
    ftcImage.do_rate = function(howmany) {
      var req = {}
      req.url = "/mediacenter/public_action/rating.php";
      req.rated_stars = howmany;
      req.file_name = ftcImage.current_obj.title;
		req.album_name = ftcImage.data.name;
      req.object_id = ftcImage.active_obj;
      req.parent_id = ftcImage.album_id;
      req.curr_r_value = ftcImage.current_obj.ranking_value;
      req.curr_r_count = ftcImage.current_obj.ranking_counter;
      HTTP.post(req.url,req,ftcImage._rating_callback); 

    } 
		//=============================================
    ftcImage.render_ranking_value = function() {
      // set ranking value
      var r_max = 100;
      var r_pixel_max = 158;
      var r_stars = 5;

      var r_pixel_gran = r_pixel_max / r_max;
      var r_display_width = Math.floor(ftcImage.current_obj.ranking_value * r_pixel_gran);

      var r_bite = r_max / r_stars;
      var r_current_stars = (ftcImage.current_obj.ranking_value / r_bite);
      var stars_2_comma = r_current_stars * 10;
      stars_2_comma = Math.floor(stars_2_comma);
      stars_2_comma = stars_2_comma / 10;
      var tobi_voll = Math.floor(r_current_stars);

      var tobi_width = Math.round(8 + (tobi_voll * 30) + ((r_current_stars - tobi_voll) * 23));
      r_display_width = tobi_width;

      UTIL.element("ranking_bar").style.width = r_display_width + "px";
      UTIL.element("ranking_string").innerHTML = stars_2_comma + txt.ranking_n_of_5 + " (" + ftcImage.current_obj.ranking_counter + txt.ranking_n_amount + ")";
    }
		//=============================================
    ftcImage._rating_callback = function(r) {
      var img_html_page = "image.html";
      if(typeof(lp_view) != "undefined") {
        img_html_page = "lp_image.html";
      }
      if(r == "0") {
        alert(txt.error_ranking);
      } else {
        ftcImage.current_obj.ranking_value = r;
        ftcImage.current_obj.ranking_counter++;
        ftcImage.render_ranking_value();
      }

      var url = img_html_page + "?preview=1&album_id="+ftcImage.album_id+"&index="+ftcImage.active_obj + (typeof(get_string) != "undefined" ? get_string : '');
      window.location.href = url;
    }
		//=============================================
/* GLOBAL FUNCTIONS */

// play video file
// nees an element("videoLayer")
// IN: string videofile (full URL)
// ... attenzione: there are hard coded player measures
function playVideo(videofile) {
  var htmlstring = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="450" width="600"><param name="src" value="' + videofile + '"><param  name="autoplay" value="true"><param name="controller" value="false"><embed width="600" height="450" src="' + videofile + '" pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" controller="true" autoplay="true"></object>';
	return htmlstring;
 
}
// play audio file
// nees an element("audioLayer")
// IN: string audiofile (full URL)
function playAudio(audiofile) {
  var htmlstring = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="0" width="0"><param name="src" value="' + audiofile + '"><param name="autoplay" value="true"><param name="controller" value="false"><embed height="0" width="0" src="' + audiofile + '" pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" controller="false" autoplay="true"></object>';
 return htmlstring;
}



/**
* dia show
***************************************************/
/**
*this is called from diashow button and switches diashow on/off
* diashow object will be instanized when this is called the first time.
*after that it only switches the dbdDiashow._is_on switch.
**/
ftcImage.diaShow = function()
{
	//first time pressing diashow button:
	if(null==ftcImage.diashow){
		var slide = new dbdDiashow(ftcPaging.obj.items,ftcPaging._select);
		//store object here:
		ftcImage.diashow = slide;
		//get video pages - we want to skip them
		var len = ftcImage.items.length;
		var item, result = [];
		for(var i=0;i<len;i++){
			item = ftcImage.items[i];
			if("video"==item.media_type) result.push(i+1);
		}
		slide.skip(result);					
	}
	//diashow starts with the current + 1 page:
	//Caution ! Rewrite fading before changing this to current.

	ftcImage.diashow.setPage((ftcPaging.obj.active+1));
	//switching diashow on/off is done there:
	dbdDiashow.work();
	//set page button:
	var d_txt = (dbdDiashow.is_on) ? txt.diashow_stop : txt.diashow_start;
	var d_link = UTIL.element("diashow_start",d_txt);
	d_link.className = (dbdDiashow.is_on) ? "btn-dia-on" : "btn-dia";
	d_link.blur();
}

	//bookmarking section:
	ftcImage.drawBookmarks = function(img)
	{
		var bookmarks = ftc_bookmark_services;
		var len = bookmarks.length;
		var s = "";
		for(var i=0; i<len; i++){
			s+= ftcImage.drawBookmarkItem(bookmarks[i], img);
		}
		try{
			var container = UTIL.element("ftc_bookmark_services",s);
			container.style.display = "block";
		}catch(e){};
	}
	
	ftcImage.drawBookmarkItem = function(item, img)
	{
		
		var url = item.url;		
		var src = ftcImage.clean_path(("image"==img.media_type) ? img.src_medium : img.src_prev);
		if(""==item.src) url+= src;
		else url+= item.src+"="+src;
		for(var i in item){
			if("object" != typeof item[i]) continue;
			if(img.hasOwnProperty(i)){
				//tags:
				if("tags"==i && img.tags.length){
					var tags = img.tags.join(" ");
					url+= "&"+item.tags[0]+"="+escape(tags);
				}else{
					url+= "&"+item[i][0]+"="+escape(img[i]);
				}
			}
		}
		var s = "<a href=\""+url+"\" target=\"_blank\" class=\"bookmark-link\" style=\"background:"+item.icon+"\" ";
		s+= " title=\""+item.name+"\" ";
		s+= "></a>";
		return s;
	}

  ftcImage.call_geo_action = function(lat, lon, p_id, o_id) {

    map_urls["GOOGLE_KML_OPEN"] = public_url + "google_kml/" + ftcImage.album_id + "/google_earth_" + o_id + ".kml";
    if(geo_map_service != "GOOGLE_KML_OPEN") {
      var url = map_urls[geo_map_service].replace(/<%LAT%>/, lat);
      url = url.replace(/<%LONG%>/, lon);
      url = url.replace(/<%LAT%>/, lat);
      url = url.replace(/<%LONG%>/, lon);
      window.open(url);
      return;
    }
    window.open(map_urls[geo_map_service]);
  }
