YAHOO.namespace("example.container");

var win_location = window.location.href.substring(window.location.href.lastIndexOf("/")+1, window.location.href.length); 

//------------------------------------------------------------------------------
//- HELPER FUNCTIONS
//------------------------------------------------------------------------------

function enter_pressed(e) {
	//- Internet Explorer
	if(window.event) { 
	   keynum = e.keyCode;
	}
	//- Firefox/Netscape/Opera
	else if(e.which) { 
	   keynum = e.which;
	}
	if (keynum == 13) 
	    return true;
	else 
	    return false;
}

Array.prototype.contains = function(r)  {
    for(var x=0;x<this.length;x++) {
        if(this[x]==r)  {
            this.splice(x,1);
            return true;
        }
    }
    return false;
}

Array.prototype.intersection = function(arr2)   {
    for(var x=0; x<this.length; x++) {
        arr2.contains(this[x]);
    }
}

// Array.forEach( function ) - Apply a function to each element
Array.prototype.forEach = function( f ) {
    var i = this.length, j, l = this.length;
    for( i=0; i<l; i++ ) { if( ( j = this[i] ) ) { f( j ); } }
}

// Array.insert( index, value ) - Insert value at index, without overwriting existing keys
Array.prototype.insert = function( i, v ) {
    if( i>=0 ) {
      var a = this.slice(), b = a.splice( i );
      a[i] = v;
      return a.concat( b );
    }
}

// Array.lastIndexOf( value, begin, strict ) - Return index of the last element that matches value
Array.prototype.lastIndexOf = function( v, b, s ) {
    b = +b || 0;
    var i = this.length;
    while(i-->b) {
       if( this[i]===v || s && this[i]==v ) { return i; }
    }
    return -1;
}

// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
Array.prototype.indexOf = function( v, b, s ) {
    for( var i = +b || 0, l = this.length; i < l; i++ ) {
       if( this[i]===v || s && this[i]==v ) { return i; }
    }
    return -1;
}

// Array.random( range ) - Return a random element, optionally up to or from range
Array.prototype.random = function( r ) {
    var i = 0, l = this.length;
    if( !r ) { r = this.length; }
    else if( r > 0 ) { r = r % l; }
    else { i = r; r = l + r % l; }
    return this[ Math.floor( r * Math.random() - i ) ];
}

// Array.walk() - Change each value according to a callback function
Array.prototype.walk = function( f ) {
    var a = [], i = this.length;
    while(i--) { a.push( f( this[i] ) ); }
    return a.reverse();
}

// Array.unique( strict ) - Remove duplicate values
Array.prototype.unique = function( b ) {
    var a = [], i, l = this.length;
    for( i=0; i<l; i++ ) {
      if( a.indexOf( this[i], 0, b ) < 0 ) { a.push( this[i] ); }
    }
    return a;
}

//------------------------------------------------------------------------------
//- LOGOUT
//------------------------------------------------------------------------------
function init_logout() {
   var bsc_acc    = readCookie('bsc_access');

   if (bsc_acc > 0) {
       var bsc_usr = readCookie('bsc_user');
       var uid     = readCookie('bsc_uid');
       document.getElementById("login_info_static").innerHTML = "<div style='float:left;font-weight:bold;'>"+bsc_usr+" &raquo; </div>"
			+ "<div style='color:#ffffff;cursor:pointer;float:left;font-weight:bold;' id='logout_id' onclick='logout_func();'>&nbsp; logout</div>";
   }
}
YAHOO.util.Event.on(this, 'load', init_logout);

//------------------------------------------------------------------------------
//- MENU BUTTONS
//------------------------------------------------------------------------------

function init_top_menu() {
   var attr_md = {
       points:   {to: [YAHOO.util.Dom.getX('home_menu'), YAHOO.util.Dom.getY('home_menu')] },
           width: {to: 50}
   };
   var anim_md = new YAHOO.util.Motion('slidemenu', attr_md, 0.5, YAHOO.util.Easing.backOut);
   YAHOO.util.Event.on(document.getElementById("home_menu"), 'mouseover', anim_md.animate, anim_md, true);

   var attr_md1 = {
       points:   {to: [YAHOO.util.Dom.getX('faqs_menu'), YAHOO.util.Dom.getY('faqs_menu')] },
           width: {to: 50}
   };
   var anim_md1 = new YAHOO.util.Motion('slidemenu', attr_md1, 0.5, YAHOO.util.Easing.backOut);
   YAHOO.util.Event.on(document.getElementById("faqs_menu"), 'mouseover', anim_md1.animate, anim_md1, true);

   var attr_md2 = {
       points:   {to: [YAHOO.util.Dom.getX('blog_menu'), YAHOO.util.Dom.getY('blog_menu')] },
           width: {to: 50}
   };
   var anim_md2 = new YAHOO.util.Motion('slidemenu', attr_md2, 0.5, YAHOO.util.Easing.backOut);
   YAHOO.util.Event.on(document.getElementById("blog_menu"), 'mouseover', anim_md2.animate, anim_md2, true);

   var attr_md3 = {
       points:   {to: [YAHOO.util.Dom.getX('wiki_menu'), YAHOO.util.Dom.getY('wiki_menu')] },
           width: {to: 50}
   };
   var anim_md3 = new YAHOO.util.Motion('slidemenu', attr_md3, 0.5, YAHOO.util.Easing.backOut);
   YAHOO.util.Event.on(document.getElementById("wiki_menu"), 'mouseover', anim_md3.animate, anim_md3, true);

   var attr_md4 = {
       points:   {to: [YAHOO.util.Dom.getX('contact_menu'), YAHOO.util.Dom.getY('contact_menu')] },
           width: {to: 80}
   };
   var anim_md4 = new YAHOO.util.Motion('slidemenu', attr_md4, 0.5, YAHOO.util.Easing.backOut);
   YAHOO.util.Event.on(document.getElementById("contact_menu"), 'mouseover', anim_md4.animate, anim_md4, true);

   var attr_md5 = {
       points:   {to: [YAHOO.util.Dom.getX('lib_menu'), YAHOO.util.Dom.getY('lib_menu')] },
           width: {to: 80}
   };
   var anim_md5 = new YAHOO.util.Motion('slidemenu', attr_md5, 0.5, YAHOO.util.Easing.backOut);
   YAHOO.util.Event.on(document.getElementById("lib_menu"), 'mouseover', anim_md5.animate, anim_md5, true);

}
YAHOO.util.Event.on(this,'load', init_top_menu);

