﻿var gContent = null;
var getBaseURL = (window.location.hostname == 'www.alchemyfilms.net' ? 'http://www.alchemyfilms.net/' : 'http://adt1012svr/alchemyfilms/');

function ShowThumbVideos(Item, Code) {
	var VideoDest = document.getElementById('Thumbs_Videos');
	var Limit = 5;
	if(!VideoDest ) return;

	setOpacity(VideoDest,20);	
	var Elem1 = document.getElementById('clip_recent');
	var Elem2 = document.getElementById('clip_all');
	
	if(Item=='recent') {
		Elem1.className = 'active';
		Elem2.className = '';
	} else {
		Elem2.className = 'active';
		Elem1.className = '';
		Limit = 0
	}



  var req = new XMLHttpRequest();
  var URL = getBaseURL  + 'common/getThumbs.asp?CategoryCode=' +  Code + '&Limit=' + Limit ;		  
  try {
    req.open('GET', URL, true);
    req.onreadystatechange=function() {
      if(req.readyState==4) {
      	VideoDest.innerHTML = req.responseText;
      	setOpacity(VideoDest ,100);
      }
    }
    req.send(null);
	} catch(e) {
		window.alert(e.message);
	}
}


function setOpacity(Elem, Amount) {
	if(document.all) {
		Elem.filters.alpha.opacity = Amount;
	} else {
	  Elem.style.opacity = Amount/100;
	}
}

function EditArticle(href, Code) {
	var URL = '';
	if(gContent && gContent.cd) {
		URL = href + gContent.cd;		
	} else if(Code != '') {
		URL = href + Code;		
	}
	
	if(URL != '') window.open(URL, "_blank","width=800,height=600,scrollbars=yes");
	
}

function getVideo2(Content) {
	var PlayerRoot = getBaseURL;
	//if(location.href.search('/beta') > 0) PlayerRoot  = '/beta/';
	
	Params = 
  "skin=" + PlayerRoot + "f4player/skins/play_round_01.swf" + 
	"&thumbnail=" + escape(Content.pr) +
  "&video=" +  escape(Content.mv) 
	//alert(Params );
	
  Video = 
  "		<object width=\"480\" height=\"270\" id=\"f4Player\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\">" + '\n' + 
  "		<param name=\"movie\" value=\"" + PlayerRoot + "f4player/player.swf\" />" + '\n' + 
  "		<param name=\"quality\" value=\"high\" />" + '\n' + 
  "		<param name=\"menu\" value=\"false\" />" + '\n' + 
  "		<param name=\"allowFullScreen\" value=\"true\" />" + '\n' + 
  "		<param name=\"scale\" value=\"noscale\" />" + '\n' + 
  "		<param name=\"allowScriptAccess\" value=\"always\" />" + '\n' + 
  "		<param name=\"swLiveConnect\" value=\"true\" />" + '\n' + 
  "		<param name=\"flashVars\" value=\"" + Params  + "\"/>" + '\n' + 
  "   <param name=\"wmode\" value=\"transparent\">" + '\n' +   
  "		<!-- [if !IE] -->" + '\n' + 
  "		<object width=\"480\" height=\"270\" data=\"" + PlayerRoot + "f4player/player.swf\" type=\"application/x-shockwave-flash\" id=\"f4Player\">" + '\n' + 
  "		<param name=\"quality\" value=\"high\" />" + '\n' + 
  "		<param name=\"menu\" value=\"false\" />" + '\n' + 
  "		<param name=\"allowFullScreen\" value=\"true\" />" + '\n' + 
  "		<param name=\"scale\" value=\"noscale\" />" + '\n' + 
  "		<param name=\"allowScriptAccess\" value=\"always\" />" + '\n' + 
  "		<param name=\"swLiveConnect\" value=\"true\" />" + '\n' + 
  "		<param name=\"flashVars\" value=\"" + Params  + "\"/>" + '\n' + 
  "   <param name=\"wmode\" value=\"transparent\">" + '\n' +   
  "		</object>" + '\n' + 
  "		 <!-- [endif] -->" + '\n' + 
  "		</object>" + '\n';
  
  return Video;


}

function getVideoContent(Content) {
  var Content =  
  "<table style=\"margin:0px 0px 0px 40px;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"922\">" + '\n' + 
  "<tr>" + '\n' + 
  "  <td valign=\"top\">" + '\n' + 
  "  <div style=\"width: 480px; height: 270px; overflow: hidden\">" + '\n' + 
  getVideo2(Content) + 
  "  </div>" + '\n' + 
  "  </td>" + '\n' + 
  "  <td style=\"PADDING:32px 0px 0px 32px; width: 100%\" class=\"bodytext\" valign=\"top\" align=\"left\">" + '\n' + 
  getVideoDetails(Content) +
  "  </td>" + '\n' + 
  "</tr>" + '\n' + 
  "</table>" + '\n';
	return Content;
}

