jQuery.fn.placeholder = function( settings ) {
  // jQuery(this) will need the following markup to work properly:
  // <input type="text" placeholder="<PLACEHOLDER_TEXT>" value="<PLACEHOLDER_TEXT>" />
  var $this = jQuery(this);
  
  // Defaults and override
  var defaults = {
      msg: $this.val(),
      defaultClass: 'defaultInput'
  };
  settings = jQuery.extend(defaults, settings);
  
  // Placeholder feature detection
  if (!Modernizr.input.placeholder) {
    
    // Init events
    $this.focus(function(){
        if( $this.val()==settings.msg ) $this.removeClass( settings.defaultClass ).val( '' );
    });
    $this.blur(function(){
        if( jQuery.trim( $this.val() ) == '' ) $this.addClass( settings.defaultClass ).val( settings.msg );
    });
    
    // Add default class if the val is equal to the default
    if( $this.val()===settings.msg ) $this.addClass( settings.defaultClass );
  
  } else {
    // If we can use HTML5 placeholder, then we can clear the value attribute (if it's set to the default)
    if( $this.val()===settings.msg ) $this.removeAttr('value');
  }

  return $this;
};

var site = {
  
  /** Logic to retrieve a cookie for the site **/
  getCookie: function(name) {
    var pattern = new RegExp('(^|; )' + name + '=([^;]*)');
    var m = document.cookie.match(pattern);
    return m && unescape(m[2]);
  },
  
  /** Logic to create a cookie for the site **/
  setCookie: function(name, value, days, path, domain, secure) {
    var c = name + '=' + escape(value);
    var expires = null;
    if (days)
      expires = new Date(new Date().getTime() + (days * 24 * 60 * 60 * 1000));
    if (expires)
      c += '; expires=' + expires.toUTCString();
    if (path)
      c += '; path=' + path;
    if (domain)
      c += '; domain=' + domain;
    if (secure)
      c += '; secure';
    document.cookie = c;
    return "woo";
  },
  
  parseUri: function(str) {
    if (str == null) {
      str = window.location.href;
    }
    var o = {
      strictMode: false,
      key: ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"],
      q: {
        name: "queryKey",
        parser: /(?:^|&)([^&=]*)=?([^&]*)/g
      },
      parser: {
        strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
        loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
      }
    },
    m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
    uri = {},
    i = 14;

    while (i--) uri[o.key[i]] = m[i] || "";

    uri[o.q.name] = {};
    uri[o.key[12]].replace(o.q.parser, function($0, $1, $2) {
      if ($1) uri[o.q.name][$1] = $2;
    });

    return uri;
  }
  
};

jq$(document).ready(function(){
  
  jq$(".large-image").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});

  jq$('body').append(jq$('<div />', {
    id : 'dialog-external',
    text : 'The link you have selected will take you away from this site to one that is not owned or controlled by Genentech, Inc. Genentech, Inc. makes no representation as to the accuracy of the information contained on sites we do not own or control. Genentech does not recommend and does not endorse the content on any third-party websites. Your use of third-party websites is at your own risk and subject to the terms and conditions of use for such sites.'
  }));
  
  jq$('body').append(jq$('<div />', {
    id : 'dialog-products',
    text : 'The link you have selected will take you to the BioOncology Approved Products site.'
  }));

  jq$('#dialog-external, #dialog-products').dialog({
    title : 'Biooncology.com',
    autoOpen : false,
    minHeight: 0,
    height: 'auto',
    width: 350,
    resizable: false,
    position: 'center'
  });
  
  function openDialog(id, $this) {
    var theHREF = $this.attr("href");

    jq$(id).dialog('option', 'buttons', {
      "Proceed" : function() {
        window.location.href = theHREF;
      },
      "Cancel" : function() {
        jq$(this).dialog("close");
      }
    });

    jq$(id).dialog("open");
  }

  jq$('.third-party').click(function() {
    openDialog('#dialog-external', jq$(this));
    return false;
  });
  
  jq$('.products-link').click(function() {
    openDialog('#dialog-products', jq$(this));
    return false;
  });

	jq$("#content-body .right-content table tr:even td").addClass('alt');
  
});