//------------------------------------------------------------------------------
//- TOP OF THE CHARTS 
//------------------------------------------------------------------------------

function closeTopOfCharts() 
{
   var attr_md_1 = {
     width:   {to: 0 },
     height:  {to: 0 },
     opacity: {to: 0 }
   };
   
   function close_view_panel() {
      var anim_md = new YAHOO.util.Anim('container_1_1', attr_md_1, 0.5, YAHOO.util.Easing.backOut);
      anim_md.animate();   
   }

   function show_open() {
      document.getElementById("tcharts").innerHTML = '<a href="#" id="top_charts"><img src="images/expand_ns.gif" border="0" title="open"></a>';
      document.getElementById("tcharts_txt").innerHTML = "click to open...";
      openTopOfCharts();
      if (win_location.match("bsc_movwin.html")) 
	  init_flash_ctrl();
   }

   var attr_md = {
       height:  { to: 15 }
   }; 

   var anim_md = new YAHOO.util.Anim('container_1', attr_md, 0.5, YAHOO.util.Easing.backOut);
   anim_md.onStart.subscribe(close_view_panel);
   anim_md.onComplete.subscribe(show_open);
   YAHOO.util.Event.on(document.getElementById("top_charts"), 'click', anim_md.animate, anim_md, true);
}

function openTopOfCharts()
{
   var attr_md_1 = {
       width:   {to: 954},
       height:  {to: 33}, 
       opacity: {to: 1 }
   }; 
   
   function show_view_panel() {
       var anim_md = new YAHOO.util.Anim('container_1_1', attr_md_1, 0.5, YAHOO.util.Easing.backOut);
       anim_md.animate();
   }                    
                           
   function show_open() {
       document.getElementById("tcharts").innerHTML = '<a href="#" id="top_charts"><img src="images/collapse_ns.gif" border="0" title="close"></a>';                    
       document.getElementById("tcharts_txt").innerHTML = "click to close...";
       show_view_panel();
       closeTopOfCharts();
       if (win_location.match("bsc_movwin.html")) 
	   init_flash_ctrl();
   }

   var attr_md = {
       height:  { to: 70 }
   };

   var anim_md = new YAHOO.util.Anim('container_1', attr_md, 0.5, YAHOO.util.Easing.backOut);
   anim_md.onComplete.subscribe(show_open);
   YAHOO.util.Event.on(document.getElementById("top_charts"), 'click', anim_md.animate, anim_md, true);
}
YAHOO.util.Event.on(this, 'load', closeTopOfCharts);

//------------------------------------------------------------------------------
//- ABOUTUS CONTROL
//------------------------------------------------------------------------------

function show_author(id) {
      if (id < 0) {
	  document.getElementById("author").innerHTML = "<center style='margin-top:30px;'><b>[</b> move mouse over team members to read about them <b>]</b></center>";
      }
      if (id == 0) {
	  document.getElementById("author").innerHTML = "Geeta is an electrical engineer with a management background. She makes sure the job gets done! She is still the only one in the team who uses a PC - its a Y2K IBM thinkpad... enough said!";
      }
      if (id == 1) {
	  document.getElementById("author").innerHTML = "Hari is a postdoctoral research fellow at Brandeis University. He is a biochemist and X-Ray crystallographer by day. The rest of his productive time is spent as a techno junkie - don't worry he is just a user, not a pusher... ok, maybe sometimes!";
      }
      if (id == 2) {
	  document.getElementById("author").innerHTML = "Suresh is a hardware designer by trade - but designing graphics and webapps are his true calling! He seems to pick up a computer language a week - he still doesn't know how he used to be productive without google search!";
      }
      if (id == 3) {
	  document.getElementById("author").innerHTML = "Shailja is a postdoctoral research fellow at Harvard Medical School working on Cancer genetics - she is also the resident icon designer and can do crazy things with adobe illustrator - Michael Angelo would have been proud!";
      }
      if (id == 4) {
	  document.getElementById("author").innerHTML = "Deepak aka 'Atom' <b>was</b> a chemist - <b>is</b> a marketing guru and an avid blogger. His blog is mndoci.com. He also blogs at techbizmedia.com. 'blog' runs through his veins!";
      }
}

