var  isiPad = navigator.userAgent.match(/iPad/i)  != null;

$(document).ready(function() {

	var base_url = 'http://dev.jtbllc.com';
	current_thumb_page=1;

	$("#testimonial_quote_text").quotator({
    	speed : 11000,
       	json : "/application/ajax/testimonials.php"
	});


	$('#iboss').jqm();


	$("#gallery_thumb_container").easySlider({
		prevText: '',
		nextText: '',
		orientation: 'vertical'
	});

	// Mailing list
	var ml_text = 'Enter your email';
	$('#ml_textbox').val(ml_text);

	$('#ml_textbox').focus(function() {
		if ( $(this).val() == ml_text ) {
			$(this).val('');
		}
	});
	$('#ml_textbox').blur(function() {
		if ( $(this).val() == '' ) {
			$(this).val(ml_text);
		}
	});

	$('.gallery_photo_container').hover(
		function() {
			$('#'+$(this).attr('id')+' .portfolio_nav' ).fadeIn();
		},
		function() {
			$('#'+$(this).attr('id')+' .portfolio_nav' ).fadeOut();
		}
	);

	$('.portfolio_nav a').click( function(){

		if ( $(this).attr('id').indexOf('next') != -1 ) {
			num = $(this).attr('id').replace('portfolio_nav_next_','');
		}
		else {
			num = $(this).attr('id').replace('portfolio_nav_prev_','');
		}
		if ( num > current_thumb_page * 4) { $('#nextBtn a').click(); }
		if ( num < current_thumb_page * 4 - 3 ) { $('#prevBtn a').click(); }
		$('#gallery_thumb_' + num).click();
	
	});

	// portfolio landing page
	// make fadein a callback... sometimes it messes up
	$('#gallery_preview_1').show();
	$('#gallery_thumb_1').addClass('active');
	$('#portfolio .gallery_thumb').hover(function(){

		if ( isiPad == false ) {
			preview = $(this).attr('id').replace('thumb','preview');
			$('.gallery_thumb').removeClass('active');
			$('.gallery_preview').hide();
			$('#'+preview).fadeIn();
			$(this).addClass('active');
		}

	});
	$('#portfolio .gallery_thumb').click(function(){

		window.location = $(this).attr('href');

	});



	// portfolio page
	$('#gallery_photo_1').css('z-index', '999');
	current_photo_id = 'gallery_photo_1';
	if ( location.hash == '#photo1' || location.hash == '' ) {
		$('#gallery_photo_1').show();
	}
	$('#portfolio_view .gallery_thumb').click(function(){

		current_id = $(this).attr('id').replace('gallery_thumb_', '');
		var new_photo_id = $(this).attr('id').replace('thumb', 'photo');
		if ( new_photo_id != current_photo_id ) {
			$('#'+current_photo_id).fadeOut(1000);
			$('#'+new_photo_id).fadeIn(2000);
			$('.gallery_thumb').removeClass('active');
			$(this).addClass('active');
			current_photo_id = new_photo_id;
		}

	});


	$('#mill_gallery a').lightBox({
		imageLoading: '/images/lightbox-ico-loading.gif',
		imageBtnClose: '/images/lightbox-btn-close.gif',
		imageBtnPrev: '/images/lightbox-btn-prev.gif',
		imageBtnNext: '/images/lightbox-btn-next.gif'
	});




	$(window).unload( function (){ document.cookie = 'tid=' + currentTestimonialId + '; expires=Thu, 2 Aug 2023 20:47:11 UTC; path=/'} );



});


	(function($) {
	
		$.fn.easySlider = function(options){
		  
			// default configuration properties
			var defaults = {
				prevId: 		'prevBtn',
				prevText: 		'Previous',
				nextId: 		'nextBtn',	
				nextText: 		'Next',
				orientation:	'', //  'vertical' is optional;
				speed: 			800			
			}; 
			
			var options = $.extend(defaults, options);  
			
			return this.each(function() {  
				obj = $(this); 				
				var s = $("li", obj).length;
				var w = obj.width(); 
				var h = obj.height(); 
				var ts = s-1;
				var t = 0;
				var vertical = (options.orientation == 'vertical');
				$("ul", obj).css('width',s*w);			
				//if(!vertical) $("li", obj).css('float','left');
				$(obj).after('<span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span> <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>');		
				$("a","#"+options.prevId).hide();
				$("a","#"+options.nextId).hide();
				$("a","#"+options.nextId).click(function(){
					current_thumb_page = t+2;
					animate("next");
					if ( t*4+4>=s ) $(this).fadeOut();
					$("a","#"+options.prevId).fadeIn();
				});
				$("a","#"+options.prevId).click(function(){		
					current_thumb_page = t;
					animate("prev");
					if (t<=0) $(this).fadeOut();
					$("a","#"+options.nextId).fadeIn();
				});	
				function animate(dir){
					if(dir == "next"){
						t = (t>=ts) ? ts : t+1;	
					} else {
						t = (t<=0) ? 0 : t-1;
					};								
					if(!vertical) {
						p = (t*w*-1);
						$("ul",obj).animate(
							{ marginLeft: p }, 
							options.speed
						);				
					} else {
						p = (t*h*-1);
						$("ul",obj).animate(
							{ marginTop: p-(10*t) }, 
							options.speed
						);					
					}
				};
				if(s>4) $("a","#"+options.nextId).fadeIn();	
			});
		  
		};
	
	})(jQuery);



var addthis_config = {
          services_compact: 'print, email, favorites, google, digg, more',
          ui_click: true
}