function getVideoDetails(Content) {
  if (Content.dr == '0') Content.dr = '';

  ReturnContent =
  "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\">" + '\n';

  if (Content.tl != '') ReturnContent +=
  "<tr>" + '\n' + 
  "  <td class=\"VideoHead\" colspan=\"2\">" + Content.tl +  "</td>" + '\n' + 
  "</tr>" + '\n';

  if (Content.cl != '') ReturnContent +=
  "<tr>" + '\n' +
  "  <td nowrap><b>Client:</b></td>" + '\n' +
  "  <td width=\"100%\">" + Content.cl + "</td>" + '\n' +
  "</tr>" + '\n';
    
  if(Content.dr != '') ReturnContent +=
  "<tr>" + '\n' + 
  "  <td><b>Director:</b></td>" + '\n' + 
  "  <td>" + Content.dr  + "</td>" + '\n' + 
  "</tr>" + '\n' ;
  
   if(Content.dp != '') ReturnContent +=
  "<tr>" + '\n' + 
  "  <td><b>DOP:</b></td>" + '\n' + 
  "  <td>" + Content.dp  + "</td>" + '\n' + 
  "</tr>" + '\n' ;
  
   if(Content.pp != '') ReturnContent +=
  "<tr>" + '\n' + 
  "  <td nowrap=\"\"><b>Post Production:</b></td>" + '\n' + 
  "  <td>" + Content.pp  + "</td>" + '\n' + 
  "</tr>" + '\n' ;
  
  if(Content.ln != '') ReturnContent +=
  "<tr>" + '\n' + 
  "  <td><b>Duration:</b></td>" + '\n' + 
  "  <td>" + Content.ln + "</td>" + '\n' + 
  "</tr>"  + '\n' ;
  
  if(Content.ln != '') ReturnContent +=
  "</table>" + '\n';
  
  return ReturnContent ;

}

function Share(Location, TheContent) {
	gContent  = TheContent;
	var URL = getBaseURL + 'films/video.asp?Video=' + gContent.cd;
	var Title = gContent.tl;
	var OpenURL = '';
	switch(Location){
	case 'facebook':
		OpenURL = 'http://www.facebook.com/sharer.php?u=' + encodeURIComponent(URL) + '&t=' + encodeURIComponent(Title);
		break;
	case 'twitter':
		OpenURL = 'https://twitter.com/share?url=' + encodeURIComponent(URL)
		break;
	}	
	//alert(OpenURL);
	window.open(OpenURL , "_blank", "width=600,height=300,resizable=yes,scrollbars=yes");
}


function PlayVideo() {
	ShowVideo(gContent);
}


function CancelTimer() {
  if (HideToolTipTimer) window.clearTimeout(HideToolTipTimer);
	HideToolTipTimer = null;

}

var gObject = null;
function ObjOnclick() {
	if(!gObject) return false;
	if(gObject.onclick) gObject.onclick();
}


function ShowGenArticle() {
	var oBj = document.getElementById('design_image_scroller');
	var MoreStyle = '';
	if(oBj) oBj.style.display = 'none';
	
	var Nav = document.getElementById('nav');
	if(Nav) Nav.style.display = 'none';
	
	var Elem = document.getElementById('design_body_content');
	if(!Elem) {
		Elem = document.getElementById('design_video_content');
		MoreStyle='width:920px;  margin:auto auto auto auto;  min-height:270px;';
	}
	
	if(Elem ) {
		Elem.style.display = 'block';
		Elem.style.visibility = 'visible';

    /*
      ImageContent = _
      "<div id=""ArticleContentImgScroll"" style=""float:right;"">" & vbCrLf & _
      "<div class=""ArticleContentImg"" style=""background-image:url('" & gArticleImagePath  & ImgLrg   & "');""></div>" & vbcrlf 
      "</div>" 
    */
		var Image = '';
		if (gContent.sl) {
		  Image =
      '<div id="ArticleContentImgScroll" style="float:right;">\n';
      var obj = gContent.sl.split(',');
      for(img in obj) {
        Image +=
        '<div class="ArticleContentImg" style="background-image:url(\'' + obj[img] + '\');"></div>\n';
      }
      Image += 
      "</div>" ;
		} else {
		  Image = '<img width="480" height=270" style="float:right" src="' + gContent.im + '">\n';
		}

		var HTML = 
  	'<div style="text-align:left; ' + MoreStyle + '" id="ArticleContent">' +
    '<div id="nav"></div>\n' +
    Image +
    '<div id="VerticalScroller" style="width:440px; height:270px; overflow:hidden;">' +
    '<div style="padding:0px 10px 10px 0px;">' +
    '<h1>' + gContent.ar  + '</h1>\n' ;
    if (gContent.sm) HTML +=
    '<div class="JobTitle">' + gContent.sm  + "</div>\n" ; 	  	 
    HTML +=	gContent.ct +					
    '</div>\n' +
    '</div>\n' +
    '<div style="clear:both; display:none;"></div>' +
    '</div>';
    
		Elem.innerHTML = HTML;
	  if(window.fleXenv) fleXenv.fleXcrollMain("VerticalScroller");
	  if (gContent.sl) {
	    if (Nav) Nav.style.display = 'block';
      LoadSlideShow();
	    
	  }
	}

	//Edit Article
	var EditLink = document.getElementById('LI_EditArticle');
	if(EditLink) EditLink.style.display ='block';


}


