var thumbwidth = 100;
var thumbheight = 80;
var thumbwidthpreview = 100;
var thumbheightpreview = 80;
var thumbwidthnopreview = 50;
var thumbheightnopreview = 40;
var accordeonFilled = false;

//var displayManifestation = 1;
//var displayfield = "idx_main";

var displayManifestation = 1;
var displayfield = "idx_main";

/*
    target == -1 : all
    target == 0 - x : item 0 - x
    target == "" : 0
*/
function checkJson(json, where) {

    stringtest = json + "";

	if(stringtest.substring(0,5) == '<html') {
	
	    errorMessage(where, "An error was encountered. Please try again later.");
	    return "";
        
	} else if(json["object-array"].length < 2 || json["object-array"][1].length == 0) {
	
	    if(resultType == 'UserDetail') {
	        errorMessage(where, "There are no works in the GAMA database for this person.");
	    } else {                
	        errorMessage(where, "No Results found.");
	    }
	    return "";
	    
    } else {
        return stringtest
    }

}

function obligated(str) {
	// adds plusses in front of words to make them obligatory
	
	var newstr = "%2B" + escape(str);

	var fttag = /%20/g;
	newstr= newstr.replace(fttag, "%20%2B");

	return newstr;
}

function obligatedQS(str) {
	// adds plusses in front of words to make them obligatory
	
	var newstr = "%2B" + str;

	var fttag = /\+/g;
	newstr= newstr.replace(fttag, "%20%2B");

	return newstr;
}


function addPlusses(str) {
    // adds plusses in front of words to make them obligatory
    
    var newstr = "+" + str;

    var fttag = / /g;
    var newstr= newstr.replace(fttag, " +");

    return newstr;
}

function limitStr(str, limit) {

        if(str.length > limit) {
            return str.substring(0,limit) + "...";
        } else {
            return str
        }
}

function getValueFromShow(results, target, limit) {

     if(target == "") {
        target = 0;
    }
    
    if(results.length == 0) {
        return ""
    } else if((target == -1) && (results.length == 1)) {
    
        return limitStr(results[0], limit)

    }
    else if( (target == -1) && (results.length > 1) ) {

		var comma = "";
        var returnvalue = "";
        
        for (var i=0; (i < (results.length -1)); i++) {
            returnvalue +=  comma + limitStr(results[i], limit);
            comma = ", ";
        }

        returnvalue +=  " and " + limitStr(results[i], limit);

        return returnvalue;
        
    } else if(results.length > target && results.length > 0) {
        return limitStr(results[target], limit);
    } else {
        return "";
    }
}

function getValueFromPerson(json, where, property, index) {

    var returnvalue = new Array();
    
    var work = json.properties;

    for (var i=0; (i < work.length); i++) {
    
        if(work[i][0] == property) {
            returnvalue = returnvalue.concat(work[i][1].values);
        }
    }

    return returnvalue;
}

// returns an array of results
function getValueFrom(json, where, property, index) {

    var returnvalue = new Array();
    
    if(where == "work") {
    
        var work = json.properties;
        for (var i=0; (i < work.length); i++) {
        
            if(work[i][0] == property) {
                returnvalue = returnvalue.concat(work[i][1].values);
            }
        }
    } else {

        var items = json[where];

        if(typeof items != "undefined") {
	        for( var j=0; (j < items.length); j++) {

	            if(index == -1 || index == j) {
	                var item = json[where][j].properties;
	                        
	                for (var i=0; (i < item.length); i++) {
	                
	                    if(item[i][0] == property) {
	                        returnvalue = returnvalue.concat(item[i][1].values);
	                    }
	                }
	            }
	        }
        }   
    }
    return returnvalue;
}

