jQuery.noConflict();

jQuery(document).ready(function () {
  jQuery('#newsletter').focus(function (){
     if(jQuery(this).val()=="Your Email Address"){
       jQuery(this).val('');
       jQuery(this).css('color','#ffffff');
       jQuery('#newsbutton').fadeIn();
       jQuery('#ty').fadeOut();
     }
  });
  jQuery('#newsletter').blur(function (){
     if(jQuery(this).val()==""){
       jQuery(this).val('Your Email Address');
       jQuery(this).css('color','#848484');
       jQuery('#newsbutton').fadeOut();
     }
  });
  
  
  if(document.getElementById('homebanner')){
    loadBannerLinks(-1);
  }
  
  if ((document.getElementById("videocontainer") && window.location!="http://www.matterco.com/category/features") || (document.getElementById("videocontainer") && window.location!="http://matterco.com/category/features")) {
    document.getElementById("videocontainer").innerHTML = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="320" height="255" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="bgcolor" value="#000000"> <param name="src" value="http://www.matterco.com/wp-content/uploads/Matter_Open_House.mov"></param><param name="autoplay" value="true"></param><param name="controller" value="true"></param><param name="loop" value="false"></param><param name="cache" value="true"></param><embed src="http://www.matterco.com/wp-content/uploads/Matter_Open_House.mov" width="320" height="255" autoplay="true" controller="true" loop="false" cache="true" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>';
    document.getElementsByTagName("img")[0].focus();
  } else if(document.getElementById("videocontainer")) {
    document.getElementById("videotext").style.display = "none";
    document.getElementById("videocontainer").style.display = "none";
  }
  
  if(document.getElementById('closeformlink')){
    document.getElementById('closeformlink').onclick = function(){
      if(window.parent.document.getElementById('openform').innerHTML=='Close the contact form'){
        fireEvent(window.parent.document.getElementById("openform"),'click');
      }else{
        fireEvent(window.parent.document.getElementById("openform"),'click');
      }
    }
  }
  
  if(document.getElementById('sub_banner')){
    document.getElementById('sub_banner').onclick = function(){
      if(document.getElementById('sub_banner').getAttribute('title')=='Click to Open'){ 
        document.getElementById('sub_banner').getElementsByTagName('div')[0].setAttribute('style','background-position:-980px top;');
        document.getElementById('sub_banner').setAttribute('title','Click to Close');
      }else{
        document.getElementById('sub_banner').getElementsByTagName('div')[0].setAttribute('style','');
        document.getElementById('sub_banner').setAttribute('title','Click to Open');
      }
    }
  }
  
  jQuery('#opencontact,#openinline,#openform').click(function (){
    if(window.frames[0].document.getElementById('wpcf_your_name')){
        var openLink  = jQuery(this);
        var oInline   = document.getElementById("openinline");
        var oContact  = document.getElementById("opencontact");
        var oForm   = document.getElementById("openform");
        var formname  = window.frames[0].document.getElementById('wpcf_your_name');
        var formemail = window.frames[0].document.getElementById('wpcf_email');
        var formsubject = window.frames[0].document.getElementById('wpcf_subject');
        var formmessage = window.frames[0].document.getElementById('wpcf_msg');
        var cform   = window.frames[0].document.getElementById('c_form_2');
        var cbutton   = window.frames[0].document.getElementById('contactsubmit');
        var ciframe   = window.frames[0].document.getElementById('contactiframe');
    
        if(document.getElementById("banner_title_project") || document.getElementById("feature-banner") || document.getElementById("project_title")){window.scrollTo(0,50000);}
        
        if (jQuery(this).html() == "Open the contact form") {
          new Effect.Parallel([
          new Effect.Move('contactdiv', {
            x: 0,
            y: -415,
            mode: 'absolute',
            transition: Effect.Transitions.sinoidal
          }), new Effect.Morph('contactdiv', {
            style: 'width:640px;',
            duration: 0.7
          }), new Effect.Morph('contactiframe', {
            style: 'width:640px;',
            duration: 0.7
          }), new Effect.Morph(formname, {
            style: 'width:244px;',
            duration: 1
          }), new Effect.Morph(formemail, {
            style: 'width:244px;',
            duration: 1
          }), new Effect.Morph(formsubject, {
            style: 'width:244px;',
            duration: 1
          }), new Effect.Morph(formmessage, {
            style: 'width:244px;',
            duration: 1
          }), new Effect.Morph(cbutton, {
            style: 'width:98px;',
            duration: 1
          })
        ]);
    
        openLink.innerHTML = "Close the contact form";
        
        if(oInline){
          oInline.innerHTML = "Close the contact form";
        }
        if(oContact){
          oContact.innerHTML = "Close the contact form";
        }
        if(oForm){
          oForm.innerHTML = "Close the contact form";
        }
      }
      else {
        new Effect.Parallel([
            new Effect.Move('contactdiv', {
            x: 640,
            y: -415,
            mode: 'absolute',
            transition: Effect.Transitions.sinoidal
          }),new Effect.Morph('contactdiv', {
            style: 'width:210px;',
            duration: 0.6
          }), new Effect.Morph('contactiframe', {
            style: 'width:210px;',
            duration: 0.6
          }), new Effect.Morph(formname, {
            style: 'width:10px;',
            duration: 0.6
          }), new Effect.Morph(formemail, {
            style: 'width:10px;',
            duration: 0.6
          }), new Effect.Morph(formsubject, {
            style: 'width:10px;',
            duration: 0.6
          }), new Effect.Morph(formmessage, {
            style: 'width:10px;',
            duration: 0.6
          }), new Effect.Morph(cbutton, {
            style: 'width:1px;',
            duration: 0.6
          })
        ]);
        
        openLink.innerHTML = "Open the contact form";
        
        if(oInline){
          oInline.innerHTML = "Open the contact form";
        }
        if(oContact){
          oContact.innerHTML = "Open the contact form";
        }
        if(oForm){
          oForm.innerHTML = "Open the contact form";
        }
      }
      return false;  
    }else{
      var openLink  = jQuery(this);
      var oInline   = document.getElementById("openinline");
      var oContact  = document.getElementById("opencontact");
      var oForm     = document.getElementById("openform");
        
      if (jQuery(this).html() == "Open the contact form") {
          new Effect.Parallel([
          new Effect.Move('contactdiv', {
            x: 0,
            y: -415,
            mode: 'absolute',
            transition: Effect.Transitions.sinoidal
          }), new Effect.Morph('contactdiv', {
            style: 'width:640px;',
            duration: 0.7
          }), new Effect.Morph('contactiframe', {
            style: 'width:640px;',
            duration: 0.7
          })
        ]);
    
        openLink.innerHTML = "Close the contact form";
        
        if(oInline){
          oInline.innerHTML = "Close the contact form";
        }
        if(oContact){
          oContact.innerHTML = "Close the contact form";
        }
        if(oForm){
          oForm.innerHTML = "Close the contact form";
        }
      }
      else {
        new Effect.Parallel([
            new Effect.Move('contactdiv', {
            x: 640,
            y: -415,
            mode: 'absolute',
            transition: Effect.Transitions.sinoidal
          }),new Effect.Morph('contactdiv', {
            style: 'width:210px;',
            duration: 0.6
          }), new Effect.Morph('contactiframe', {
            style: 'width:210px;',
            duration: 0.6
          })
        ]);
        
        openLink.innerHTML = "Open the contact form";
        
        if(oInline){
          oInline.innerHTML = "Open the contact form";
        }
        if(oContact){
          oContact.innerHTML = "Open the contact form";
        }
        if(oForm){
          oForm.innerHTML = "Open the contact form";
        }
      }
      return false;  
    }
  });
});