function initAboutUs() {

      var title_menu = "About Us";

      function show_aboutus() {
              document.getElementById("aboutus_info_c").innerHTML = "<b><font size='4' color='#1C8CE2'>"+title_menu+"</font></b><br>"
                        + "<hr noshade style='width:580px;color:#cccccc;'></hr>"
			+ "<div style='font-size=11px;font-family:Verdana, Arial, Helvetica, sans-serif;'>"
			+ "<p style='text-align:justify;margin:20px 10px 0px 5px;'>We are a team of scientists and engineers who got together to create a "
			+ "website specifically for the <b>scientific community</b> to share <b>screencasts</b> (audio/video capture of software running on your computer screen). "
			+ "Our goal is to provide an easy-to-use platform for users to learn and "
			+ "share how to use software in the science space. <br><br>"
			+ "<b>Team</b><br><br>"
			+ "<a style='cursor:pointer;' onmouseover='show_author(0);' onmouseout='show_author(-1);'>Geeta Athalye</a><br>"
			+ "<a style='cursor:pointer;' onmouseover='show_author(1);' onmouseout='show_author(-1);'>Hari Jayaram, Ph.D</a><br>"
		 	+ "<a style='cursor:pointer;' onmouseover='show_author(2);' onmouseout='show_author(-1);'>Suresh Madhu</a><br>"
			+ "<a style='cursor:pointer;' onmouseover='show_author(3);' onmouseout='show_author(-1);'>Shailja Pathania, Ph.D</a><br>"
			+ "<a style='cursor:pointer;' onmouseover='show_author(4);' onmouseout='show_author(-1);'>Deepak Singh, Ph.D</a>"
			+ "</p></div>"														
			+ "<div id='author' style='position:absolute;top:140px;left:160px;width:350px;height:70px;text-align:justify;margin:0px;padding:10px;background:#f2f2f2;border:1px dotted #E39602;color:#1C8CE2;font-size:11px;'>"
			+ "<center style='margin-top:30px;'><b>[</b> move mouse over team members to read about them <b>]</b></center></div>";

              function eraseContent() {
                  document.getElementById("i_aboutus_bg").style.opacity = "0";
                  document.getElementById("aboutus_info_c").innerHTML = "";
              }
              function hideContact() {
                  document.getElementById("aboutus_info").style.visibility = "hidden";
                  document.getElementById("aboutus_info").style.display = "none";

   	  	  if (document.getElementById("CatBox") != null) {
	      	      document.getElementById("CatBox").style.overflowY = "auto";
  	  	  }	      
                 if (document.getElementById("nav_info") != null) {
                     document.getElementById("nav_info").style.visibility = "visible";
                 }
		 if (document.getElementById("flashcontent") != null) {
		     document.getElementById("flashcontent").style.visibility = "visible";
		 }
              }

          var attr_md = {
                opacity: { to: 0 },
                height : { to: 0 }
          };

          var anim_md = new YAHOO.util.Motion('c_aboutus_bg', attr_md, 0.5, YAHOO.util.Easing.backOut);
          anim_md.onStart.subscribe(eraseContent);
          anim_md.onComplete.subscribe(hideContact);
          YAHOO.util.Event.on(document.getElementById("exit_aboutus_info"),'click', anim_md.animate, anim_md, true);
      }

      function makeVisible() {
              function show_block() {
		 if (document.getElementById("flashcontent") != null) {
		     document.getElementById("flashcontent").style.visibility = "hidden";
		 }
                 if (document.getElementById("nav_info") != null) {
                     document.getElementById("nav_info").style.visibility = "hidden";
                 }
                 if (document.getElementById("CatBox") != null) {
                     document.getElementById("CatBox").style.overflowY = "hidden";
                 }
                 document.getElementById("aboutus_info").style.visibility = "visible";
                 document.getElementById("aboutus_info").style.display    = "block";
              }
              function show_shadow() {
                 document.getElementById("i_aboutus_bg").style.opacity    = "0.7";
              }
              var attr_md = {
                opacity: { to: 1 },
                height : { to: 302 }
              };
              var anim_md = new YAHOO.util.Motion('c_aboutus_bg', attr_md, 0.5, YAHOO.util.Easing.backOut);
              anim_md.onStart.subscribe(show_block);
              anim_md.onComplete.subscribe(show_shadow);
              anim_md.animate();
      }

      var attr_md = {
          points:   {from: [parseInt(YAHOO.util.Dom.getDocumentWidth()/2)-315,230], to: [parseInt(YAHOO.util.Dom.getDocumentWidth()/2)-315,230] }
      };

      var anim_md = new YAHOO.util.Motion('aboutus_info', attr_md, 0.5, YAHOO.util.Easing.backOut);
      anim_md.onStart.subscribe(makeVisible);
      anim_md.onComplete.subscribe(show_aboutus);

      YAHOO.util.Event.on(document.getElementById("aboutus"),'click', anim_md.animate, anim_md, true);
}
YAHOO.util.Event.onAvailable("aboutus", initAboutUs);

//------------------------------------------------------------------------------
//- MAKESC PANEL CONTROL
//------------------------------------------------------------------------------