function unescapeHtml(text) {

	var newtext = text.replace(/&lt;br&gt;/g, "<br \\>")
	newtext = newtext.replace(/&lt;br\/&gt;/g, "<br \\>")
	newtext = newtext.replace(/&lt;br \/&gt;/g, "<br \\>")
	newtext = newtext.replace(/\u000a/g, "<br \\>")

	newtext = newtext.replace(/&lt;p&gt;/g, "<p>")
	newtext = newtext.replace(/&lt;\/p&gt;/g, "</p>")

	newtext = newtext.replace(/&lt;b&gt;/g, "<b>")
	newtext = newtext.replace(/&lt;\/b&gt;/g, "</b>")

	newtext = newtext.replace(/&lt;em&gt;/g, "<em>")
	newtext = newtext.replace(/&lt;\/em&gt;/g, "</em>")

	newtext = newtext.replace(/&lt;strong&gt;/g, "<strong>")
	newtext = newtext.replace(/&lt;\/strong&gt;/g, "</strong>")

	newtext = newtext.replace(/&lt;sup&gt;/g, "<sup>")
	newtext = newtext.replace(/&lt;\/sup&gt;/g, "</sup>")

	newtext = newtext.replace(/&lt;sub&gt;/g, "<sub>")
	newtext = newtext.replace(/&lt;\/sub&gt;/g, "</sub>")

	return newtext;
}

// extra can: limit for textlimted, showarray for the rest
function sanitize(type, result, target, extra) {

    if(type == "text") {
        return unescapeHtml(sanitizeText(result, target, extra))
        
    } else if(type =="textlimited") {
        return unescapeHtml(sanitizeTextLimited(result, target, extra))
        
    } else if(type =="number") {
        return sanitizeNumber(result, target, extra)

    } else if(type =="image") {
        return sanitizeImage(result, target, extra)

    } else if(type =="url") {
        return sanitizeUrl(result, target, extra)

    } else if(type =="date") {
        return sanitizeDate(result, target, extra)

    } else if(type =="duration") {
        return sanitizeDuration(result, target, extra)

    } else if(type =="archive") {
        return sanitizeArchive(result, target, extra)
        
    } else if(type =="artistslimited") {
        return sanitizeArtistsLimited(result, target, extra)
        
    } else if(type =="type") {
        return sanitizeType(result, target, extra)

    }
}

function sanitizeText(result, target, extra) {

    var src = "";
    if(result == ""){

    } else {
    
       src = (getValueFromShow(result, target));
    }
        
    return src;
}

function sanitizeNumber(result, target, extra) {

    var src = -1;
    if(result == ""){

    } else {
    
       src = (getValueFromShow(result, 0));
       src = toInt(src);
    }
        
    return src;
}

function sanitizeArtistsLimited(result, target, extra) {
    
   // clear everything beyond the third artist.
   var newresult = new Array();
   skipped = false;
   
   for (var i=0; (i < result.length); i++) {
      var name = result[i];
      if (name == "") {
         name = "[Unknown]"
      }
      
      if(false && name.split(" ").length > 4) {
        // skip for now,
      } else {
          if(newresult.length < 3 ) {
            newresult[newresult.length] = name;
          } else {
            skipped = true; 
          }
      }
   }
   
   if(skipped) newresult[newresult.length] = "more";
        
   return sanitizeTextLimited(newresult, target, extra);
}


function sanitizeDate(result, target, extra) {

    var src = "";
    if(result == ""){

    } else {
    
       src = getValueFromShow(result, target).substring(0,4);
    }
    
    return src;
}

function sanitizeDuration(result, target, extra) {

    var src = "";
    if(result == ""){

    } else {
    
       duration = toInt(getValueFromShow(result, target));

       seconds = duration % 60
       minutes = Math.floor((duration % 3600) / 60)
       hour = Math.floor(duration / 3600)
       
       if (hour > 0 ) {
         if (hour > 1) {
           src += hour + " hours ";
         } else {
           src += hour + " hour ";
         }
       }
       
       if (minutes > 0 || src != "") {
         if (minutes > 1) {
           src += minutes + " minutes ";
         } else {
           src += minutes + " minute ";
         }
       }

       if (seconds > 0 || src != "") {
         if (seconds > 1) {
           src += seconds + " seconds";
         } else {
           src += seconds + " second";
         }
       }
       
    }
    
    return src;
}

