/* Header functions*/
// Tog More for Search
// Tog More for Search
function togMore(sShow)
{
  if (sShow == "hide")
  {
    document.getElementById("srchMoreId").style.display = "none";
  }
  else
  {
    document.getElementById("srchMoreId").style.display = "block";
  }
  return false;
}
        
function togFootMore(sShow)
{
  if (sShow == "hide")
  {
    document.getElementById("srchFootMoreId").style.display = "none";
  }
  else
  {
    document.getElementById("srchFootMoreId").style.display = "block";
  }
  return false;
}
                
// Begin : Headers 2 code
function p_o(o){return getEl(o);}
                
String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g,"");
}
                
function srchSub(ref){
  var frm=p_o("search");
  var queryval = frm.topquery.value.trim();
  queryval = queryval.replace( /\+/, " ");
  newurl = ref.href + queryval;
  window.location = newurl;
  return false;
}
                
function searchTarget(url, newWindow, newTarget) {
  // Set the target for the form
  document.bb_topform.action = url;
  if (newWindow) {
    document.bb_topform.target = '_blank';
  } else {
    document.bb_topform.target = '';
  }
  // Update the tabs classes to allow highlighting of the selected
  var arrElements = ["search-tab-Stylelist","search-tab-Web","search-tab-Blog","search-tab-Video","search-tab-News","search-tab-Images","search-tab-Local"];
  for (var i=0; i<arrElements.length; i++) {
    getEl(arrElements[i]).className = '';
  }
  getEl(newTarget).className = 'searchCatBg';
                
                
  return false;
}
            
function searchTarget2(url, newWindow, newTarget) {
  // Set the target for the form
                
  document.bb_bottomform.action = url;
  if (newWindow) {
    document.bb_bottomform.target = '_blank';
  } else {
    document.bb_bottomform.target = '';
  }
  // Update the tabs classes to allow highlighting of the selected
  var arrElements = ["search-tab-Stylelist2","search-tab-Web2","search-tab-Blog2","search-tab-Video2","search-tab-News2","search-tab-Images2","search-tab-Local2"];
  for (var i=0; i<arrElements.length; i++) {
    getEl(arrElements[i]).className = '';
  }
  getEl(newTarget).className = 'searchCatBg';
            
            
  return false;
}
        
function eventIsEnterKey(event) {
  if (event && event.which == 13 || window.event && window.event.keyCode == 13 || event && event.which == 3 || window.event && window.event.keyCode == 3) {
    return true;
  }
  return false;
}
        
function submitHeaderSearch(event) {
  if (event == "onclick" || eventIsEnterKey(event)) {
    return srchSub2();
  } else {
    return true;
  }
}
    
function srchSub2() {
  var frm=p_o("search");
  var queryval = frm.topquery.value.trim();
  queryval = queryval.replace( /\+/, " ");
  var newurl = frm.action + URLEncode(queryval);
  if (frm.target == '_blank') {
    window.open(newurl, '_blank', '');
  } else {
    window.location = newurl;
  }
  return false;
}

function submitFooterSearch(event) {
  if (event == "onclick" || eventIsEnterKey(event)) {
    return srchSub4();
  } else {
    return true;
  }
}

function srchSub4() {
  var frm=p_o("search2");
  var queryval = frm.Bottomquery.value.trim();
  queryval = queryval.replace( /\+/, " ");
  var newurl = frm.action + URLEncode(queryval);
  if (frm.target == '_blank') {
    window.open(newurl, '_blank', '');
  } else {
    window.location = newurl;
  }
  return false;
}


//Prevent IE flickr
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function hideHeaderMore(e) {
  var targ;
  if (!e) var e = window.event;
  if (e.target) targ = e.target;
  else if (e.srcElement) targ = e.srcElement;
    
  if (targ.nodeType == 3) // defeat Safari bug
    targ = targ.parentNode;
  if(targ.id != 'srchMoreAnc' && targ.id != 'srchMoreAnc2') {
    document.getElementById("srchMoreId").style.display = 'none';
    document.getElementById("srchFootMoreId").style.display = 'none';
  }
}


// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresearch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// And thanks to everyone else who has provided comments and suggestions.
// ====================================================================
function URLEncode(textToEncode)
{
  // The Javascript escape and unescape functions do not correspond
  // with what browsers actually do...
  var SAFECHARS = "0123456789" +					// Numeric
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
  "abcdefghijklmnopqrstuvwxyz" +
  "-_.!~*'()";					// RFC2396 Mark characters
  var HEX = "0123456789ABCDEF";
    
  var plaintext = textToEncode;
  var encoded = "";
  for (var i = 0; i < plaintext.length; i++ ) {
    var ch = plaintext.charAt(i);
    if (ch == " ") {
      encoded += "+";				// x-www-urlencoded, rather than %20
    } else if (SAFECHARS.indexOf(ch) != -1) {
      encoded += ch;
    } else {
      var charCode = ch.charCodeAt(0);
      if (charCode > 255) {
        alert( "Unicode Character '"
          + ch
          + "' cannot be encoded using standard URL encoding.\n" +
          "(URL encoding only supports 8-bit characters.)\n" +
          "A space (+) will be substituted." );
        encoded += "+";
      } else {
        encoded += "%";
        encoded += HEX.charAt((charCode >> 4) & 0xF);
        encoded += HEX.charAt(charCode & 0xF);
      }
    }
  } // for
  return encoded;
};