function initMakesc() {

      var title_menu = "Make a screencast";

      function show_makesc() {
              document.getElementById("makesc_info_c").innerHTML = "<center><b><font size='4' color='#1C8CE2'>"+title_menu+"</font></b></center>"
                        + "<hr noshade style='width:580px;color:#cccccc;'></hr>"
			+ "<div style='font-size=11px;font-family:Verdana, Arial, Helvetica, sans-serif;position:relative;'>"
			+ "<p style='text-align:center;margin:0px;'>Download any of these tools below and start making your first screencast! Learn more about making screencasts with these tools at <a target='_new_' href='http://www.bioscreencastwiki.com/index.php?title=Screencast_tutorial' style='text-decoration:underline;'>bioscreencastwiki.com</a><br> "
			+ "<div style='position:absolute;left:30px;top:50px;'><a target='_new' href='http://www.shinywhitebox.com'><img style='border:0px;' src='./images/ishowu.png'></a></div>"
			+ "<div style='position:absolute;left:400px;top:40px;'><a target='_new' href='http://www.techsmith.com/camtasia.asp'><img style='border:0px;' src='./images/camtasia.png'></a></div>"
			+ "<div style='position:absolute;left:150px;top:60px;'><a target='_new' href='http://www.camstudio.org/'><img style='border:0px;' src='./images/camstudio.png'></a></div>"
			+ "<div style='position:absolute;left:220px;top:150px;'><a target='_new' href='http://www.debugmode.com/wink/'><img style='border:0px;' src='./images/wink.png'></a></div>"
			+ "<div style='position:absolute;left:260px;top:47px;'><img style='border:0px;' src='./images/itsfree.png'></div>"
			+ "<div style='position:absolute;left:220px;top:210px;'><img style='border:0px;' src='./images/itsfree.png'></div>"
			+ "</p></div>";														

              function eraseContent() {
                  document.getElementById("i_makesc_bg").style.opacity  = "0";
                  document.getElementById("makesc_info_c").innerHTML = "";
              }
              function hideContact() {
                  document.getElementById("makesc_info").style.visibility = "hidden";
                  document.getElementById("makesc_info").style.display = "none";

   	  	  if (document.getElementById("CatBox") != null) {
	      	      document.getElementById("CatBox").style.overflowY = "auto";
  	  	  }	      
                 if (document.getElementById("nav_info") != null) {
                     document.getElementById("nav_info").style.visibility = "visible";
                 }
              }

          var attr_md = {
                opacity: { to: 0 },
                height : { to: 0 }
          };

          var anim_md = new YAHOO.util.Motion('c_makesc_bg', attr_md, 0.5, YAHOO.util.Easing.backOut);
          anim_md.onStart.subscribe(eraseContent);
          anim_md.onComplete.subscribe(hideContact);
          YAHOO.util.Event.on(document.getElementById("exit_makesc_info"),'click', anim_md.animate, anim_md, true);
      }

      function makeVisible() {
              function show_block() {
                 if (document.getElementById("nav_info") != null) {
                     document.getElementById("nav_info").style.visibility = "hidden";
                 }
                 if (document.getElementById("CatBox") != null) {
                     document.getElementById("CatBox").style.overflowY = "hidden";
                 }
                 document.getElementById("makesc_info").style.visibility = "visible";
                 document.getElementById("makesc_info").style.display    = "block";
              }
              function show_shadow() {
                 document.getElementById("i_makesc_bg").style.opacity    = "0.7";
              }
              var attr_md = {
                opacity: { to: 1 },
                height : { to: 302 }
              };
              var anim_md = new YAHOO.util.Motion('c_makesc_bg', attr_md, 0.5, YAHOO.util.Easing.backOut);
              anim_md.onStart.subscribe(show_block);
              anim_md.onComplete.subscribe(show_shadow);
              anim_md.animate();
      }

      var attr_md = {
          points:   {from: [parseInt(YAHOO.util.Dom.getDocumentWidth()/2)-315,230], to: [parseInt(YAHOO.util.Dom.getDocumentWidth()/2)-315,230] }
      };

      var anim_md = new YAHOO.util.Motion('makesc_info', attr_md, 0.5, YAHOO.util.Easing.backOut);
      anim_md.onStart.subscribe(makeVisible);
      anim_md.onComplete.subscribe(show_makesc);

      YAHOO.util.Event.on(document.getElementById("makesc"),'click', anim_md.animate, anim_md, true);
}
YAHOO.util.Event.onAvailable("aboutus", initMakesc);

//------------------------------------------------------------------------------
//- CONTACT PANEL CONTROL
//------------------------------------------------------------------------------

function contact_enter_func(e) {

   if (enter_pressed(e)) {
       contact_func();
   }
}

function contact_func() {
   var em  = document.getElementById("contact_email").value;
   var fn  = document.getElementById("contact_name").value; 
   var msg = document.getElementById("contact_msg").value;

   if (em.lastIndexOf("@") == -1) {
      document.getElementById("contact_result").innerHTML = "<font color='red'>error:</font> please enter a valid email address";
      return;   
   }

   if (fn.length < 1) {
      document.getElementById("contact_result").innerHTML = "<font color='red'>error:</font> please enter a name";
      return;   
   }

   if (msg.length < 1) {
      document.getElementById("contact_result").innerHTML = "<font color='red'>error:</font> please enter a message";
      return;   
   }   

   var postData = "contact_email="+em+"&contact_name="+fn+"&contact_msg="+msg;
      
   var cb = {
                        success : function(o) {
                           document.getElementById("contact_result").innerHTML = "<font color='green'>success:</font> "+o.responseText;
                           document.getElementById("contact_signup").innerHTML = "<img src='images/greybutton_submit.gif'>";
                        },
                        failure : function(o) {
                           document.getElementById("contact_result").innerHTML = "fail: "+o.responseText;
                           document.getElementById("contact_signup").innerHTML = "<img src='images/greybutton_submit.gif'>";
                        }
        }                  
                         
        document.getElementById("contact_signup").innerHTML = "<img src='images/loading_blue_small.gif'>";
        var conn = YAHOO.util.Connect.asyncRequest("POST", "./php/get_contact.php", cb, postData);
}

