var TOPIFY = {};

TOPIFY.menu = (function(){

  var panels;

  return {
    init: function() {
      $('#side-menu').bind('mouseover', function(e){
        if (!panels) {
          panels = $('#side-content');
        }
        var el = $(e.target);
        if (!el.is('a')) return;
        el = el.parent();
        el.addClass('selected').siblings().removeClass('selected');
        panels.children('div').eq(el.prevAll().length)
          .show()
          .siblings().hide();
        return false;
      });
	  $('#side-menu').bind('click', function(e){
		return false;
	  });
    }
  };
})();


jQuery.fn.extend({
  hcenter: (function(){
    if (!jQuery.browser.msie) return function() {return this;};
    return function() {
      var center = Math.abs($(window).width()/2);
      return this.each(function () {
        var elem = $(this);
        elem.css({left: center - elem.width()/2});
      });
    };
  })(),

  vcenter: function() {
    return this.each(function () {
      $(this).css('top', $(window).scrollTop()+50);
    });
  },

  toggleVal: function(maskClass) {
    maskClass = maskClass || 'light';
  	return this.each(function() {
  	  var $this = $(this);
	  
  	  var defaultValue = $.data(this, 'toggleVal', $this.val());
  	  $this
  	    .addClass(maskClass)
  		  .focus(function() {
    			// clear value if current value is the default or maskclass active
    			if($(this).hasClass(maskClass)){
    			  defaultValue = $.data(this, 'toggleVal', $this.val());
    			  $(this).val('');
    			};
    			$(this).removeClass(maskClass);
  		  })
  		  .blur(function() {
  			  // restore to the default value if current value is empty
    			if($(this).val() == "") {
    			  $(this).addClass(maskClass).val(defaultValue);
    			}
  		});
  	});
  }
});

$("#password").focus(
        function()
        {
            if($(this).val().length > 0)
            {
                removeBackgroundFromPassword();
            }
        });

$("#email").keypress (
	function ()
	{
		$("#email_confirm_div").removeClass ('hidden');
//		$("#email_confirm").addClass ('input-error');
	});


	
$("#email_confirm").change (
	function () 
	{
		email_confirm();
	});

function email_confirm () {
	if ($("#email_confirm").val() != $("#email").val()) 
	{
		$("#email_confirm").addClass ('input-error');
		$("#email").addClass ('input-error');
	} 
	else 
	{
		$("#email_confirm").removeClass ('input-error');
		$("#email").removeClass ('input-error');			
	}	
}    

$("#password").keypress(
    function()
    {
        removeBackgroundFromPassword();
    });
        
$("#password").blur(
    function()
    {
        if($(this).val().length == 0)
        {
            addBackgroundToPassword();
        }
    });

function addBackgroundToPassword()
{
    var password = $("#password");

    if(password.hasClass("withoutBackground"))
    {
        password.addClass("password_background").removeClass("withoutBackground");
    }
}

function removeBackgroundFromPassword()
{
    var password = $("#password");

    if(password.hasClass("password_background"))
    {
        password.addClass("withoutBackground").removeClass("password_background");
    }
}

TOPIFY.overlay = (function(){

  var bg;

  function show(onClose, blocking) {
    bg
      .one('mousedown.overlay', function(e) {
        if (blocking) return;
        onClose && onClose();
        bg.hide();
      })
    .show();
  };

  return {
    show: function () {
      if (!bg) {
        bg = $('<div id="overlay"></div>')
          .css({
            top: 0,
            height: $(document).height(),
            dislay: 'none'
          })
          .appendTo('body');
      }
      TOPIFY.overlay.show = show;
      show.apply(null, arguments);
    },

    hide: function () {
      bg.hide();
    }
  };

})();


$(function(){

  TOPIFY.menu.init();

  var video;
  /*$('#watch-video').bind('click', function(e){
    if (!video) {	
      video = $('<div id="reg-video">'
        +'<a class="close" href="">close</a>'
        //+'<object height="323" width="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" data="http://www.screentoaster.com/swf/STPlayer.swf" type="application/x-shockwave-flash" wmode="transparent" id="stUExQRU1IR1paQ1ReWlldVlZQ"><param value="http://www.screentoaster.com/swf/STPlayer.swf" name="movie"/><param value="true" name="allowFullScreen"/><param value="always" name="allowScriptAccess"/><param value="video=stUExQRU1IR1paQ1ReWlldVlZQ" name="flashvars"/><param value="transparent" name="wmode"/></object>'
		+'<div style="width:600px;height:543px;"><object width="600" height="543"><param name="movie" value="http://embedr.com/swf/slider/topify-better-twitter-email-notifications/600/543/0x7e858c/true/wide"></param><param name="allowFullScreen" value="true"></param><param name="wmode" value="transparent"><embed src="http://embedr.com/swf/slider/topify-better-twitter-email-notifications/600/543/0x7e858c/true/wide" type="application/x-shockwave-flash" allowFullScreen="true" width="600" height="543" wmode="transparent"></embed></object><a href="http://embedr.com/playlist/topify-better-twitter-email-notifications" target="_blank" style="background:transparent url(http://embedr.com/img/embedr-custom-video-playlists.gif);float:right;margin:0;padding:0;outline:none;width:115px;height:35px;position:relative;top:-35px;"><span style="display:none;">Build your own custom video playlist at embedr.com</span></a></div>'
		+'</div>')
        .appendTo(document.body)
        .children('.close').bind('click', function(e){
          video.hide();
          TOPIFY.overlay.hide();
          return false;
        })
      .end();
    }
    video
      .vcenter()
      .hcenter()
      .show();

    TOPIFY.overlay.show(function() {
      video.hide();
    });
    return false;
  });*/

  $('#beta-form input').toggleVal();
});

$(document).ready(function() { 
	// var s = document.createElement('style');
	// s.type = "text/css";
	// document.getElementsByTagName('head')[0].appendChild(s);
	// s.innerHTML = ".stico_default {background-position: right 0 !important;}";
	var css =  ".stico_default {background-position: right 0 !important;}";

	var style = document.createElement('style');
	document.getElementsByTagName('head')[0].appendChild(style);

	if(!window.ActiveXObject) {
	 document.styleSheets[document.styleSheets.length-1].cssText = css;
	} else {
	 var styleTxt = document.createTextNode(css);
	 style.appendChild(styleTxt);
	}
});