gama_archives = [
    {
      "id": "c3",
      "name": "C3",
      "tag" : "gama:c3:main:Archive:C3",
      "testtag" : "c3",
      "simplename": "C3",
      "homepageURL": "http://www.c3.hu/",
      "logoURL": "logourl"
    },
    {
      "id": "fi",
      "name": "Filmform",
      "tag" : "gama:filmform:main:Archive:Filmform",
      "testtag" : "filmform",
      "simplename": "Filmform",
      "homepageURL": "http://www.filmform.com/",
      "logoURL": "logourl"
    },
    {
      "id": "di",
      "name": "DIVA",
      "tag" : "gama:diva:main:Archive:DIVA",
      "testtag" : "diva",
      "simplename": "diva",
      "homepageURL": "http://www.scca-ljubljana.si/indexengl.htm",
      "logoURL": "logourl"
    },
    {
      "id": "he",
      "name": "Heure Exquise!",
      "tag" : "gama:heure-exquise:main:Archive:HeureExquise",
      "testtag" : "heure_exquise",
      "simplename": "heure-exquise",
      "homepageURL": "http://www.heure-exquise.org/",
      "logoURL": "logourl"
    },
    {
      "id": "in",
      "name": "Les Instants Vid&#233;o",
      "tag" : "gama:instants:main:Archive:Instants",
      "testtag" : "les_instants",
      "simplename": "instants",
      "homepageURL": "http://www.instantsvideo.com/",
      "logoURL": "logourl"
    },
    {
      "id": "mo",
      "name": "NIMk",
      "tag" : "gama:montevideo:main:Archive:NIMk",
      "testtag" : "NIMK",
      "simplename": "monte",
      "homepageURL": "http://www.nimk.nl/en/",
      "logoURL": "logourl"
    },
    {
      "id": "ar",
      "name": "Argos",
      "tag" : "gama:argos:main:Archive:Argos",
      "testtag" : "argos",
      "simplename": "argos",
      "homepageURL": "http://www.argosarts.org/",
      "logoURL": "logourl"
    },
    {
        "id": "ae",
        "name": "Ars Electronica",
        "tag" : "gama:ars-electronica:main:Archive:ArsElectronica",
        "testtag" : "ars_electronica",
        "simplename": "ars_electronica",
        "homepageURL": "http://www.aec.at/",
        "logoURL": "logourl"
      }

  ];


function getFacetArchive(tag) {
    var archivename = "";
    
    for (var j=0; (j < gama_archives.length); j++) {
        if(gama_archives[j].testtag == tag) {
            archivename = gama_archives[j].name;
        }
    }
    
    return archivename
}

function sanitizeArchive(result, target, extra) {

    var src = "";
    if(result == ""){

    } else {
    
       var tag = getValueFromShow(result, target);

       for (var j=0; (j < gama_archives.length); j++) {
            if(gama_archives[j].tag == tag) {
	        	if(gama_archives[j].homepageURL == "") {
		            src = gama_archives[j].name;
	        	} else {
		            src = '<a class="archive" href="' + gama_archives[j].homepageURL + '">' + gama_archives[j].name + "</a>";
		        }
            }
       }
    }
    
    return src;
}

function sanitizeTextLimited(result, target, limit) {

    var src = "";
    
    if(result == ""){

    } else {
        src = getValueFromShow(result, target, limit);
    }
    
    return src;
}

function addSpace(str) {
	re=/(.+)([A-Z])/;

	var check=str.replace(re,"$1 $2");

	return check;
}

function removeSpace(str) {

	var check=str.replace(" ","");

	return check;
}


function sanitizeType(result, target, extra) {
    
   // clear everything beyond the third type.
   var newresult = new Array();
   var count = 0;
   var eventstr = "";

   if(result.length == 1) {

	   slashPos = result[0].lastIndexOf("/")
	   if(slashPos > 0 ) {
	       newresult[newresult.length] = addSpace(result[0].substr((slashPos +1)));
	   } else {
	       newresult[newresult.length] = addSpace(result[0]);
	   }

   } else {

		for (var i=0; (i < result.length); i++) {

			if(count < 4 ) {

				slashPos = result[i].lastIndexOf("/")
				if(slashPos > 0 ) {
					eventstr = result[i].substr((slashPos +1));
				} else {
					eventstr = result[i]
				}

				if(eventstr == "Event" ||
					eventstr == "Artwork" ||
					eventstr == "Resource" ) {
					// skip		   		
				} else {
					newresult[newresult.length] = addSpace(eventstr);
					count++;
				}
			}
		}
   }
   
   if(count > 3) newresult[newresult.length] = "more";
        
   return sanitizeTextLimited(newresult, target, extra);
}

