// JavaScript Document

// JavaScript Document
videoMode='';
function loadVideoImg($videoID){
	var img = new Image();  
  // wrap our new image in jQuery, then:
  $(img)
    // once the image has loaded, execute this code
    .load(function () {
      // set the image hidden by default    
      $(this).hide();
    
// with the holding div #loader, apply:
      $('#videoHolder')
	     // then insert our image
		 //.empty()
        .append(this);
       // fade our image in to create a nice effect
      $(this).fadeIn();
    })
    // if there was an error loading the image, react accordingly
    .error(function () {
      // notify the user that the image could not be loaded
    })
    // *finally*, set the src attribute of the new image to our image
    .attr('src', 'images/videoThumbs/medium/'+$videoID+'.jpg');
	
}
function loadVideo($videoID,plaing){
	if (!isMobile()){
		//if 	(hasRequestedFlashVersion('9,0,115') ){
			$('#videoDetails').empty();
			// show flash content
			var flashvars = {};
			var params = {};
			var attributes = {};
			attributes.id = "flashplayer";
			attributes.name = "flashplayer";
			flashvars.filename = $videoID;
			flashvars.plaing = plaing;
			params.wmode = "transparent";
			params.allowFullScreen='true';
			$('#videoDetails').empty();
			$.get('?videoID='+$videoID+'&xml',function(data){
					$(data).find('video').each(function(){
							var $entry = $(this);
							var html = '';
							var $artist=$entry.find('artist');
							var $title=$entry.find('title');
							var $director=$entry.find('director');
							var $production_company=$entry.find('production_company');
							var $notes=$entry.find('notes');
							var $videofile=$entry.find('videofile');
							html += '<ul class="videoDetails">';
							html += '<li>';	
								if ($artist.text().length ){
									html += '<span class="videoName">';	
									html +=  $artist.text();
									html += '</span>';	
								}
								if ($title.text().length){
									html += ' <span class="videoArtist">';	
									if ($artist.text().length ){
										//html +=  ' : ';
									}
									html += $title.text()
									html += '</span>';
								}								
							html += '</li>';	
							
							if ($director.text().length){
								html += '<li><span class="videoProp">Director </span>'
										+' <span class="videoSpec">'+$director.text()+'</span></li>';
							}
							if ($production_company.text().length){
								html += '<li><span class="videoProp">Production co. </span>'
										+'<span class="videoSpec">'+$production_company.text()+'</span></li>';
							}
							if ($notes.text().length){
								html += '<li>'
										+'<span>'+$notes.text()+'</span></li>';
							}
							//alert($videofile.text())
							//$('#imageColumn')
								// emoty it
								//.empty()
								//.append('<div id="videoHolder"></div')
								//.append('<div id="videoDetails"></div');
							selectThumbs($videoID);
							if ($videofile.text()=='true'){
								if (videoMode==2 || videoMode==''){
									videoMode=1;
									swfobject.embedSWF("flash/player.swf", "videoHolder", "567", "360", "9.0.115","flash/expressInstall.swf", flashvars, params, attributes);
								}else{
									// send videoid to  videoPlayer	
									//alert('send variable');
									PlayFlashMovie($videoID)
								}
							}else{
								videoMode=2;
								$('#imageColumn')
									// emoty it
									.empty()
									.append('<div id="videoHolder"></div')
									.append('<div id="videoDetails"></div');
								loadVideoImg($videoID);
							}
							$('#videoDetails').append($(html));
					});
 			});
							
	}else{
		// load img and 
		//alert(getFlashVersion());
		if (plaing!='false'){
			window.location="video/"+$videoID+".m4v";
		}
	}
}
function hasRequestedFlashVersion(requestedVersion){
	var requestedVersionArray =requestedVersion.split(',');
	var version= getFlashVersion().split(',');
	if (Number(version[0]) > Number(requestedVersionArray[0])){
		return true
	}else if(Number(version[0]) == Number(requestedVersionArray[0])){
			if (Number(version[1]) > Number(requestedVersionArray[1])){
				return true
			}else if (Number(version[1]) == Number(requestedVersionArray[1])){
				if (Number(version[2]) >= Number(requestedVersionArray[2])){
					return true
				}else{
					return false;
				}
			}else{
				return false;
			}
	}else{
		return false;
	}
}
function getFlashVersion(){ 
  // ie 
  try { 
    try { 
      // avoid fp6 minor version lookup issues 
      // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
      try { axo.AllowScriptAccess = 'always'; } 
      catch(e) { return '6,0,0'; } 
    } catch(e) {} 
    return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
  // other browsers 
  } catch(e) { 
    try { 
      if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
        return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
      } 
    } catch(e) {} 
  } 
  return '0,0,0'; 
} 
function hasQuickTime(){ 
  // ie 
  try { 
    try { 
      // avoid fp6 minor version lookup issues 
      // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
      var axo = new ActiveXObject('QuickTime.QuickTime'); 
     } catch(e) {} 
    return true; 
  // other browsers 
  } catch(e) { 
    try { 
      if(navigator.mimeTypes["QuickTime.QuickTime"].enabledPlugin){ 
        return true
      } 
    } catch(e) {} 
  } 
  return false; 
} 
function isMobile() {
	var agents = new Array ('phone');
	var agent = navigator.userAgent.toLowerCase();
	for (i=0;i<agents.length;i++){
		if (agent.match(agents[i])){
			return true;
		};
	}
	return false
}
function selectThumbs($videoID){
	$('.thumbnails > li > a > img').removeClass('selected');
	$('li[id^='+$videoID+'] > a > img').addClass('selected');	
}
// F. Permadi May 2000
function getFlashMovieObject(movieName){
  if (window.document[movieName]){
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")== -1){
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }else if (navigator.appName.indexOf("Microsoft Internet") ==-1){
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }else // if (navigator.appName.indexOf("Microsoft Internet")!=-1){
    return document.getElementById(movieName);
  
}
function PlayFlashMovie(movie){
	var flashMovie=getFlashMovieObject('flashplayer');
	flashMovie.SetVariable("/:playVideoId",movie);	
	//embed.nativeProperty.anotherNativeMethod();
}