var activeBanner;
var activeText;
var homeBanner= new Array();
homeBanner[0] = new Array("home0", "Innovation is Dead.", "hometext0");

function loadBannerLinks(active){
  var content = new Array();
  content[0]  = homeBanner[0];
  
  var span0   = document.getElementById("homebanner").getElementsByTagName("span")[0].getElementsByTagName("em")[0];
  var span1   = document.getElementById("homebanner").getElementsByTagName("span")[1].getElementsByTagName("em")[0];
  
  if(active==-1){ 
    active = Math.floor(Math.random()*content.length);
    new Effect.Parallel([
      new Effect.Appear(content[active][0],{sync: true}),
      new Effect.Appear(content[active][2],{sync: true})
    ]);
  }
}

function bannerLinks(which){
  for(j=0;j<homeBanner.length;j++){
    if(document.getElementById(which).getElementsByTagName("em")[0].innerHTML == homeBanner[j][1]){
      new Effect.Parallel([
        new Effect.Fade(activeBanner,{sync: true}),
        new Effect.Fade(activeText,{sync: true})    
      ]);
      new Effect.Parallel([
        new Effect.Appear(homeBanner[j][0],{sync: true}),
        new Effect.Appear(homeBanner[j][2],{sync: true})  
      ]);
      loadBannerLinks(j);
      break;
    }
  }
}

function fireEvent(obj,evt){
  var fireOnThis = obj;
  if( document.createEvent ) {
    var evObj = document.createEvent('MouseEvents');
    evObj.initEvent( evt, true, false );
    fireOnThis.dispatchEvent(evObj);
  } else if( document.createEventObject ) {
    fireOnThis.fireEvent('on'+evt);
  }
}

function validate(form_id,email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) {
      jQuery('#ee').fadeIn();
      return false;
   }else{
     jQuery('#ee').fadeOut();
     jQuery('#newsletter').css('color','#848484');
     jQuery('#newsbutton').fadeOut();
     jQuery('#ty').fadeIn();
   }
}