function sanitizeUL(result, alwaysul) {
    
    if(result.length == 0) {
        return ""
    } else if(result.length == 1 && !alwaysul) {
        return result[0];    
    } else {
    
        var src = "<ul>";
        
        for (var i=0; (i < result.length); i++) {
            src += "<li>" + result[i] + "</li>" 
        }
        src += "</ul>";
        
        return src
    }
}

function hasManifestation(work) {
    return (getManifestation(work) == -1)
}

function getManifestionId(work) {
    var manifestid = -1;
    
    var manifestations = work.manifestations;

    if(typeof manifestations != "undefined") {

	    for (var i=0; (i < manifestations.length); i++) {
	    
	        var display = sanitize("text", getValueFrom(work, "manifestations", displayfield, i), 0)
	
	        if(display == displayManifestation) {
	            manifestid = manifestations[i].id;
	        }
	    }
	}
    return manifestid

}

/*
    {
      "name": "totalcount",
      "value": 21
    },
      "name": "workcount",
      "name": "pagecount",
      "name": "pagesize",
      "name": "pagenumber",
      "name": "urlparams",
*/

function getConstantData(data, name) {

    value = -1;
    
    for (var i=0; (i < data.length); i++) {
        if(data[i].name == name) {
          value = data[i].value
        }
    }
    
    return value;
}

function getPageSize(data) {
    return getConstantData(data[0], "pagesize"); 
}

function getPageNumber(data) {
    return getConstantData(data[0], "pagenumber"); 
}

function getPageCount(data) {
    return getConstantData(data[0], "pagecount"); 
}

function getTotalCount(data) {
    return getConstantData(data[0], "totalcount"); 
}

// only when looking for users
function getWorkCount(data) {
    return getConstantData(data[0], "workcount"); 
}

function getTotalPages(data) {
    var nrpages = Math.ceil( (getTotalCount(data) / getPageSize(data)));

    return nrpages; 
}

function getSortTag() {
   return $("form#searchform" + resultType + " input#sorttag").val()
}

function getSortDirection() {
   return $("form#searchform" + resultType + " input#sortdirection").val()
}

function getWorkId(work) {
    return work.id
}

function getUserId(user) {
    return user.id
}


function getPreviewUrl(work) {
    var manifestations = work.manifestations;
    var manifestation = -1;

    if(typeof manifestations != "undefined") {
	    for (var i=0; (i < manifestations.length); i++) {
	    
//	        var display = sanitize("text", getValueFrom(work, "manifestations", "idx_main", i), 0)
	
//	        if(display == 1) {
		        var stream_avail = sanitize("text", getValueFrom(work, "manifestations", "idx_stream_avail", i), 0)
		        
		        if(stream_avail == 1 || stream_avail == 2) {
		            manifestation = manifestations[i].id;
		    	}
//	        }
	    }
    }
    
    if (manifestation == -1) {
        return ""
    } else {
    	if( stream_avail == 2) {
        	return iconurl + manifestation + "/full.mp4"
    	} else {
        	return iconurl + manifestation + "/preview.mp4"
        }
    }
}

function getShot(work, nr, iconlarge) {

    var manifestations = work.manifestations;
    var manifestation = "";
    if(typeof manifestations != "undefined") {
	    for (var i=0; (i < manifestations.length); i++) {
	    
	        var display = sanitize("text", getValueFrom(work, "manifestations", displayfield, i), 0)
	
	        if(display == displayManifestation) {
	            manifestation = manifestations[i].id;
	
	        }
	    }
	}

    if(manifestation == "") {
        return "";
    } else {
        return iconurl + manifestation + "/" + nr + "." + iconlarge + ".jpg";
    }
}

