/**
 * the_script.js
 * Miscellaneous scripts.
 *
 * @author  Ray McNeill ( http://mcneill.cc/contact/ )
 * @package mcneill.cc mmxi
 * @since   11.0414
 * @version 11.0414
 */

/**
 * fail() : adapted/hijacked from twitter's bust();
 * Frameless,... please.
 */
  var fail = function() {
		document.write = "";
		window.top.location = window.self.location;
		setTimeout( function() { 
		  document.body.innerHTML = ''; 
		}, 0 );
		window.self.onload = function( evt ) { 
		  document.body.innerHTML = ''; 
		};
	  };
	  
	  if ( window.top !== window.self ) {
		try {
		  if ( window.top.location.host ) {
			
		  } else {
			fail();
		  }
		} catch ( ex ) {
		  fail();
		}
	  }

/**
 * externalLinks
 */
  var externalLinks = function() {
		var anchors = document.getElementsByTagName( 'a' );
		  for ( var i = 0; i < anchors.length; i++ ) {
			if ( anchors[i].getAttribute( 'href' ) && anchors[i].getAttribute( 'rel' ) == 'external' ) anchors[i].target = '_blank';
		  }
		};

/**
 * genPasswd
 */
  var genPasswd = function( objForm ) {
		var blnGen       = true;
		var objMaster    = objForm.master;
		var objMasterChk = objForm.masterchk;
		var objSite      = objForm.site;
		var objPasswd    = objForm.password;

		  if ( objMaster.value == '' ) {
			blnGen = false;
			alert( 'A master password must be provided.' );
			objMaster.focus();
			return( false );
			}
		  if ( !( objMaster.value == objMasterChk.value ) ) {
			blnGen = false;
			alert( 'Master passwords don\'t match.' );
			objMasterChk.focus();
			return( false );
			}
		  if (objSite.value == "") {
			blnGen = false;
			alert( 'You must distinguish your password with an associated site.' );
			objSite.focus();
			return( false );
			}
		  if ( blnGen ) {
			objPasswd.value = hex_md5(objMaster.value + ':' + objSite.value).substr(0,12);
			objPasswd.focus();
			objPasswd.select();
			return( false );
			}
		};

/**
 * Image preloader. http://goo.gl/8Cc4o
 */
  ( function( $ ) {
	 var cache = [];
	 // Arguments are image paths relative to the current page.
	 $.preLoadImages = function() {
	  var args_len = arguments.length;
	  for ( var i = args_len; i--; ) {
		var cacheImage = document.createElement( 'img' );
		cacheImage.src = arguments[i];
		cache.push( cacheImage );
	  }
	}
  })( jQuery );

/**
 * The script stuff.
 */
	$( document ).ready( function() {
		/**
		 * Build link targets.
		 */
			externalLinks();

		/**
		 * Contact link.
		 */
			var arr     = [ 'fast_junkie', 'mailto:', '@', 'mcneill.cc' ];
			var $hidden = $( '#hidden' );
				if ( $hidden.length != 0 ) {
					$hidden.empty();
					$( '<a>' ).attr(
						{
							'href': arr[1] + arr[0] + arr[2] + arr[3],
							'title': 'You MUST put the word [ Fixx ] somewhere within the subject line.'
						}
					).appendTo( $hidden ).html( arr[0] + arr[2] + arr[3] );
				}

		/**
		 * If class exists, stripe.
		 */
			var $stripe = '.stripe';
				if ( $( $stripe ).length != 0 ) {
					$( 'ul' + $stripe + ' li:odd,  table' + $stripe + ' tbody tr:odd' ).addClass( 'odd' );
					$( 'ul' + $stripe + ' li:even, table' + $stripe + ' tbody tr:even' ).addClass( 'even' );
				}
	});