function showContactPanel(id) {

      var title_menu;
      var txt_msg;

      title_menu = "Contact Us";
      txt_msg    = "";

      function show_contact() {

              var randomnumber=Math.floor(Math.random()*10000);
              document.getElementById("contact_info_c").innerHTML = "<b><font size='4' color='#1C8CE2'>"+title_menu+"</font></b><br>"
                                                        + "<hr noshade style='width:580px;color:#cccccc;'></hr><br>"
                                                        + "<div style='float:left;width:50px;'>Email:</div><div style='float:left;width:230px;'><input id='contact_email' name='contact_email' type='text' size='30'></div>"
                                                        + "<div style='float:left;width:50px;'>Name:</div><div style='float:left;'><input id='contact_name' name='contact_name' type='text' size='30'></div><div style='clear:both;'></div><br>"
                                                        + "Message:<br><textarea id='contact_msg' name='contact_msg' rows='7' cols='80'>"+txt_msg+"</textarea><br><br>"
                                                        + "<div id='contact_signup' onclick='contact_func();' style='cursor:pointer;'>"
                                                        + "<img src='images/greybutton_submit.gif'></div>";

	      document.getElementById("contact_email").focus();

              function eraseContent() {
                  document.getElementById("i_contact_bg").style.opacity = "0";
                  document.getElementById("contact_info_c").innerHTML = "";
                  document.getElementById("contact_result").innerHTML = "";
              }
              function hideContact() {
                  document.getElementById("contact_info").style.visibility = "hidden";
                  document.getElementById("contact_info").style.display = "none";

   	          if (document.getElementById("CatBox") != null) {
	              document.getElementById("CatBox").style.overflowY = "auto";
  	          }	      
                 if (document.getElementById("nav_info") != null) {
                     document.getElementById("nav_info").style.visibility = "visible";
                 }
		 if (document.getElementById("flashcontent") != null) {
		     document.getElementById("flashcontent").style.visibility = "visible";
		 }
              }

          var attr_md = {
		opacity: { to: 0 },
		height : { to: 0 }
          };

          var anim_md = new YAHOO.util.Motion('c_contact_bg', attr_md, 0.5, YAHOO.util.Easing.backOut);
          anim_md.onStart.subscribe(eraseContent);
          anim_md.onComplete.subscribe(hideContact);
          YAHOO.util.Event.on(document.getElementById("exit_contact_info"),'click', anim_md.animate, anim_md, true);
      }

      function makeVisible()  {
	      function show_block() {
		 if (document.getElementById("flashcontent") != null) {
		     document.getElementById("flashcontent").style.visibility = "hidden";
		 }
		 if (document.getElementById("nav_info") != null) {
		     document.getElementById("nav_info").style.visibility = "hidden";
		 }
   	         if (document.getElementById("CatBox") != null) {
	             document.getElementById("CatBox").style.overflowY = "hidden";
  	         }	      
                 document.getElementById("contact_info").style.visibility = "visible";
                 document.getElementById("contact_info").style.display    = "block";
	      }
	      function show_shadow() {
                 document.getElementById("i_contact_bg").style.opacity    = "0.7";
	      }
              var attr_md = {
		opacity: { to: 1 },
		height : { to: 302 }
              };
	      var anim_md = new YAHOO.util.Motion('c_contact_bg', attr_md, 0.5, YAHOO.util.Easing.backOut);
	      anim_md.onStart.subscribe(show_block);
	      anim_md.onComplete.subscribe(show_shadow);
	      anim_md.animate();
      }

      var attr_md = {
          points:   {from: [parseInt(YAHOO.util.Dom.getDocumentWidth()/2)-315,230], to: [parseInt(YAHOO.util.Dom.getDocumentWidth()/2)-315,230] }
      };

      var anim_md = new YAHOO.util.Motion('contact_info', attr_md, 0.5, YAHOO.util.Easing.backOut);
      anim_md.onStart.subscribe(makeVisible);
      anim_md.onComplete.subscribe(show_contact);

      YAHOO.util.Event.on(document.getElementById("contact_menu"),'click', anim_md.animate, anim_md, true);
      if (id == 1)
          anim_md.animate();
}
YAHOO.util.Event.onAvailable("contact_menu", showContactPanel);

//------------------------------------------------------------------------------
//- MISC FUNCTIONS 
//------------------------------------------------------------------------------

function shakeWindow(n) {
        if (parent.moveBy) {
           for (i = 10; i > 0; i--) {
                for (j = n; j > 0; j--) {
                        parent.moveBy(0,i);
                        parent.moveBy(i,0);
                        parent.moveBy(0,-i);
                        parent.moveBy(-i,0);
                }
           }
        }
}

var shake_login;

function shake_cont() {
   shake_login.value--;
   shake_login.start();
}

function shake(id, v) {

   this.id    = id;
   this.value = v;

   this.start = function () {
       if (this.value < 0) return false;

       var dirX;

       if ((this.value % 2) == 1) {
          dirX = -10;
       } else {
          dirX = 10;
       }

       var attr_md = {
           points:   {to: [parseInt(YAHOO.util.Dom.getDocumentWidth()/2)-100+dirX,140] }
       }

       anim_md = new YAHOO.util.Motion("login_info", attr_md, 0.01, YAHOO.util.Easing.backOut);
       anim_md.onComplete.subscribe(shake_cont);
       anim_md.animate();
   }
}

//------------------------------------------------------------------------------
//- LOGIN FUNCTIONS 
//------------------------------------------------------------------------------

var l = new Object();
var login_dataset;

function send_email() {
   var e = document.getElementById("email_login").value;

   if (e.lastIndexOf("@") == -1) {
      document.getElementById("login_result").innerHTML = "<font color='red'>error:</font> please enter a valid email address";
      return;
   }

   var postData = "cmd=1&email="+e;
   var cb = {
                        success : function(o) {
                           document.getElementById("login_result").innerHTML = o.responseText;
                        },
                        failure : function(o) {
                           alert("fail: "+o.responseText);
                        }
   }
   var conn = YAHOO.util.Connect.asyncRequest("POST", "./php/send_email.php", cb, postData);
}

function logout_func() {
   eraseCookie('bsc_uid');
   eraseCookie('bsc_user');
   eraseCookie('bsc_access');
   eraseCookie('bsc_verf');
   window.location.reload();
}

function login_enter_func(e) {

   if (enter_pressed(e)) {
       login_func();
   }
}

