jQuery(document).ready(function($) {

	if (jQuery.browser.msie) { 
		//$('.slider_get_card').css({background: "#fff", opacity: '0'});
		
	  	if(parseInt(jQuery.browser.version) == 6) { 
	  } 
	}
	
	/*
	$('.jscroll').jScrollPane({
		scrollbarWidth: 10,
		scrollbarMargin: 0,
		showArrows: false
	});
	*/
	$('#story #sidebar .jscroll').jScrollPane({
		scrollbarWidth: 0,
		scrollbarMargin: 0,
		showArrows: true
	});
	
	$('.jscroll').not('#story #sidebar .jscroll').jScrollPane({
		scrollbarWidth: 0,
		scrollbarMargin: 0,
		showArrows: true
	});
	
	$('.gallery_content_div .wrapper').jScrollPane({
		scrollbarWidth: 0,
		scrollbarMargin: 0,
		showArrows: true
	});
	
	flashembed('video1', 'http://gardnermohr.com/wp-content/themes/gardner2/includes/GM_HomepageAndWorkPage.swf');
	flashembed('video2', 'http://gardnermohr.com/wp-content/themes/gardner2/includes/GM_Workpage.swf');
	flashembed('video3', 'http://gardnermohr.com/wp-content/themes/gardner2/includes/GM_Story.swf');

	
	reinitialiseScrollPane = function()
	{
		$('.jscroll').jScrollPane({
			scrollbarWidth: 0,
			scrollbarMargin: 0,
			showArrows: false
		});
	}
	
	$(function(){
		$('#globalnav li').each(function(){
			var spanit = $(this).find('a').text();
			
			$(this).find('a').html('<span>'+spanit+'</span>');
		});
	
	});

	
//	$('.accordion h2:first-child').addClass('current');
//	$('.accordion div.wrapper').each(function(){ $(this).find('div.pane:first').css({display: "block"}); });
	$(".accordion").tabs(".accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: null});
	$('.accordion h2.current').next('.pane').css({display: "block"});

	$('.gallery_content_div').fadeOut('fast');

	$('.show_gallery_content').click(function(){
		if($('.gallery_content_div').is(':visible')) {
			$('.show_gallery_content span').text('+ Project Description');
			$('.gallery_content_div').fadeOut('fast');
			
		} else {
			$('.gallery_content_div').css({bottom: '0px'});
			var imgWidth = $('.gallery_image img').width();
			if(imgWidth > $('.gallery_image').width()) {
				imgWidth = $('.gallery_image').width();
			}
			$('.show_gallery_content span').text('- Close');
			
		//	$('.gallery_content_div').width(imgWidth).fadeIn('fast');
			$('.gallery_content_div').fadeIn('fast');
			
		}
	});
	

	var gallery_content_div_resize = function() {
			/*
		var imgWidth = $('.gallery_image img').width();
		
		if(imgWidth > $('.gallery_image').width()) {
			imgWidth = $('.gallery_image').width();
		}
		
		$('.gallery_content_div').animate({
			//width: imgWidth
		}, 'fast');
		*/
	}


	$('.gallery li a').click(function(){
		var imgSrc = $(this).attr('href');
		
		var img = new Image();

		$(img).one('load', function(){
			$('.gallery_image').fadeOut('fast', function(){
				$(this).empty().append(img).fadeIn('fast');

				if($('.gallery_content_div').is(':visible')) {
					//gallery_content_div_resize();
				}
			});
	
		}).attr('src', imgSrc).each(function(){
			
			if(this.complete) $(this).trigger('load');
			
		}).addClass('resizable');
		
		$('.gallery li.active').removeClass('active');
		$(this).parent().animate({opacity: "1"}, 'fast').addClass('active').parent().find('li:not(.active)').animate({opacity: '.4'}, 'fast');
		
		return false;
	});	
	$('.gallery li:first-child a').click();
	
	$('.gallery li').hover(function(){
		$(this).stop().animate({opacity: "1"}, 'fast');
	}, function(){
		if($(this).hasClass('active')) {
			
		} else {
			$(this).stop().animate({opacity: ".4"}, 'fast');
			
		}
		
	});
	


	
	
	var ajaxLoadPage = function(id, type) {
		$.get(ajaxurl, {action: 'load_panel', panel: type, currentPage: id}, function(data){
			$('.gallery_image .wrapper').html(data).animate({opacity: '1'},'fast')
			.jScrollPane({
				scrollbarWidth: 0,
				scrollbarMargin: 0,
					showArrows: true
				});

		});
	}
	
	var personHover = function() {
		$('.person').hover(function() {
			$(this).stop().animate({opacity: "1"}, 'fast');
		}, function(){
			if($(this).hasClass('active')) {

			} else {
				$(this).stop().animate({opacity: ".4"}, 'fast');

			}

		});		
	}

	
	
	$('.person').click(function(){
		var id = $(this).attr('data-id');
		$('.gallery_image .wrapper').animate({opacity: '.2'},'fast', function(){
			ajaxLoadPage(id, 'page');
			
		});

		$('.person.active').removeClass('active');
		$(this).animate({opacity: "1"}, 'fast').addClass('active').parent().find('.person:not(.active)').animate({opacity: '.4'}, 'fast')
		personHover();
	});
	
	
	
	$('.load_cat').click(function(){
		var id = $(this).attr('data-string');
		$('.gallery_image .wrapper').animate({opacity: '.2'},'fast', function(){
			ajaxLoadPage(id, 'post');
			
		});
	});
	
	
	$('.load_resource').click(function(){
		var id = $(this).attr('data-string');
		$('.gallery_image .wrapper').animate({opacity: '.2'},'fast', function(){
			ajaxLoadPage(id, 'resource');
			
		});
		
		
	});
	
	
	$('#press_page > h2:first').click();
/****************************
Simple Scrollable Element
***************************/	
	$(function(){
		$('.scrollable.simple').scrollable({circular: true});	
	});

/****************************
SCROLLABLE BANNER
***************************/	
	$(function(){
		$('.scrollable.slider').each(function(){
			var width = $(this).parent().width();
			$(this).find('.flowpanes, .item_container').width(width);
		});
		
		$('.scrollable.slider .flowtabs ul li:first-child a').addClass('current');
		$(".scrollable.slider").scrollable({ circular: true}).navigator({

				// select #flowtabs to be used as navigator
				navi: ".scrollable.slider .flowtabs",

				// select A tags inside the navigator to work as items (not direct children)
				naviItem: 'a',

				// assign "current" class name for the active A tag inside navigator
				activeClass: 'current'
				
				//history: true

			}).autoscroll({
				autoplay: false, 
				interval: 1000
			});;

	});
	
/****************************
SLIDESHOW
***************************/	
	$(function(){
		$(".tabbed.slider .flowtabs").tabs('.flowpanes .items > div.item_container', {
			// enable "cross-fading" effect
			effect: 'fade',
			fadeOutSpeed: "slow",
			
			// start from the beginning after the last tab
			rotate: true
		}).slideshow({
			autoplay: false, 
			interval: 1000
		});
	});
	


/****************************
OVERLAY
***************************/
	$('body').append('<div id="overlay"></div>');	
	$('#disclaimer a[rel]').overlay({
		absolute: true,
		// some expose tweaks suitable for modal dialogs 
	    expose: { 
	        color: '#000', 
	        loadSpeed: 200, 
	        opacity: 0.9,
			maskId: 'maskOverlay',
			onLoad: function(){}
	    }, 
	    closeOnClick: true
	});


	
	
	var gridOverlay = function() { 
		var overlayMarkup = '\
		<div id="grid_overlay">\
			<div class="container">\
				<div class="span-1"><span>1</span></div>\
				<div class="span-1"><span>2</span></div>\
				<div class="span-1"><span>3</span></div>\
				<div class="span-1"><span>4</span></div>\
				<div class="span-1"><span>5</span></div>\
				<div class="span-1"><span>6</span></div>\
				<div class="span-1"><span>7</span></div>\
				<div class="span-1"><span>8</span></div>\
				<div class="span-1"><span>9</span></div>\
				<div class="span-1"><span>10</span></div>\
				<div class="span-1"><span>11</span></div>\
				<div class="span-1"><span>12</span></div>\
				<div class="span-1"><span>13</span></div>\
				<div class="span-1"><span>14</span></div>\
				<div class="span-1"><span>15</span></div>\
				<div class="span-1"><span>16</span></div>\
				<div class="span-1"><span>17</span></div>\
				<div class="span-1"><span>18</span></div>\
				<div class="span-1"><span>19</span></div>\
				<div class="span-1"><span>20</span></div>\
				<div class="span-1"><span>21</span></div>\
				<div class="span-1"><span>22</span></div>\
				<div class="span-1"><span>23</span></div>\
				<div class="span-1 last"><span>24</span></div>\
			</div>\
		</div>';
		$('body').append(overlayMarkup);
		$('#grid_overlay .span-1').height($(window).height()).css({opacity: '1'});
		
		$(window).bind('resize', function(){
			$('#grid_overlay .span-1').height($(window).height()).css({opacity: '1'});
		});
	}
	
	//gridOverlay();




	
});