function getThumbnail(result, thumb, iconlarge) {

    var shotnr = sanitize("number", getValueFrom(result, "work", "bestmatch", 0),0);

    // the default
    if(shotnr == -1 ) shotnr = 0;

    var thumbnail = sanitize("text", getValueFrom(result, "work", thumb))
    
    if(thumbnail == "") {
        return getShot(result, shotnr, iconlarge);
    } else {
        return thumbnail;
    }
}
function sanitizePopup(result, work, image, url, i, title, width, height) {

    var src = '';
    if(image == ""){

    } else {

       var thumb_large =  getThumbnail(result, image, "large");
    
        if(url == "") {
            src='<a href="#" class="popuplink" rel="' + work + '" '
                + ' title="' + title + '"><img src="/fileadmin/templates/img/play_big.png" style="background-image: url(' + thumb_large + ');" title="' + title + '" width="' 
                + width + '" height="' + height + '" \></a>';
    
        } else {
    
            src='<a href="' + url + '" class="popuplink" rel="' + work + 
                '" title="' + title + '"><img src="/fileadmin/templates/img/play_big.png" style="background-image: url(' + thumb_large + ');" title="' + title + '" width="'
                + width + '" height="' + height + '" \></a>';
        }
    }
    
    return (src);
}

function sanitizeThumbnail(result, work, thumb, image, url, i, title) {

    var src = '';
    if(thumb == ""){

    } else {
    
       var thumb_small = getThumbnail(result, thumb, "icon");
       var thumb_large = getThumbnail(result, thumb, "large");
    
        if(thumb_small == "" ) {
            src = "";
        } else {
	        if(url == "") {
	            src='<a href="#" class="popuplink" rel="' + work + '" '
	                + ' title="' + title + '"><img src="/fileadmin/templates/img/play_small.png" style="background-image: url(' + thumb_small + ');" title="' + title + '" width="' 
	                + thumbwidth + '" height="' + thumbheight + '" \></a>';
	    
	        } else {
	    
	            src='<a href="' + url + '" class="popuplink" rel="' + work + 
	                '" title="' + title + '"><img src="/fileadmin/templates/img/play_small.png" style="background-image: url(' + thumb_small + ');" title="' + title + '" width="'
	                + thumbwidth + '" height="' + thumbheight + '" \></a>';
	        }
	    }
    }
    
    return (src);
}

function sanitizeShot(result, i, title) {
    var thumb_small = getShot(result, i, "icon");
    var thumb_large = getShot(result, i, "large");
    
/*    var src='<a href="#" class="popuplink" rel="' + thumb_large + '" '
           + ' title="' + title + '"><img src="' + thumb_small + '" title="' + title + '" width="' 
           + thumbwidthpreview + '" height="' + thumbheightpreview + '" \></a>';
*/


	var src='';
	if(thumb_small == "" ) {
		src='<img src="/fileadmin/templates/img/trans.png" title="" width="' 
	           + thumbwidthpreview + '" height="' + thumbheightpreview + '" \>';
	} else {
		src='<img src="' + thumb_small + '" title="' + title + '" width="' 
	           + thumbwidthpreview + '" height="' + thumbheightpreview + '" \>';
    }

    return (src);
}

function errorMessage(frame, msg) {
    $(frame).empty().append('<p class="error">' + msg + '</p>');
}

function createPopups(domain) {
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
	// something different for iPhone/iPods can be done here....
} else {
    $(domain + " a.popuplink").click(function(elem){
//    $(".popuplink").click(function(elem){
        destroyPopup(this);
        createMoviePopup(elem, this);
        return false;
    });
}
}

var openPopup = null;

function createPopup(elem, url){

    if(openPopup == url) {
    
        openPopup = null;
        
    } else {
   
        openPopup = url;
        
        var caption = (url.title == "") ? "" : "<br/>" + url.title;
        var alttext = (url.title == "") ? "image preview" : "<br/>" + url.title;
        
        $("body").append('<div id="popupimg"><div id="handle"><a href="javascript:closePopup()" class="close">close</a>' + url.title + '</div>')
        
        if(url.href.indexOf("#") == -1) {


        $("#popupimg").append('<a href="javascript:openMovie(\'' + url.href + '\',\'' + url.title.replace("\'","\\\'") + 
                              '\')"><img src="'+ url.rel +'" alt="' + alttext + '" /></a>');
        } else {
        $("#popupimg").append('<img src="'+ url.rel +'" alt="' + alttext + '" />');
        
        }
        
        if(url.href.indexOf("#") == -1) {
            $("#popupimg").append("<p>Click image to play (generated) preview<a href='Javascript:switchToInfo(\"" + url.uri + "\")' class='moreinfo'>More info<a/></p>")
        }
        
        $("#popupimg").append('</div>');

// $('#popupimg').height()/2
// $('#popupimg').width()/2 
// assumes a set width and height for a shot 400px × 320px
        top = $(window).height()/2 - 200 + $(window).scrollTop();
        left = $(window).width()/2 - 160 + $(window).scrollLeft();
            
        showBlackscreen()
        
        $("#popupimg")
            .css("position", "absolute")
            .css("display", "none")
            .css("top",top)
            .css("left",left)
            .css("z-index","10")
            .fadeIn("fast");
            
       $("#popupimg").draggable({handle: "#handle"});
    }
}