function login_func() {
   var lg = document.getElementById("email_login").value;
   var ps = document.getElementById("pass_login").value;

   if (lg.lastIndexOf("@") == -1) {
      document.getElementById("login_result").innerHTML = "<font color='red'>error:</font> please enter your email to login";
          return;
   }

   if (ps.length < 1) {
      document.getElementById("login_result").innerHTML = "<font color='red'>error:</font> please enter your password";
          return;
   }

   var postData = "cmd=2&uid=-1&email_login="+lg+"&pass_login="+ps;
   var cb = {
                        success : function(o) {
                           eval("l="+o.responseText);
                           login_dataset = l['arr'];
                                if (login_dataset[0].ACCESS == -2) {
                                   shake_login = new shake("login_id", 5);
                                   shake_login.start();
                                   document.getElementById("login_result").innerHTML = "failure: sorry, no login, please signup.";
                                   document.getElementById("submit_login").innerHTML = "<img src='images/greybutton_submit.gif'>";
                                }
                                else if (login_dataset[0].ACCESS == -1) {
                                   shake_login = new shake("login_id", 5);
                                   shake_login.start();
                                   document.getElementById("login_result").innerHTML = "failure: "+login_dataset[0].FNAME+": incorrect password!";
                                   document.getElementById("submit_login").innerHTML = "<img src='images/greybutton_submit.gif'>";
                                }
                                else {
                                   createCookie('bsc_access', login_dataset[0].ACCESS, 365);
                                   createCookie('bsc_user',   login_dataset[0].FNAME+" "+login_dataset[0].LNAME, 365);
                                   createCookie('bsc_uid',    login_dataset[0].ID, 365);
                                   createCookie('bsc_verf',   login_dataset[0].VERF, 365);

				   if (win_location.match("bsc_popup.html")) {
                                       closeLoginPanel();
				       createUrlInput();
				   }
				   if (win_location.match("bsc_movwin.html")) {
                                       closeLoginPanel();
				       window.location.reload();
				   }
				   else if (win_location != "bsc_main.html") {
                                       closeLoginPanel();
				       window.location = "bsc_main.html";
				   } 
				   else {
                                       getFavTags(login_dataset[0].ID);
                                       showAccDetails();
                                       closeLoginPanel();

                                       document.getElementById("login_info_static").innerHTML = "<div style='float:left;font-weight:bold;'>"+login_dataset[0].FNAME+" "+login_dataset[0].LNAME+" &raquo; </div><div style='color:#ffffff;cursor:pointer;float:left;font-weight:bold;' id='logout_id' onclick='logout_func();'>&nbsp; logout</div>";
                                       document.getElementById("tab1").style.visibility = "visible";
                                       document.getElementById("tab2").style.visibility = "visible";
                                       document.getElementById("tab3").style.visibility = "visible";
				   }			   
                                }
                        },
                        failure : function(o) {
                                document.getElementById("login_result").innerHTML = "fail: "+o.responseText;
                            document.getElementById("submit_login").innerHTML = "<img src='images/greybutton_submit.gif'>";
                        }
        }

        document.getElementById("submit_login").innerHTML = "<img src='images/loading_blue_small.gif'>";
        var conn = YAHOO.util.Connect.asyncRequest("POST", "./php/get_login.php", cb, postData);
}

function closeLoginPanel() {
      function eraseContent() {
          document.getElementById("i_login_bg").style.opacity = "0";
          document.getElementById("login_info_c").innerHTML = "";
          document.getElementById("login_result").innerHTML = "";
      }
      function hideLoginPanel() {
          document.getElementById("login_info").style.visibility = "hidden";
          document.getElementById("login_info").style.display = "none";
      }

      var attr_md = {
	  opacity: { to: 0 },
	  height : { to: 0 }
      };

      var anim_md = new YAHOO.util.Motion('c_login_bg', attr_md, 0.5, YAHOO.util.Easing.backOut);
      anim_md.onStart.subscribe(eraseContent);
      anim_md.onComplete.subscribe(hideLoginPanel);
      anim_md.animate();
}

