/**
 * minitabs (jQuery plugin)
 * Nizam Sayeed (nizam@nomadjourney.com)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php) 
 *
 * Version: 1.0
 * Requires: jQuery 1.2.6+
 * 
 * Based on simpleTabs (http://supercanard.phpnet.org/jquery-test/simpleTabs/)
 * Originally developed by: Jonathan Coulet (j.coulet@gmail.com)
 *
 * Example:
 *
 *     $( '#myTabs' ).minitabs({
 *         first: '#minitabFoo',
 *         callback: myFunc,
 *         speed: 'slow'
 *     });
 *
 **/
(function( $ ) {
	
	$.fn.minitabs = function( opt ) {
		var options = jQuery.extend( {
			first: '',            // id of first tab to activate
			callback: null,       // callback function when a tab is switched
			speed: 'fast'         // transition effect speed
		}, opt );

		$( this ).each( function() {
			var tabContainer = '#' + this.id;
			hideAll();

			// if first tab id is not provided, try to guess
			if( options.first == '' ) {
				var first = $( this ).children( 'div.minitabsNav' ).children( 
					'ul' ).children( 'li' )[ 0 ];
				options.first = '#' + $( first ).attr( 'id' );
			}
			changeTab( options.first );
			
			// hide all tab content divs
			function hideAll() {
				$( tabContainer + ' .minitabsContent' ).hide();
			}
			
			// change active tab
			function changeTab( tabId ) {
				//alert(tabId);
				y = '#'+tabId.split('#a')[1]
				hideAll();
				$( tabContainer + ' .minitabsNav li' ).removeClass( 'active' );
				$( tabContainer + ' .minitabsNav ' + y ).addClass( 'active' );
				$( tabContainer + ' div.minitabsContent' + y ).fadeIn( options.speed );
				if( $.isFunction( options.callback ) ) {
					options.callback.apply();
				}
			}

			// attach tab click event
			$( tabContainer + ' .minitabsNav li' ).click( function() {
				changeTab( '#' + this.id );				
				if(this.id == 'aid_bio'){
				the_url = window.location.href.split('?');
				window.location.hash = 'bio';
				}
				if(this.id == 'aid_photo'){
					the_url = window.location.href.split('?');
					window.location.hash = 'photo';
				}
				if(this.id == 'aid_video'){
					the_url = window.location.href.split('?');
					window.location.hash = 'video';
				}
			});
			
			the_url = window.location.href.split('#');			
			if(the_url[1]== 'video'){
				hideAll();
				changeTab('#aid_video');
			}
			if(the_url[1]== 'photo'){
				hideAll();
				changeTab('#aid_photo');
			}
			if(the_url[1]== 'bio'){
				hideAll();
				changeTab('#aid_bio');
			}
			
		});
	}
})( jQuery );



function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ){
	var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
	var aQueryString = strQueryString.split("&");
	for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
	var aParam = aQueryString[iParam].split("=");
	strReturn = aParam[1];
	break;
	}
	}
	}
	return strReturn;
}