//document.onclick = hideHeaderMore;
/*end header functions*/

/* clear input box */
function enterTxt(id) {
  var txt = document.getElementById(id);
  if (txt.defaultValue == txt.value) {
    txt.value = '';
  }
}
/* shared module popup */
function shareWin(url) {
  w = window.open(url,'stylelistShared','resizable=yes,height=550,width=783');
  if (window.focus) {
    w.focus()
  }
  return false;
}
/* common */
var ratingFlg = true; // If user login info available, change this to true else false
var usrRate = 0;
var isAvgFlag;
function fn_miniSignIn(obj, parentUrl, hostname) {
    
  alert("fn_miniSignIn");
  var parDiv = document.createElement("div");
  parDiv.style.position="absolute";
  parDiv.style.zIndex="100";
  parDiv.style.display="inline";
  parDiv.style.margin="22 -17";
  var innerHtml = ajaxCall("miniSignIn.jsp?parentUrl="+encodeURL(parentUrl)+"&hostname="+hostname);
  parDiv.innerHTML= "<div id='snsMiniUI' style='left: 0px; top: -49px; position: relative; z-index: 5000; display: block;'>"+innerHtml+"</div>";
  obj.appendChild(parDiv);
}

function comment_report_popup(obj, coco, violator, clip, deleteInfo){
    if(obj && document.getElementById("notPop") && obj.parentNode.rowIndex==flgFly) {return;}
  if(document.getElementById("notPop")){
    var x=document.getElementById("notPop").parentNode;
    x.parentNode.removeChild(x);
  }
  if(obj) {
    var parDiv = document.createElement("div");
    parDiv.style.position="absolute";
    parDiv.style.zIndex="100";
    parDiv.style.padding="20px 0px 0px 0px";
    parDiv.style.display="inline";
    parDiv.style.margin="22 -17";
    var innerHtml = ajaxCall("/commentReport.jsp?coco="+coco+"&violator="+violator+"&clip="+clip+"&dinfo="+deleteInfo+"&url="+document.location);
    flgFly = obj.parentNode.rowIndex;
    parDiv.innerHTML= "<div id='notPop'><a href='javascript:void(0);' onclick='javascript:comment_report_popup();' class='closeBut'>CLOSE</a><div class='notPMain'>"+innerHtml+"</div></div>";
    obj.parentNode.insertBefore(parDiv,obj);
  }
}
function reportThisComment(umtHost, coco, violator, clip, deleteInfo, contextPath) {
  var yourEmailAddr=document.getElementById("yourEmailAddr").value;
  var userComment=document.getElementById("additComments").value;
  var reportType=document.getElementById("reportType").value;
  var comment = encodeURIComponent(userComment + "<br>Report Type: " + reportType);
  clip = encodeURIComponent(clip + "<br><br>" + deleteInfo);
  // If no email address is sent use a default
  yourEmailAddr = yourEmailAddr.replace(/\s+/, "");
  if (yourEmailAddr == "") {
    yourEmailAddr = "living_user@aol.com";
  }
  var reportAbuseData = "action=insert&reporter=" + yourEmailAddr + "&product=LivingComments&violator=" + violator + "&coco=" + coco + "&violator_url=" + encodeURIComponent(document.location) + "&clip=" + clip  + "&comment=" + comment;

  http_request = false;
 
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      // set type accordingly to anticipated content type
      //http_request.overrideMimeType('text/xml');
      http_request.overrideMimeType('text/html');
    }
  } else if (window.ActiveXObject) { // IE
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  if (!http_request) {
    //alert('Cannot create XMLHTTP instance');
    return false;
  }
  //alert('host: ' + umtHost + '\nreporter: ' + yourEmailAddr+ '\nviolator: ' + violator + '\ncountry: ' + coco + '\nURL: ' + document.location + "\nclip: " + clip + "\ncomment: " + comment);

  http_request.open('POST', umtHost, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", reportAbuseData.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(reportAbuseData);
    javascript:comment_report_popup();
}
function reportThisCommentCancel() {
  //alert("test");
  javascript:comment_report_popup();
}

function cntCheckOfCommntsInNotify()
{
  var     cnt=document.getElementById("notifyCommentsMaxLength");
  var     field=document.getElementById("additComments").value;
  var len=field.length;
  if(len > 1024){
    document.getElementById("additComments").value=field.substring(0,1024);
  }
  cnt.innerText=1024-len;
  cnt.innerHTML=1024-len;
}


function ajaxCall(url) {
  var page_request = false;
    
  if (window.ActiveXObject){ // if IE
    try {
      page_request = new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch (e){
      try{
        page_request = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch (e){}
    }
  }
  else if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
  else
    return false
  page_request.open('GET', url, false) //get page synchronously
  page_request.send(null);
  return page_request.responseText;
    
}

var channelURN = "";
var galId = "";
var user = "";

// Login Functions
function getEl( id ){ return document.getElementById( id ); }
function AsnsSignIn( obj, leftOffSet, topOffSet, ele ) {
  if (!leftOffSet) leftOffSet = 0;
  if (!topOffSet) topOffSet = 0;
  var pSNS = getEl(ele);
  pSNS.innerHTML = "";
  pSNS.innerHTML += _sns_var_;
  if ( document.all ) {
    var pos = findPos(obj);
    pSNS.style.position = 'absolute';
    pSNS.style.left = (pos[0] + leftOffSet - 138) + 'px';
    pSNS.style.top =  (pos[1] + topOffSet + 12)  + 'px';
  } else {
    obj.appendChild(pSNS);
    pSNS.style.left = leftOffSet + 'px';
    pSNS.style.top =  topOffSet  + 'px';
    pSNS.style.position = 'relative';
  }
  var close = document.createElement("span");
  var a = document.createElement("a");
  a.href = 'javascript:AsnsClose("'+ele+'")';
  a.title = "close";
  var img = document.createElement("img")
  img.src = "http://my.screenname.aol.com/images/10x10_x.gif";
  img.style.border = "0px"
  a.appendChild(img);
  close.appendChild(a);
  spans = pSNS.getElementsByTagName("span");
  spans[1].style.cssFloat = "right";
  spans[1].style.styleFloat = "right";
  spans[1].style.margin = "1px 0px 0px 10px";
  close.style.cssFloat = "right";
  close.style.styleFloat = "right";
  close.style.margin = "2px 2px 0px 0px";
  spanPar = spans[1].parentNode;
  spanPar.insertBefore(close,spans[1]);
  pSNS.style.zIndex = 5000;
  pSNS.style.display = "block";
}
function closeSNS(ele) {
  getEl(ele).innerHTML = '';
}

function AsnsClose(ele) {
  pSNS = getEl(ele);
  pSNS.style.display = "none";
}

function findPos(obj) {
  var curleft = curtop = 0;
  curleft = getX(obj);
  curtop = getY(obj);
  return [curleft,curtop];
}
function getY( oElement )
{
  var iReturnValue = 0;
  while( oElement != null ) {
    iReturnValue += oElement.offsetTop;
    oElement = oElement.offsetParent;
  }
  return iReturnValue;
}

function getX( oElement )
{
  var iReturnValue = 0;
  while( oElement != null ) {
    iReturnValue += oElement.offsetLeft;
    oElement = oElement.offsetParent;
  }
  return iReturnValue;
}
function loginCheck(sitedomain) {
  var sitedmn = "sitedomain="+sitedomain;
  var origPath = "" + window.location + "";
  var url="siteState="+encodeURIComponent("OrigUrl="+encodeURIComponent(origPath));
  if(_sns_isLoggedIn) {
    getEl("userspan").innerHTML="Logged In: "+_sns_current_user;
    getEl("loginlink").href="https://my.screenname.aol.com/_cqr/logout/mcLogout.psp?"+sitedmn+"&"+url;
    getEl("loginlink").title="Sign Out";
    getEl("loginlink").innerHTML="Sign Out";
  } else {
    getEl("loginlink").href="https://my.screenname.aol.com/_cqr/login/login.psp?"+sitedmn+"&"+url;
    getEl("loginlink").title="Sign In";
    getEl("loginlink").innerHTML="Sign In";
  }
}
/* end of login*/

function encodeURL (string) {
  string = string.replace(/\r\n/g,"\n");
  var utftext = "";
    
  for (var n = 0; n < string.length; n++) {
        
    var c = string.charCodeAt(n);
        
    if (c < 128) {
      utftext += String.fromCharCode(c);
    }
    else if((c > 127) && (c < 2048)) {
      utftext += String.fromCharCode((c >> 6) | 192);
      utftext += String.fromCharCode((c & 63) | 128);
    }
    else {
      utftext += String.fromCharCode((c >> 12) | 224);
      utftext += String.fromCharCode(((c >> 6) & 63) | 128);
      utftext += String.fromCharCode((c & 63) | 128);
    }
        
  }
    
  return utftext;
}

function galChRate(obj,aStr,rating) {
  var ratColl = document.getElementById("gRat").getElementsByTagName("div");
  for(i=0;i<ratColl.length;i++) {
    ratColl[i].className = i<rating?"backPicFill":"backPicEmpty";
  }
  if(aStr=="Average Rating") {
    obj.parentNode.innerHTML = "<span  onclick=\"javascript:galChRate(this,'Your Rating',"+avgRating+");\" style=\"color:#3094C6;cursor:pointer;\">Avg Rating </span>";
    isAvgFlag=0;
  }
  else{
    obj.parentNode.innerHTML = "<span  onclick=\"javascript:galChRate(this,'Average Rating',"+yourRating+");\" style=\"color:#3094C6;cursor:pointer;\">Your Rating </span>";
    isAvgFlag=1;
  }
  galRate();
}

function galRate() {
    if(isAvgFlag==1){return;}
  var ratColl = document.getElementById("gRat").getElementsByTagName("div");
  var rateTemp = usrRate==0 && ratColl[0].parentNode.getAttribute("rating")>0?ratColl[0].parentNode.getAttribute("rating"):usrRate;
  for(i=0;i<ratColl.length;i++) {
    ratColl[i].className = i<rateTemp?"backPicFill":"backPicEmpty";
  }
}

function galRatingIn(obj) {
    if(isAvgFlag==1){return;}
  var ratColl = document.getElementById("gRat").getElementsByTagName("div");
  for(i=0;i<ratColl.length;i++) {
    ratColl[i].className = i<obj.id.replace("star","")?"backfillash":"backPicEmpty";
  }
}

function galRateItPhotoStream(obj,photoURN,catId,userGUID){
  usrRate = obj.id.replace("star","");
  ajaxCall("rateItPhotoStream.jsp?rating="+usrRate+"&photoURN="+galleryId+"&catid="+catId+"&uname="+userGUID);
  yourRating=usrRate;
}

function galRateIt(obj,galleryId,catId,userGUID) {
  usrRate = obj.id.replace("star","");
  ajaxCall("rateIt.jsp?rating="+usrRate+"&galleryURN="+galleryId+"&catid="+catId+"&uname="+userGUID);
  yourRating=usrRate;
}

function fDate(){
  var todayDate = new Date();
  var montharray = new Array(12);
    
  montharray[0]="January";
  montharray[1]="February";
  montharray[2]="March";
  montharray[3]="April";
  montharray[4]="May";
  montharray[5]="June";
  montharray[6]="July";
  montharray[7]="August";
  montharray[8]="September";
  montharray[9]="October";
  montharray[10]="November";
  montharray[11]="December";
    
  theDay=todayDate.getDay();
  switch (theDay)
  {
    case 6:
      todayDate.setDate(todayDate.getDate() - 1);
      break;
    case 0:
      todayDate.setDate(todayDate.getDate() - 2);
      break;
  }
  if (document.getElementById("todayDate"))
    document.getElementById("todayDate").innerHTML = montharray[todayDate.getMonth()] + " " + todayDate.getDate() + ", " + todayDate.getFullYear();
}

var ratingFlg = true; // If user login info available, change this to true else false
var usrRate = 0;
var isAvgFlag = 0;
var userRating = 0;
function getEl( id ){ return document.getElementById( id ); }
function addComment()
{
  document.commentAddForm.newCommentBody.value=document.commentAddForm.newCommentBody.value.replace(/^\s*/, "").replace(/\s*$/, "").replace(/\\/g,"");
  if(document.commentAddForm.newCommentBody.value.length==0 || document.commentAddForm.newCommentBody.value.indexOf("Type your own comment here")>-1){
        return false;}else{
    document.commentAddForm.submit();
  }
}
function ajaxCall(url) {
  var page_request = false;
  if (window.ActiveXObject){ // if IE
    try {
      page_request = new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch (e){
      try{
        page_request = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch (e){}
    }
  }
  else if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
  else
    return false
  page_request.open('GET', url, false) //get page synchronously
  page_request.send(null);
  return page_request.responseText;
}
function galRate() {
    if(isAvgFlag==1){return;}
  var ratColl = document.getElementById("gRat").getElementsByTagName("div");
  var rateTemp = usrRate==0 && ratColl[0].parentNode.getAttribute("rating")>0?ratColl[0].parentNode.getAttribute("rating"):usrRate;
  for(i=0;i<ratColl.length;i++) {
    ratColl[i].className = i<rateTemp?"backPicFill":"backPicEmpty";
  }
}
function galRateItAs(obj,path,assetURN,catId,userGUID,assetType)
{
  //alert("radha");
  //if(!ratingFlg) {return;}
    if(userRating==1){return;}
  usrRate = obj.id.replace("star","");
  //alert("gallery: " + galleryId + "catId: " + catId + "userGUID: " + userGUID);
  ajaxCall(path+"/rateIt?rating="+usrRate+"&assetURN="+assetURN+"&catid="+catId+"&userGUID="+userGUID+"&type="+assetType);
  //ratingFlg = false;
  yourRating=usrRate;
  userRating=1;
}
function galRatingIn(obj)
{	
  //alert(userRating);
  //alert(isAvgFlag);
    if(isAvgFlag==1){return;}
    if(userRating==1){return;}
  //if(!ratingFlg) {return;}
  var ratColl = document.getElementById("gRat").getElementsByTagName("div");
  for(i=0;i<ratColl.length;i++) {
    ratColl[i].className = i<obj.id.replace("star","")?"backfillash":"backPicEmpty";
  }
//userRating=1;
}
function galChRate(obj,aStr,rating,pgName)
{	
  var ratColl = document.getElementById("gRat").getElementsByTagName("div");
  for(i=0;i<ratColl.length;i++) {
    ratColl[i].className = i<rating?"backPicFill":"backPicEmpty";
  }
  if(aStr=="Average Rating"){
    obj.parentNode.innerHTML = "<span  onclick=\"javascript:galChRate(this,'Your Rating',"+avgRating+",'"+pgName+"');\" style=\"color:#3094C6;cursor:pointer;\">Avg Rating </span>";
    document.getElementById("ratingTitle").innerHTML="Your Rating";
    isAvgFlag=0;
  }
  else{
    obj.parentNode.innerHTML = "<span  onclick=\"javascript:galChRate(this,'Average Rating',"+yourRating+",'"+pgName+"');\" style=\"color:#3094C6;cursor:pointer;\">Your Rating </span>";
    if(pgName=="gallery")
      document.getElementById("ratingTitle").innerHTML="Avg Rating";
    else
      document.getElementById("ratingTitle").innerHTML="Photo Avg Rating";
    isAvgFlag=1;
  }
  galRate();
}
function shareWin(url) {
  var winurl=new String(window.location);
  winurl=replaceAll(winurl, '&', '!');
  url+="&parentUrlEncoded="+winurl;
  w = window.open(url,'stylelistShared','resizable=yes,height=550,width=783');
  if (window.focus) {
    w.focus()
  }
  return false;
}
function popupWin(url,atts) {
  w = window.open(url,'popupWin',atts);
  if (window.focus) {
    w.focus()
  }
  return false;
}
function replaceAll(winurl, pcFrom, pcTo){
  var i = winurl.indexOf(pcFrom);
  var c = winurl;
  while (i > -1){
    c = c.replace(pcFrom, pcTo);
    i = c.indexOf(pcFrom);
  }
  return c;
}

function copy(text2copy,path) {	
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text2copy);
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="'+path+'/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
    
  }
}
function clickclear(thisfield, defaulttext) {
  if (thisfield.value == defaulttext) {
    thisfield.value = "";
  }
}

function fn_miniSignIn(obj, parentUrl, sitedomain,contextPath){
    
  //if(obj) {
  var parDiv = document.createElement("div");
  parDiv.style.position="absolute";
  parDiv.style.zIndex="100";
  parDiv.style.display="inline";
  parDiv.style.margin="22 -17";
  var innerHtml = ajaxCall(contextPath+"/miniSignIn.jsp?parentUrl="+encodeURL(parentUrl)+"&sitedomain="+sitedomain);
  //flgFly = obj.parentNode.rowIndex;
  parDiv.innerHTML= "<div id='snsMiniUI' style='left: -103px; top: -49px; position: relative; z-index: 5000; display: block;'>"+innerHtml+"</div>";
  obj.appendChild(parDiv);
//}
    
}

/* Begin: Code for video promo module*/

var vpObject = function() {
  this.totalImg = 0;
  this.vpTimer = 0;
  this.currImg = 0;
  this.imgSrcArray = new Array();
  this.imgCrdArray = new Array();
  this.ovrArray = new Array();
  this.vpOpTimer = 0;
  this.rotInt = 5;
  this.fadeSpeed = 50;
}

function vpClass() {
    
  var setOpacity = function(mId,id,value) {
        
    var object = ge(id).style;
    //beat the IE bug
    if(document.all)
      object.zoom=1;
        
    object.opacity = (value / 10);
    object.MozOpacity = (value / 10);
    object.KhtmlOpacity = (value / 10);
    object.filter = "alpha(opacity=" + value*10 + ")";
  }
    
  var ovrlayDomCreate = function(mId){
    var mI = window['vpMod_'+mId];
    var d = window.document;
    var pLnk = ge('vpImgLnk_'+mId);
    var imgCnt = ge('vpImgCnt_'+mId);
        
    a = d.createElement('a');
    a.className = 'ovrLay';
    a.id = 'vpOvrLnk_'+mId;
    a.href = pLnk.href;
    a.innerHTML = '&nbsp;';
        
    wd = d.createElement('div');
    wd.className = 'overLayWrp';
    wd.appendChild(a);
    imgCnt.appendChild(wd);
    pLnk.onclick = ge('lkLst'+mId+'_'+mI.currImg).onclick;
  }
    
  var next = function(mId) {
    var ovrlayDiv = '<div class="overLayWrp"><a href="http://food.aol.com/tyler-florence?video=3" class="ovrLay" id="vpOvrLnk_12190">&nbsp;</a></div>';
    var objId = 'vpMod_'+mId;
    var mI = window[objId];
    var fadeInt = 0;// fading speed
    //it is necessary to clear the previous timer as the user's next click may break the sequence
    clearTimeout(mI.vpTimer);
    setOpacity(mId,'vpImgCnt_'+mId,10);
        
    //current highlighted list item
    var curlkLst = 'lkLst'+mId+'_'+mI.currImg;
    //fade out the current image
    for(var i=10;i>=0;i--) {
      fn = "vpClassObj.setOpac('"+mId+"','vpImgCnt_" + mId + "','" + i + "')";
      setTimeout(fn,fadeInt);
      fadeInt+=mI.fadeSpeed;;
    }
        
    //remove the highlight from current list item
    fn = "document.getElementById('"+curlkLst+"').className=''";
    setTimeout(fn,fadeInt);
        
    fn = "window.vpClassObj.showNextWrap('"+mId+"')";
    mI.vpTimer = setTimeout(fn,fadeInt);
  }
    
  var showNext = function(mId) {
    var objId = 'vpMod_'+mId;
    var mI = window[objId];
        
    var fadeInt = 0;//fading speed
        
    if(++mI.currImg >= mI.totalImg) {
      mI.currImg = 0;
    }
        
    //remove highlight from the current link and add to next link
    var curlkLst = 'lkLst'+mId+'_'+mI.currImg;
    ge(curlkLst).className = "highlight";
        
    //update credit text , image and the overlay image
    ge('ptCredit_'+mId).innerHTML = mI.imgCrdArray[mI.currImg];
    ge('vpImgCnt_'+mId).innerHTML = mI.imgSrcArray[mI.currImg];
    if(mI.ovrArray[mI.currImg] == 1) {
      ovrlayDomCreate(mId);
    }
    //fade in the new image
    for(var i=0;i<=10;i++) {
      fn = "vpClassObj.setOpac('"+mId+"','vpImgCnt_" + mId + "','" + i + "')";
      mI.vpTimer=setTimeout(fn,fadeInt);
      fadeInt+=mI.fadeSpeed;
    }
    scroll(mId,(mI.rotInt-(mI.fadeSpeed/1000)));
  }
    
  var prev = function(mId) {
    var objId = 'vpMod_'+mId;
    var mI = window[objId];
    var fadeInt = 0;// fading interval
    //it is necessary to clear the previous timer as the user's next click may break the sequence
    clearTimeout(mI.vpTimer);
    setOpacity(mId,'vpImgCnt_'+mId,10);
        
    //current highlighted list item
    var curlkLst = 'lkLst'+mId+'_'+mI.currImg;
    //fade out the current image
    for(var i=10;i>=0;i--) {
      fn = "vpClassObj.setOpac('"+mId+"','vpImgCnt_" + mId + "','" + i + "')";
      setTimeout(fn,fadeInt);
      fadeInt+=mI.fadeSpeed;;
    }
        
    //remove the highlight from current list item
    fn = "document.getElementById('"+curlkLst+"').className=''";
    setTimeout(fn,fadeInt);
        
    fn = "window.vpClassObj.showPrevWrap('"+mId+"')";
    mI.vpTimer = setTimeout(fn,fadeInt);
  }
    
  var showPrev = function(mId) {
    var objId = 'vpMod_'+mId;
    var mI = window[objId];
        
    var fadeInt = 0;//fading speed
        
    if(--mI.currImg < 0) {
      mI.currImg = parseInt(mI.totalImg-1);
    }
        
    //remove highlight from the current link and add to next link
    var curlkLst = 'lkLst'+mId+'_'+mI.currImg;
    ge(curlkLst).className = "highlight";
        
    //update credit text and image
    ge('ptCredit_'+mId).innerHTML = mI.imgCrdArray[mI.currImg];
    ge('vpImgCnt_'+mId).innerHTML = mI.imgSrcArray[mI.currImg];
    if(mI.ovrArray[mI.currImg] == 1) {
      ovrlayDomCreate(mId);
    }
    //fade in the new image
    for(var i=0;i<=10;i++) {
      fn = "vpClassObj.setOpac('"+mId+"','vpImgCnt_" + mId + "','" + i + "')";
      mI.vpTimer=setTimeout(fn,fadeInt);
      fadeInt+=mI.fadeSpeed;
    }
    scroll(mId,(mI.rotInt-(mI.fadeSpeed/1000)));
  }
    
  var scroll = function(mId,time) {
    var objId = 'vpMod_'+mId;
    mI = window[objId];
    var fn = "window.vpClassObj.vpNextImg('"+mId+"')";
    mI.vpTimer = setTimeout(fn,1000*time);
  }
    
    var ge = function(id){return document.getElementById(id);}
    
  return {
        
    vpNextImg : function(mId) {
      next(mId);
    },
        
    vpPrevImg : function(mId) {
      prev(mId);
    },
        
    autoScroll : function(mId,time) {
      scroll(mId,time);
    },
        
    stopScroll : function(mId) {
      var objId = 'vpMod_'+mId;
      mI = window[objId];
      clearTimeout(mI.vpTimer);
    },
        
    setOpac : function(mId,objId,value) {
      setOpacity(mId,objId,value);
    },
        
    showNextWrap: function(mId) {
      showNext(mId);
    },
        
    showPrevWrap: function(mId) {
      showPrev(mId);
    }
        
  };
    
}

var vpClassObj = new vpClass();
/* End code for video promo module */

//begin HP Tabblo code for Print Article
function __TABBLO_TPT_LOAD() {
  Tabblo.embedded.sites.SettingsObject.preprocess.apply({
        
    Properties:
    {
      template: 'news_large'
    },
    FixedContent:
    {
      accentcolor: '#555',
      accentcolor2: '#ccc'
    },
    // content definition:
    Content:
    {
            'pagetitle':   { match: 'css', selector:'.artHeader h2' },
            'text':        { match: 'css', selector:'#mainArtNavHead' },
            'logo':        { match: 'match',  attr: 'src', value:'gmc-title', continueHooks: false, nodeContentType: 'image' }
      }
  },[]);
  Tabblo.embedded.printabulous();
}

function MakePDF() {
  // append tabblo print script on demand
  var _tpt_script_loaded = false;
  if (!_tpt_script_loaded) {
    _tpt_script_loaded = true;
    var tpS = document.createElement('script');
    tpS.setAttribute('type','text/javascript');
    tpS.setAttribute('charset', 'utf-8');
    tpS.setAttribute('src','http://h30405.www3.hp.com/edit/tptboot/1.0');
    document.getElementsByTagName('body').item(0).appendChild(tpS);
  } else {
    Tabblo.embedded.detect.setup(Tabblo.embedded.printabulous.bind(null,false));
  }
}
//end HP Tabblo code

// LOCALNAV DYNAMIC HIGHTLIGHTING
function selCatAsset() {
  if(document.getElementById("LocalNav").getElementsByTagName("ul")) {
    var ulObjARR = document.getElementById("LocalNav").getElementsByTagName("ul")[0];
    for(i=0;i<ulObjARR.getElementsByTagName("a").length;i++) {
      if(ulObjARR.getElementsByTagName("a")[i].href.indexOf(catSTR+"/"+assetSTR)>-1) {
        ulObjARR.getElementsByTagName("a")[i].className = "picLocalNavDflt";
      }
    }
  }
}

function levisPopUp(path){
  url = path;
  var stat = ajaxCall(url);
  var enDiv = document.createElement("div");
  enDiv.setAttribute('id','outerEnDiv');
  var enInDiv = document.createElement("div");
  enInDiv.setAttribute('id','inEnDiv');
  enInDiv.innerHTML=stat;
  document.body.appendChild(enDiv);
  document.body.appendChild(enInDiv);
  document.getElementById('outerEnDiv').style.height = document.body.clientHeight + "px";
  window.scrollTo(0,0);
}
function levisPopUpCancel() {

  if(document.getElementById("levisMain")){

    /*var x=document.getElementById("levisMain").parentNode;
        x.parentNode.removeChild(x);*/
    document.body.removeChild(document.getElementById("outerEnDiv"));
    document.body.removeChild(document.getElementById("inEnDiv"));
  }

}

function ajaxCall(url) {
  var page_request = false;
  if (window.ActiveXObject){ // if IE
    try {
      page_request = new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch (e){
      try{
        page_request = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch (e){}
    }
  }
  else if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
  else
    return false
  page_request.open('GET', url, false) //get page synchronously
  page_request.send(null);
  return page_request.responseText;
}
function regFormCheck()
{
  var flag=0;
  var params="";
  for(i=0;i<document.lReg.elements.length-1;i++)
  {
    if(document.lReg.elements[i].type == "text" && document.lReg.elements[i].value=="" || document.lReg.elements[i].type == "select-one" && document.lReg.elements[i].selectedIndex==0) {
      if(document.lReg.elements[i].parentNode.getElementsByTagName("label")[0].className != 'err'){
        document.lReg.elements[i].parentNode.getElementsByTagName("label")[0].className += "err";
      }
      document.getElementById("levisError").style.display="block";
      flag++;
    } else {
      document.lReg.elements[i].parentNode.getElementsByTagName("label")[0].className = document.lReg.elements[i].parentNode.getElementsByTagName("label")[0].className.replace(/err/g,"");
            
    }
    params+=document.lReg.elements[i].name+"="+document.lReg.elements[i].value+"&";
  }
  if(document.lReg.opt_in_1.checked==true){
        params+=document.lReg.opt_in_1.name+"="+document.lReg.opt_in_1.value;}else{
        params+=document.lReg.opt_in_1.name+"=0";}
  if(flag<=0){
    var  url="/userInfo.jsp?"+params;
    var stat=ajaxCall(url);
    if(stat==1){
      document.body.removeChild(document.getElementById("outerEnDiv"));
      document.body.removeChild(document.getElementById("inEnDiv"));
      document.getElementById('createGal').style.display="block";
    }
  }
    
}
//End of LocalNav dynamic hilight
/**
 *  getElementsByClassName
 *  Developed by Robert Nyman, http://www.robertnyman.com
 *  Code/licensing: http://code.google.com/p/getelementsbyclassname/
 */
var getElementsByClassName = function (className, tag, elm){
  if (document.getElementsByClassName) {
    getElementsByClassName = function (className, tag, elm) {
      elm = elm || document;
      var elements = elm.getElementsByClassName(className),
      nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
      returnElements = [],
      current;
      for(var i=0, il=elements.length; i<il; i+=1){
        current = elements[i];
        if(!nodeName || nodeName.test(current.nodeName)) {
          returnElements.push(current);
        }
      }
      return returnElements;
    };
  }
  else if (document.evaluate) {
    getElementsByClassName = function (className, tag, elm) {
      tag = tag || "*";
      elm = elm || document;
      var classes = className.split(" "),
      classesToCheck = "",
      xhtmlNamespace = "http://www.w3.org/1999/xhtml",
      namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
      returnElements = [],
      elements,
      node;
      for(var j=0, jl=classes.length; j<jl; j+=1){
        classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
      }
      try	{
        elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
      }
      catch (e) {
        elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
      }
      while ((node = elements.iterateNext())) {
        returnElements.push(node);
      }
      return returnElements;
    };
  }
  else {
    getElementsByClassName = function (className, tag, elm) {
      tag = tag || "*";
      elm = elm || document;
      var classes = className.split(" "),
      classesToCheck = [],
      elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
      current,
      returnElements = [],
      match;
      for(var k=0, kl=classes.length; k<kl; k+=1){
        classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
      }
      for(var l=0, ll=elements.length; l<ll; l+=1){
        current = elements[l];
        match = false;
        for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
          match = classesToCheck[m].test(current.className);
          if (!match) {
            break;
          }
        }
        if (match) {
          returnElements.push(current);
        }
      }
      return returnElements;
    };
  }
  return getElementsByClassName(className, tag, elm);
};

function collapseAds() {
  var ad = getElementsByClassName('collapseAd');
  if (ad != '') {
    var arr = ad.length;
    for (var i=0, len=arr; i<len; ++i) {
      if (ad[i].offsetHeight <= 30) {
        ad[i].style.display = 'none';
        ad[i].style.border = '1px solid red';
      }
    }
  }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func;
    }
  }
}
/* windows.onload functions begin here */
addLoadEvent(fDate);
addLoadEvent(setTimeout('collapseAds()',8000));

/* Relegence */
function hideHeadlines() 
{
  var infodiv = document.getElementById("headlinesInfo");
  infodiv.style.display = "none";
}
		
function hideRelated() 
{
  unPauseRiverWidget();
  var infodiv = document.getElementById("newsRelatedInfo");
  if (infodiv != null)
  {
    infodiv.style.display = "none";
    infodiv.firstChild.innerHTML = "";
    clearTimeout(RelatedPopupTimer);
  }
}
function unPauseRiverWidget() 
{
  // read through stories stored and call populate RiverWidget
  var story = dropOldestStory();
  while (story != null) {
    // Do filtering
    outputToPage(story[0]);
    story = dropOldestStory();
  }
  pauseRiverWidget = "";
}

function handleHeadlineHover(e, storyDate, firstLine, filterSource, thisDiv)
{
  var infodiv = document.getElementById("headlinesInfo");
  xy = findPos(thisDiv);

  infodiv.style.display = "block";
  xy[0] = xy[0] + thisDiv.offsetWidth;

  infodiv.style.left = xy[0] + "px";
	
  infodiv.style.top = xy[1] + "px";
  infodiv.innerHTML = firstLine;
  if (navigator.appName == "Microsoft Internet Explorer")	{
    infodiv.style.left = xy[0] - 137 + "px";
  }
  HeadlinePopupTimer = setTimeout('hideHeadlines()', RTN_HOVER_TIMEOUT);
}

function showTab(param) {
  document.getElementById("rAll").style.display = "none";
  document.getElementById("rBlog").style.display = "none";
  document.getElementById("rNews").style.display = "none";
  document.getElementById("all").className = "all";
  document.getElementById("blogs").className = "blogs";
  document.getElementById("news").className = "news";
  switch(param) {
    case 1:
      document.getElementById("all").className = "all selected";
      document.getElementById("rAll").style.display = "";
      break;
    case 2:
      document.getElementById("blogs").className = "blogs selected";
      document.getElementById("rBlog").style.display = "";
      break;
    case 3:
      document.getElementById("news").className = "news selected";
      document.getElementById("rNews").style.display = "";
      break;
    default:
      document.getElementById("all").className = "all selected";
      document.getElementById("rAll").style.display = "";
  }
}

//Ticker for Editor's Pick Page

var ticker = {
			params: {slideRate:100,interval:3000,message:"",tickers:null,activeSlide:0},
  init: function() {
    this.params.tickers = document.getElementById("tickerEditorPick").getElementsByTagName("li");
    for(i=0;i<this.params.tickers.length;i++) {
      this.params.tickers[i].style.display = "none";
      this.params.tickers[i].style.zoom = 1;
      this.params.tickers[i].style.opacity = 0;
      this.params.tickers[i].style.filter = "alpha(opacity=0)";
      this.params.tickers[i].style.marginLeft = -50+"px";
    }
    this.next();
  },
  next: function() {
    for(i=0;i<this.params.tickers.length;i++) {
      if(this.params.activeSlide==i) {
        this.params.message = this.params.tickers[i].innerHTML;
        this.animateFade();
        return;
      }
    }
  },
  animateFade: function() {
    this.params.tickers[this.params.activeSlide].style.display = "";
    if(this.params.tickers[this.params.activeSlide].style.opacity<1) {
      this.params.tickers[this.params.activeSlide].style.opacity = 0.1+eval(this.params.tickers[this.params.activeSlide].style.opacity);
      this.params.tickers[this.params.activeSlide].style.filter = "alpha(opacity="+(this.params.tickers[this.params.activeSlide].style.opacity*100)+")";
      this.params.tickers[this.params.activeSlide].style.marginLeft = 5+eval(this.params.tickers[this.params.activeSlide].style.marginLeft.replace("px",""))+"px";
      setTimeout("ticker.animateFade()",this.params.slideRate);
    } else {
      this.params.activeSlide = this.params.activeSlide==this.params.tickers.length-1?0:this.params.activeSlide+1;
      setTimeout("ticker.init()",this.params.interval);
    }
  }
}
// Comment On & Off
function fn_toggleComments(obj) {
  var objLi = obj.parentNode.parentNode.getElementsByTagName("li");
  var objDiv = document.getElementById("RecentComments").getElementsByTagName("div");
  if(objLi.length==3) {
    if(objLi[0].style.display=="none") {
      objLi[0].style.display = "";
      objLi[1].style.display = "";
      objLi[2].firstChild.innerHTML = "Turn Comments Off";
      for(i=0;i<objDiv.length;i++) {
        objDiv[i].className=="recComOuter"?objDiv[i].style.display = "":"";
      }
    } else {
      objLi[0].style.display = "none";
      objLi[1].style.display = "none";
      objLi[2].firstChild.innerHTML = "Turn Comments On";
      for(i=0;i<objDiv.length;i++) {
        objDiv[i].className=="recComOuter"?objDiv[i].style.display = "none":"";
      }
    }
  }
}
//End of Comment On & Off

//Ajax call for Rght Col user Photos
function onloadPhotosAjax(url){   
  document.getElementById("StyleCommunity").innerHTML= ajaxCall(url);
}

//Ajax call for Relegence
function onloadrelegenceAjax(url){   
  document.getElementById("relegence").innerHTML= ajaxCall(url);
}