function ShowToolTip(TheContent, obj, e) {
  xPos = qBookXPos(obj);
  yPos = qBookYPos (obj);
  gContent  = TheContent;
  if (HideToolTipTimer) window.clearTimeout(HideToolTipTimer);
	HideToolTipTimer = null;	
	gObject  = obj;
	
	if(TheContent.ar) {
		HTML = "<div  class=\"tooltip_heading\" style=\"padding:10px 0px 0px 10px;\">" + TheContent.ar + "</div>";
		if(TheContent.sm) HTML +=
		"<div  class=\"tooltip_summary\" style=\"padding:0px 0px 0px 10px;\">" + TheContent.sm + "</div>";		
	} else {
    HTML = "<div style=\"padding:10px; white-space:nowrap; width:130px; overflow:hidden\">";
    if(TheContent.tl != '') HTML += TheContent.tl + "<br>";
		if(TheContent.cl != '') HTML += "Client: " + TheContent.cl + "<br>";
		if(TheContent.pj != '') HTML += "Project: " + TheContent.pj + "<br>";
		if(TheContent.ln != '') HTML += "Duration: " + TheContent.ln + '<br>' ;
		HTML += "<a class=\"PlayVideo\" href=\"#\" onclick=\"PlayVideo();\">&nbsp;</a>";
	}
  //alert('xPos: ' + xPos  + ', yPos :' + yPos );
  var ToolTip = document.getElementById('tooltip_content');
  ToolTip.innerHTML = HTML ;
  var Elem = document.getElementById('tooltip');
	//var H = Elem.clientHeight - 4;
	var H = document.body.clientTop;
	
	
  Elem.style.top = (yPos - H) + 'px';
  Elem.style.left = xPos + 'px';
  Elem.style.visibility='visible';
  Elem.style.width = obj.clientWidth + 'px';  
  
  ToolTip.style.top = (yPos - H) + 'px';
  ToolTip.style.left = xPos + 'px';
  ToolTip.style.visibility='visible';
  ToolTip.style.width = obj.clientWidth + 'px';
  
}

var HideToolTipTimer = null;

function HideToolTip() {
	if (HideToolTipTimer) window.clearTimeout(HideToolTipTimer);
	HideToolTipTimer = window.setTimeout('fnHideToolTip()',100);
}
function fnHideToolTip() {	
	var Elem = document.getElementById('tooltip');
	Elem.style.visibility='hidden';	
  var ToolTip = document.getElementById('tooltip_content');
	ToolTip.style.visibility='hidden';	
}

function ShowVideo(TheContent) {
	var Elem = document.getElementById('design_video_content');
	var Body = document.getElementById('design_image_scroller');
	var Nav = document.getElementById('nav');
	
	Body.style.backgroundImage = 'none';
	Body.style.display='none';
	Elem.style.visibility='visible';
	Elem.style.display='block';
	Content = getVideoContent(TheContent);	
	Elem.innerHTML = Content ;
	if(Nav) Nav.style.display = 'none';
	
	//Edit Article
	var EditLink = document.getElementById('LI_EditArticle');
	if(EditLink) EditLink.style.display ='block';
	document.body.scrollTop = 0;
}

function qBookXPos(el) {
  //el.style.position = 'relative';
  var ol = el.offsetLeft;
  //el.style.position = '';
  //return ol;

  if(el.style.position == 'relative') {
    alert(el.id);
    return ol;
  }
  while ((el = el.offsetParent) != null) {
  	ol += el.offsetLeft;
  	var sL = el.scrollLeft;
  	if(sL) ol-=sL;
	}
  return ol;
}

function qBookYPos (el) {
  var ot = el.offsetTop;
  if(el.style.position == 'relative')return ot;
  while((el = el.offsetParent) != null) {
    ot += el.offsetTop;
  }
  return ot;
}


