/*global YAHOO */
var VideoSharing = {
/***********************************************************
* IS24 Video Sharing, JS Bibliothek V0.1 BETA
* Constants to use:
************************************************************/
	undefinedURL: "Video URL could not be fetched. Sorry.",   	//Error message for undefined URL
	fetchVideoURL: "/videoservice",                   			//do not use absolute : "http://localhost:6969/videoservice/internal";  
	defaultVideoWidth: 118,                                     //deafult player width
	defaultVideoHeight: 116,                                    //deafult player heigth
	ajaxRequestTimeout: 5000,									//timeout in milliseconds before request failure gets called
	refreshVideoStatusTimeout: 12000,							//timeout in milliseconds before fetch URL again gets called (video is in progress)
	fetchURLMethodName: "fetchVideoURL",						//method name
	fetchDescriptionMethodName: "fetchVideoDescription",		//method name
	retryURLFetchesCount: 20,									//how oft to retry the fetch URL after error response
	convertProcessImage: "/published-images/converting_video.gif",	//image url of picture for process convert activ
	failedProcessImage: "/published-images/videoservice_convert_error.gif",	//Fehler_load_service.gif",	
	unaviableProcessImage: "/published-images/videoservice_temp_error.gif",	//Fehler_load_video.gif",
	wrongFileFormatImage: "/local/cms/is24/img/wrong-format.gif", // error pic in case of wrong file format
	convertProcessImageALT: "Video wird konvertiert...",		//ALT Text for last						
	failedProcessImageALT: "Videokonvertierung fehlgeschlagen",		
	wrongFileFormatImageALT: "falsches Dateiformat",
	unaviableProcessImageALT: "Service nicht verf&uuml;gbar",		
//*****************************************************CONFIG END*****************************************

	allVideoLayersByDivID: new Array(),
	descriptionElement: null,

fetchVideo : function (videoid, divLayerName, width, height, additonalElements, customStillImage, clickOnDisplay, showDetails, popUpTargetName, designData){
  this.fetchVideoData(videoid, divLayerName, width, height, additonalElements, customStillImage, clickOnDisplay, showDetails, popUpTargetName, designData);
},

showVideoDescriptionInElement : function(videoid, textControlElementName){
    var requestURL = this.fetchVideoURL + "?method=" + this.fetchDescriptionMethodName + "&videoid=" + videoid + "&timestamp=" + new Date().valueOf();    
	VideoSharing.descriptionElement = textControlElementName;
    var fetchVideoURLcallback ={
      success: this.showVideoDescriptionCB,
      failure: this.showVideoDescriptionCB,
      timeout: this.ajaxRequestTimeout
    };    
    var request = YAHOO.util.Connect.asyncRequest('GET', requestURL, fetchVideoURLcallback);
},

showVideoDescriptionCB : function(response){
	if (response.status==200){
		//document.forms[0].elements[""+VideoSharing.descriptionElement].value = response.responseText;	//IE7 BUG
		document.getElementById(""+VideoSharing.descriptionElement).value = response.responseText;
	}else{
		document.getElementById(VideoSharing.descriptionElement).value = unaviableProcessImageALT
	}
},

/*
*	Handle Zoom Klick Event
*/
handelZoomKlick : function(videoid){
  var video = this.allVideoLayersByDivID[videoid];
  if (typeof video != "undefined"){    
    video.handelZoomKlick();
  }
},

/*
*	Handle Display Klick Event
*/
handelDisplayKlick : function(videoid){
  var video = this.allVideoLayersByDivID[videoid];
  if (typeof video != "undefined"){    
    video.handelDisplayKlick();
  }
},

 /*
 *  Restores the origin inner HTML of video DIV
 */
restoreOriginDisplay : function(videoid){
  var video = this.allVideoLayersByDivID[videoid];
  if (typeof video != "undefined"){    
    video.restoreDisplay();
  }
},
 
//*****************************************************AJAX CALLS*****************************************
fetchVideoData : function (videoid, divLayerName, width, height, additonalElements, customStillImage, clickOnDisplay, showDetails, popUpTargetName, designData){    
    var requestURL = this.fetchVideoURL + "?method=" + this.fetchURLMethodName + "&videoid=" + videoid + "&timestamp=" + new Date().valueOf();    
    var video = this.allVideoLayersByDivID[videoid];
    if (typeof video == "undefined"){ 
      video = new VideoObject(videoid, divLayerName, width, height, additonalElements, customStillImage, clickOnDisplay, showDetails, popUpTargetName, designData);
      this.allVideoLayersByDivID[videoid] = video;
    }    
    
    var fetchVideoDescriptionCallback ={
      success:video.processVideoURL,
      failure:video.handleFailure,
      timeout: this.ajaxRequestTimeout
    };    
    var request = YAHOO.util.Connect.asyncRequest('GET', requestURL, fetchVideoDescriptionCallback);
 },

helper:null,
open_window: function( url, name, breite, hoehe, look ) {
		if( helper ) {
			helper.close();
		}
		helper = window.open(url, name, 'width='+breite+',height='+hoehe+','+look); 
	}
};//Namespace END


/**************************************************
* Tracking Functionality
***************************************************/ 
function callDisplay(videoid){
	VideoSharing.handelDisplayKlick(videoid);
}

function callPlay(videoid){
	try{
		captureVideo();	//index tools
	}catch (er){
		//ignore for user
	}
}

function callZoom(videoid){
	VideoSharing.handelZoomKlick(videoid);
}

function closeVideoZoom(videoid){

}