function createMoviePopup(elem, url){

    if(openPopup == url) {
    
        openPopup = null;
        
    } else {
   
        openPopup = url;
        
        var caption = (url.title == "") ? "" : url.title;
        
        $("body").append('<div id="popupimg"><div id="handle"><a href="javascript:closePopup()" class="close">close</a>' + url.title + '</div>')

		openMovie(url.href, caption, url.rel)
		
// $('#popupimg').height()/2
// $('#popupimg').width()/2 
// assumes a set width and height for a shot 400px × 320px
        var top = $(window).height()/2 - 200 + $(window).scrollTop();
        var left = $(window).width()/2 - 160 + $(window).scrollLeft();
            
        showBlackscreen()
        
        $("#popupimg")
            .css("position", "absolute")
            .css("display", "none")
            .css("top",top)
            .css("left",left)
            .css("z-index","10")
            .fadeIn("fast");
            
       $("#popupimg").draggable({handle: "#handle"});
    }
}

function switchToInfo(myUri)
{
	closePopup();
	clickResult(null,myUri);
}

function openMovie(movie, caption, workuri) {
/*
        embedUrl = '<embed width="400" height="290"' + 
        'flashvars="config={"autoPlay":false,"controlBarBackgroundColor":"0x2e8860","initialScale":"scale","videoFile":"' +  
         movie + '"}" pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash"' + 
         ' bgcolor="#ffffff" quality="high" allowscriptaccess="always" allowfullscreen="true" src="FlowPlayerDark.swf"/>';
*/        
        $("#popupimg").empty();

		var moreinfourl = "";
		if(homepage) {
			moreinfourl = cmsbaseurl + "index.php?id=search&workdetail=" + workuri
		} else {
			moreinfourl = "javascript:switchToInfo('" + workuri + "')"
		}
		
        src = '<div id="handle"><a href="javascript:closePopup()" class="close">close</a>' + caption + '</div>'
                         + '<div style="width:400px;height:320px;" id="video"></div><a href="' + moreinfourl + '" class="moreinfo">More info<a/>';
        $("#popupimg").append(src);
        
    	flashembed("video", 
    			{
    			   "src": 'fileadmin/swf/flowplayer-3.0.3.swf',
    	    	   "version": [10, 0],  
   	    		   "expressInstall": "fileadmin/swf/expressinstall.swf",
   	    		   "onFail": function() {
        			  $("#popupimg").append("<br \>You have flash version " + this.getVersion() + ". You need 10.");
    			   }
    			},
    			{"config": {  
				  clip: {
				    url: movie,
				    provider: 'h264streaming'
				  },
				  plugins: {
				    h264streaming: {
				      url: 'fileadmin/swf/flowplayer.h264streaming-3.0.5.swf'
				    },
				    controls: {  
				      url: 'fileadmin/swf/flowplayer.controls-3.0.3.swf',  
				 
				      // which buttons are visible and which not ?  
				      play:true,       
				      fullscreen:true,
				 
				     // scrubber is a well known nickname to the timeline/playhead combination  
				      scrubber: true          
				    }
    			}}
    			});
}