function showLoginPanel() {

      function show_login() {
              document.getElementById("login_info_c").innerHTML = "<b><font size='4' color='#1C8CE2'>Login</font></b><br>"
                                                        + "<hr noshade style='width:180px;color:#cccccc;'></hr>"
                                                        + "Email:<br><input id='email_login' name='email_login' type='text' size='25'><br>"
                                                        + "Password:<br><input id='pass_login' name='pass_login' type='password' size='25' onkeypress='login_enter_func(event);'><br>"
                                                        + "<a id='forgot_pass' title='<center>enter your email address, <br>and press the <b>email password</b> link above</center>' style='font-size:10px;'>for\
got password?</a> :: <a onclick='send_email();' style='font-size:10px;cursor:pointer;'>email password</a><br><br>"
                                                        + "<div id='submit_login' onclick='login_func();' style='cursor:pointer;text-align:center;'>"
                                                        + "<img src='images/greybutton_submit.gif'></div><br>"
						 	+ "<div style='font-size:11px;'>Don't have a login? then <a id='signup' style='text-decoration:underline;cursor:pointer;'>signup here</a></div>"; 
	      document.getElementById("email_login").focus();

	      showSignupPanel();

              YAHOO.example.container.tt2 = new YAHOO.widget.Tooltip("tt2", { context:"forgot_pass",zIndex:30000 });

              function eraseContent() {
                  document.getElementById("i_login_bg").style.opacity = "0";
                  document.getElementById("login_info_c").innerHTML = "";
                  document.getElementById("login_result").innerHTML = "";
              }
              function hideLoginPanel() {
                  document.getElementById("login_info").style.visibility = "hidden";
                  document.getElementById("login_info").style.display = "none";
                  if (document.getElementById("nav_info") != null) {
                      document.getElementById("nav_info").style.visibility = "visible";
                  }
		 if (document.getElementById("flashcontent") != null) {
		     document.getElementById("flashcontent").style.visibility = "visible";
		 }
              }

          var attr_md = {
		opacity: { to: 0 },
		height : { to: 0 }
          };

          var anim_md = new YAHOO.util.Motion('c_login_bg', attr_md, 0.5, YAHOO.util.Easing.backOut);
          anim_md.onStart.subscribe(eraseContent);
          anim_md.onComplete.subscribe(hideLoginPanel);
          YAHOO.util.Event.on(document.getElementById("exit_login_info"),'click', anim_md.animate, anim_md, true);
      }

      function makeVisible() {
	      function show_block() {
		 if (document.getElementById("flashcontent") != null) {
		     document.getElementById("flashcontent").style.visibility = "hidden";
		 }
                 if (document.getElementById("nav_info") != null) {
                     document.getElementById("nav_info").style.visibility = "hidden";
                 }
                 document.getElementById("login_info").style.visibility = "visible";
                 document.getElementById("login_info").style.display    = "block";
	      }
	      function show_shadow() {
                 document.getElementById("i_login_bg").style.opacity    = "0.7";
	      }
              var attr_md = {
		opacity: { to: 1 },
		height : { to: 216 }
              };
	      var anim_md = new YAHOO.util.Motion('c_login_bg', attr_md, 0.5, YAHOO.util.Easing.backOut);
	      anim_md.onStart.subscribe(show_block);
	      anim_md.onComplete.subscribe(show_shadow);
	      anim_md.animate();
      }

      var anim_md;
      var attr_md = {
             points:   {from: [parseInt(YAHOO.util.Dom.getDocumentWidth()/2)-100,230], to: [parseInt(YAHOO.util.Dom.getDocumentWidth()/2)-100,230] }
      };
      anim_md = new YAHOO.util.Motion('login_info', attr_md, 0.5, YAHOO.util.Easing.backOut);
      anim_md.onStart.subscribe(makeVisible);
      anim_md.onComplete.subscribe(show_login);
      YAHOO.util.Event.on(document.getElementById("login"),'click', anim_md.animate, anim_md, true);
}

YAHOO.util.Event.onAvailable("login", showLoginPanel);

//------------------------------------------------------------------------------
//- SIGNUP PANEL CONTROL
//------------------------------------------------------------------------------

function signup_enter_func(e) {

   if (enter_pressed(e)) {
       signup_func();
   }
}

function signup_func(rn) {
   var em = document.getElementById("signup_email").value;
   var fn = document.getElementById("signup_fname").value;
   var ln = document.getElementById("signup_lname").value;
   var pr = document.getElementById("signup_prof").value;
   var pa = document.getElementById("signup_pass").value;
   var re = document.getElementById("signup_repass").value;
   var ve = document.getElementById("signup_verf").value;
   var rt = document.getElementById("rd_tos").checked;

   if (em.lastIndexOf("@") == -1) {
      document.getElementById("signup_result").innerHTML = "<font color='red'>error:</font> please enter a valid email address";
          return;
   }
   if (fn.length < 1) {
      document.getElementById("signup_result").innerHTML = "<font color='red'>error:</font> please enter a valid firstname";
          return;
   }
   if (ln.length < 1) {
      document.getElementById("signup_result").innerHTML = "<font color='red'>error:</font> please enter a valid lastname";
          return;
   }
   if (pr.length < 1) {
      document.getElementById("signup_result").innerHTML = "<font color='red'>error:</font> please enter a valid profession";
          return;
   }
   if (pa.length < 1) {
      document.getElementById("signup_result").innerHTML = "<font color='red'>error:</font> please enter a valid password";
          return;
   }
   if (pa != re) {
      document.getElementById("signup_result").innerHTML = "<font color='red'>error:</font> passwords should match";
          return;
   }
   if (ve != rn) {
      document.getElementById("signup_result").innerHTML = "<font color='red'>error:</font> verification code does not match";
          return;
   }
   if (rt == false) {
      document.getElementById("signup_result").innerHTML = "<font color='red'>error:</font> please read & check the terms of use checkbox";
          return;
   }

   var binfo = BrowserDetect.browser+" / version: "+BrowserDetect.version +" / on: "+BrowserDetect.OS;
   var postData = "signup_email="+em+"&signup_fname="+fn+"&signup_lname="+ln+"&signup_prof="+pr+"&signup_pass="+pa+"&signup_verf="+ve+"&binfo="+binfo;

   var cb = {
                        success : function(o) {
                           document.getElementById("signup_result").innerHTML = "<font color='green'>success:</font>  "+o.responseText;
                           document.getElementById("submit_signup").innerHTML = "<img src='images/greybutton_submit.gif'>";
                        },
                        failure : function(o) {
                           document.getElementById("signup_result").innerHTML = "fail: "+o.responseText;
                           document.getElementById("submit_signup").innerHTML = "<img src='images/greybutton_submit.gif'>";
                        }
        }

        document.getElementById("submit_signup").innerHTML = "<img src='images/loading_blue_small.gif'>";
        var conn = YAHOO.util.Connect.asyncRequest("POST", "./php/get_signup.php", cb, postData);
}

