// 2010.02.14 - For Lorem Ipsum
// Grendelfly - A Division of SC&G Technology Solutions
//
// Requires JQuery: jquery-1.3.2.min.js or above



$(function(){
$(document).ready(function() {

// Replace H1 Tags w/Images

	// H1 title tag and file name of image should be the same
	// Img spaces in file name should be replaced with "_"
	// Img file name should start with "tx_"
	$('h1.repl').each(function(){
		var r_img = this.title;
		if(r_img !=""){
			r_img = r_img.toLowerCase();
			r_img = r_img.replace(/ /gi,"_");
		$(this).html('<img src="/img/tx_'+ r_img +'.gif" />');
		}; // if(r_img !="")
	});
	
	// creating all links to be external
	$('a').each( function(i,x){
		var g_url = $(x).attr('href');
		if(g_url.indexOf('.com') != -1 && g_url.indexOf('acornconstruction') == -1){
			$(x).attr({'target':'_blank'});
			};
		});

	$('#pic_wrp img').each( function(i,x){
		$(x).attr({'id':'pic_'+i}); // pass out IDs in order listed
		if(i==0){$(x).show();}; // show first pic
		});
	
	$('#dsc_wrp div').each( function(i,x){
		$(x).attr({'id':'dsc_'+i}); // pass out IDs in order listed
		if(i==0){$(x).show();}; // show first description
		});
	
	$('#thm_wrp img').each( function(i,x){
		$(x).attr({'id':'thm_'+i}); // pass out IDs in order listed
		if(i==0){$(x).css({'border-color':'#eb7816'});}; // show first pic
		});
		
	$('#thm_wrp img').click( function(){
		var g_id = $(this).attr('id').replace('thm_','');
		$('#pic_stats').text(g_id); // record ID
		
		$('#pic_wrp img').hide();
		$('#pic_wrp img#pic_' + g_id).show();
		
		$('#dsc_wrp div').hide();
		$('#dsc_wrp div#dsc_' + g_id).show();
		
		$('#thm_wrp img').each( function(i,x){ // reset border to white
			$(x).css({'border-color':'#FFF'});
			});
		$(this).css({'border-color':'#eb7816'});
		});

	$('.btn').click( function(){
		var g_btn = $(this).attr('id');
		var g_id = $('#pic_stats').text();
		var g_len = $('#thm_wrp img').length;
		
		if(g_btn=='btn_fwd'){g_id = Number(g_id)+1};
		if(g_btn=='btn_bck'){g_id = Number(g_id)-1};
		if(g_id <= -1){g_id = g_len-1};
		if(g_id >= g_len){g_id = 0};
		
		$('#pic_stats').text(g_id); // record ID

		$('#pic_wrp img').hide();
		$('#pic_wrp img#pic_' + g_id).show();
		
		$('#dsc_wrp div').hide();
		$('#dsc_wrp div#dsc_' + g_id).show();

		$('#thm_wrp img').each( function(i,x){ // reset border to white
			$(x).css({'border-color':'#FFF'});
			});
		$('#thm_' + g_id).css({'border-color':'#eb7816'});
		$("#thm_wrp").scrollLeft( (g_id*149)-511 );
		});


/*
// Picture Viewer Function
	// Show first slides
	$('#pic_1').fadeIn(800);
	$('#dsc_1').show();
	$('#thm_1').css({'border-color':'#F58220'});
	
	// Thumb Function
	$('.thm').click(function(){
		$('.thm').css({'border-color':'#CCC'});
		$(this).css({'border-color':'#F58220'});
		
		var g_id = $(this).attr('id').replace('thm_','');
		$('.pic').hide();
		$('.dsc').hide();
		
		$('#pic_' + g_id).fadeIn(800);
		$('#dsc_' + g_id).show();
		$('#pic_stats').html(g_id);
		
		// move slider
		var n_pic = $('#pic_wrp img').length;
		var g_id = $('#pic_stats').html();
		$('.slider').slider("value", g_id);
		$('#thm_wrp_in').css('margin-left', Math.round( g_id / 8 * ( 630 - (170 * n_pic) )) + 'px');		

	});
	
	// Button Function
	$('.btn').click(function(){
		var n_pic = $('#pic_wrp img').length;
		var g_id = $('#pic_stats').html();
		
		if($(this).attr('id') == 'btn_fwd'){g_id = parseInt(g_id) + 1;};
		if($(this).attr('id') == 'btn_bck'){g_id = parseInt(g_id) - 1;};
		if(g_id > n_pic){g_id = 1};
		if(g_id < 1){g_id = n_pic};
		
		$('.pic').hide();
		$('.dsc').hide();
		$('.thm').css({'border-color':'#CCC'});
		
	
		$('#pic_' + g_id).fadeIn(800);
		$('#dsc_' + g_id).show();
		$('#thm_' + g_id).css({'border-color':'#F58220'});
		$('#pic_stats').html(g_id);
		
		// move slider
		$('.slider').slider("value", g_id);
		$('#thm_wrp_in').css('margin-left', Math.round( g_id / 8 * ( 630 - (170 * n_pic) )) + 'px');		
	});

	// Slider Function
		var n_pic = $('#pic_wrp img').length;

		$('.slider').slider({
			animate:false,
			min: 0,
			max: n_pic
			}).slider( "widget" );
		

		$('.slider').slider({
			slide:function(e, ui){

				var scrollPane = $('.ui-slider');
				var scrollContent = $('#thm_wrp_in');
				
				if( scrollContent.width() > scrollPane.width() ){
					 scrollContent.css('margin-left', Math.round( ui.value / 8 * ( scrollPane.width() - (170 * n_pic) )) + 'px'); }
				else { scrollContent.css('margin-left', 0); }
				
				}
			});
	*/	
	//  Color Box Functions
		$("a.clr_bx").colorbox({transition:"elastic"}); // single

}); // $(document).ready(function()
}); // $(function()