function accOpenMovie(movie, caption) {
	
    src = '<div style="width:400px;height:320px;" id="accvideo"></div>' + caption;
	$("#acc_movie").append(src);

        flashembed("accvideo", 
                {
                   "src": 'fileadmin/swf/flowplayer-3.0.3.swf',
                   "version": [10, 0],  
                   "expressInstall": "fileadmin/swf/expressinstall.swf",
                   "onFail": function() {
                      $("#popupimg").append("<br \>You have flash version " + this.getVersion() + ". You need 10.");
                   }
                },
    			{"config": {  
				  clip: {
				    url: movie,
				    provider: 'h264streaming'
				  },
				  plugins: {
				    h264streaming: {
				      url: 'fileadmin/swf/flowplayer.h264streaming-3.0.5.swf'
				    },
				    controls: {  
				      url: 'fileadmin/swf/flowplayer.controls-3.0.3.swf',  
				 
				      // which buttons are visible and which not ?  
				      play:true,       
				      fullscreen:true,
				 
				     // scrubber is a well known nickname to the timeline/playhead combination  
				      scrubber: true          
				    }
    			}}
    			});
	
}

function closePopup() {
    openPopup = null;
    destroyPopup();
}

function destroyPopup() {
    $("#popupimg").remove();
    hideBlackscreen()
}


function ajaxError(XMLHttpRequest, textStatus, errorThrown) {
  // typically only one of textStatus or errorThrown 
  // will have info
 // this; // the options for this ajax request
  
  errorMessage(ErrorFrame, "<p>An error was encountered (" + textStatus + "). Please try again later.</p>");
  endLoader();
}

function startLoader(text) {

var div = jQuery('<div id="loader"><p><img src="' + imgroot + 'waiting.gif" /></p><p>' + text + '</p></div>');

div.appendTo(document.body)

        var top = $(window).height()/2 - $("#loader").height() + $(window).scrollTop();
        var left = $(window).width()/2 - $("#loader").width() + $(window).scrollLeft();
            
        $("#loader")
            .css("position", "absolute")
            .css("display", "none")
            .css("top",top)
            .css("left",left)
            .css("z-index","10")
            .fadeIn("fast");

}

function endLoader() {
    $("#loader").remove();
}

// Accordeon
function initialiseAccordeon() {
}

function closeAccordeon() {
    $(".accordeon").slideUp("slow");
    $(".acc_select").addClass('acc_noselect').removeClass('acc_select');
}

function openAccordeon(number) {
    old_display = $(".accordeon:eq(" + number + ")").css("display");
    
    if(old_display == "none") {
	    closeAccordeon()
	    
	    if(number < $(".accordeon").length && 
	       number >= 0 ) {
	       
	        $(".accordeon:eq(" + number + ")").slideDown("normal")
	        $(".acc_noselect:eq(" + number + ")").addClass('acc_select').removeClass('acc_noselect');
	    }
	}
}

function toggleAccordeon(number) {
    
    if(accordeonFilled) {
	    old_display = $(".accordeon:eq(" + number + ")").css("display");
	    closeAccordeon()
	    
	    if(number < $(".accordeon").length && 
	       number >= 0 &&
	       old_display == "none") {
	       
	        $(".accordeon:eq(" + number + ")").slideDown("normal")
	        $(".acc_noselect:eq(" + number + ")").addClass('acc_select').removeClass('acc_noselect');
	    }
	 }
}

function showBlackscreen() {

	$("#blackscreen")
	    .css("position", "absolute")
	    .css("top", 0)
	    .css("left",0)
	    .css("width",$(document).width())
	    .css("height",$(document).height())
	    .css("display", "inline")
}

function hideBlackscreen() {
    $("#blackscreen")
        .css("position", "absolute")
        .css("top", 0)
        .css("left",0)
        .css("width",0)
        .css("height",0)
        .css("display", "none")
}

function getAccessibility() {
    var color = queryString("color");
    var size = queryString("size");
    
    return "&color=" + color + "&size=" + size;
}

function toInt(x)
{
    return (parseInt(x) + 0);
}

function queryString(ji) {

    var qsvalue = "";
    hu = window.location.search.substring(1);
   
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) {
    
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            if  (ft.length > 1) return ft[1];
        }
    }
    
    return qsvalue
}

function getQsValue(hu, ji) {

    gy = hu.split("&");
    for (i=0;i<gy.length;i++) {
    
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            if  (ft.length > 1) return ft[1];
        }
    }
}