function showSignupPanel() {

      function show_signup() {
              var randomnumber=Math.floor(Math.random()*1000000);
              document.getElementById("signup_info_c").innerHTML = "<b><font size='4' color='#1C8CE2'>Signup</font></b><br>"
                                                        + "<hr noshade style='width:280px;color:#cccccc;'></hr>"
                                                        + "Email:<br><input id='signup_email' name='signup_email' type='text' size='30'><br>"
                                                        + "First Name:<br><input id='signup_fname' name='signup_name' type='text' size='30'><br>"
                                                        + "Last Name:<br><input id='signup_lname' name='signup_name' type='text' size='30'><br>"
                                                        + "Profession:<br><input id='signup_prof' name='signup_prof' type='text' size='30'><br>"
                                                        + "Password:<br><input id='signup_pass' name='signup_pass' type='password' size='30'><br>"
                                                        + "Re-type Password:<br><input id='signup_repass' name='signup_repass' type='password' size='30'><br>"
                                                        + "Type Verification Code: "+randomnumber+"<br>"
                                                        + "<input id='signup_verf' name='signup_verf' type='text' size='30' onkeypress='signup_enter_func(event);'><br>"
                                                        + "<div style='position:relative;margin-top:4px;margin-left:90px;'>"
                                                        + "<div style='float:left;'><input id='rd_tos' type='checkbox' style='border:0px;'></div><div style='float:left;margin-top:2px;margin-left:5px;'>I accept the <a style='text-decoration:underline;' href='bsc_tos.html' target='_new'>terms of use</a></div><div style='clear:both;'></div></div>";

	     if (BrowserDetect.browser != "Explorer") 
		 document.getElementById("signup_info_c").innerHTML += "<br>";

	     document.getElementById("signup_info_c").innerHTML += "<div id='submit_signup' onclick='signup_func("+randomnumber+");' style='cursor:pointer;z-index:20000;'>"
                                                        	+ "<img src='images/greybutton_submit.gif'></div>";
	      document.getElementById("signup_email").focus();

              function eraseContent() {
                  document.getElementById("i_signup_bg").style.opacity = "0";
                  document.getElementById("signup_info_c").innerHTML = "";
                  document.getElementById("signup_result").innerHTML = "";
              }
              function hideSignup() {
                  document.getElementById("signup_info").style.visibility = "hidden";
                  document.getElementById("signup_info").style.display = "none";
                 if (document.getElementById("nav_info") != null) {
                     document.getElementById("nav_info").style.visibility = "visible";
                 }
		 if (document.getElementById("flashcontent") != null) {
		     document.getElementById("flashcontent").style.visibility = "visible";
		 }
              }

          var attr_md = {
		opacity: { to: 0 },
		height : { to: 0 }
          };

          var anim_md = new YAHOO.util.Motion('c_signup_bg', attr_md, 0.5, YAHOO.util.Easing.backOut);
          anim_md.onStart.subscribe(eraseContent);
          anim_md.onComplete.subscribe(hideSignup);
          YAHOO.util.Event.on(document.getElementById("exit_signup_info"),'click', anim_md.animate, anim_md, true);
      }

      function makeVisible() {
	      function show_block() {
                 closeLoginPanel();
		 if (document.getElementById("flashcontent") != null) {
		     document.getElementById("flashcontent").style.visibility = "hidden";
		 }
                 if (document.getElementById("nav_info") != null) {
                     document.getElementById("nav_info").style.visibility = "hidden";
                 }

                 document.getElementById("signup_info").style.visibility = "visible";
                 document.getElementById("signup_info").style.display    = "block";
	      }
	      function show_shadow() {
                 document.getElementById("i_signup_bg").style.opacity    = "0.7";
	      }
              var attr_md = {
		opacity: { to: 1 },
		height : { to: 347 }
              };
	      var anim_md = new YAHOO.util.Motion('c_signup_bg', attr_md, 0.5, YAHOO.util.Easing.backOut);
	      anim_md.onStart.subscribe(show_block);
	      anim_md.onComplete.subscribe(show_shadow);
	      anim_md.animate();
      }

      var attr_md = {
          points:   {from: [parseInt(YAHOO.util.Dom.getDocumentWidth()/2)-150,230], to: [parseInt(YAHOO.util.Dom.getDocumentWidth()/2)-150,230] }
      };

      var anim_md = new YAHOO.util.Motion('signup_info', attr_md, 0.5, YAHOO.util.Easing.backOut);
      anim_md.onStart.subscribe(makeVisible);
      anim_md.onComplete.subscribe(show_signup);

      YAHOO.util.Event.on(document.getElementById("signup"),'click', anim_md.animate, anim_md, true);
}

//------------------------------------------------------------------------------
//- HORIZONTAL SCROLLER FOR TOP OF CHARTS
//------------------------------------------------------------------------------

YAHOO.example.top_charts = function() {

                var $D  = YAHOO.util.Dom;
                var $E  = YAHOO.util.Event;
                var $A  = YAHOO.util.Anim;
                var $M  = YAHOO.util.Motion;
                var $DD = YAHOO.util.DD;
                var $   = $D.get;
                var x   = 1;

                return {
                        init : function() {
                                $E.on(['move-left','move-right'], 'click', this.move);
                        },

                        move : function(e) {
                                $E.stopEvent(e);
                                switch(this.id) {
                                        case 'move-left':
                                                if ( x === 1 ) {
                                                        return;
                                                }
                                                var attributes = {
                                                        points : {
                                                                by : [700, 0]
                                                        }
                                                };
                                                x--;
                                        break;
                                        case 'move-right':
                                                if ( x === 3 ) {
                                                        return;
                                                }
                                                var attributes = {
                                                        points : {
                                                                by : [-700, 0]
                                                        }
                                                };
                                                x++;
                                        break;
                                };
                                var anim = new $M('tcharts_themes', attributes, 0.5, YAHOO.util.Easing.easeOut);
                                anim.animate();
                        }
                };
        }();
