// 2010.12.30
// Grendelfly - A Division of SC&G Technology Solutions
// For Service Logic
// Requires JQuery: jquery-1.4.2.min.js

$(function(){
$(document).ready(function() {

// Tab Animation
	$('.tab').hover( function(){
		$(this).stop(true,true).animate({'height':'40px','width':'90px','margin-top':'10px','font-size':'15px'},100)
			   .animate({'height':'35px','width':'90px','margin-top':'15px'},150);
							   }, function(){	
								$(this).stop(true,true).animate({'height':'30px','width':'80px','margin-top':'20px','font-size':'13px'},250);		
											});
	
// Sub Nav Achor Effect
	$('#sub_nav li.nav').mouseenter( function(){
		var g_chk = $(this).attr('class');
		if (g_chk.indexOf('select') == -1){$(this).stop(true,true).animate({'font-size':'16px'},100);};
		});
	$('#sub_nav li.nav').mouseleave( function(){
		var g_chk = $(this).attr('class');
		if (g_chk.indexOf('select') == -1){$(this).stop(true,true).animate({'font-size':'14px'},250);};
		});

// Login Achor Effect
	$('#idLogin a').hover( function(){
		$(this).stop(true,true).animate({'padding-bottom':'10px','padding-top':'10px'},250);
			}, function(){	
				$(this).stop(true,true).animate({'padding-bottom':'5px','padding-top':'5px'},100);
		});

// Action Box Effect
$('#actBx_1').hover( function(){
		$(this).children('div').children('div').children('img').stop(true,true).animate({'margin-top':'20px'},250);
			}, function(){	
				$(this).children('div').children('div').children('img').stop(true,true).animate({'margin-top':'40px'},200);
		});

$('#actBx_2').hover( function(){ 
		$(this).children('div').children('div').children('img').stop(true,true).animate({'width':'119px','height':'90px','margin-left':'99px','margin-top':'44px'},200);
			}, function(){	
				$(this).children('div').children('div').children('img').stop(true,true).animate({'width':'105px','height':'76px','margin-left':'105px','margin-top':'58px'},200);
		});

// Action Navigation
$('.act').click( function(){
	var g_url = $(this).children('p').children('a').attr('href');
	if(g_url != null){window.location.assign(g_url);};
	});


// External Links - Open in new window
// Ancor tags with class of 'ext'

	$('a.ext').each(function(){
		$(this).attr({'target':'_blank'});
		});

// Javascript Button Function
	$('input[type="button"]').click( function(){
		var g_url = $(this).attr('url');
		window.location.assign(g_url);
		});



// URL Javascript Link Issue  ------  Paging
// Being the paging is all done in javascript
// we have to find a creative way to share URL's for marketing or Email to a friend
// Paging Effect

var g_url = document.URL;
if(g_url.indexOf('#') != -1){
	fGetHash();
	}else{
		$('.wrp_out img').hide();
		$('.wrp_out img').first().show(); // Load first picture
		$('.pg').first().show(); // Load first paragraph
		$('#sub_nav li').first().addClass('select');
		};

function fShowHash(g_hsh){
	$('.pg').hide();	
	$('#pg_' + g_hsh).show();
	fSetEle(g_hsh);
	};

function fPutHash(g_hsh){ // Put Hash into URL
	window.location.hash = g_hsh;
	};

function fGetHash(){ // Get Hash from URL
	var g_url = document.URL;
	var g_hsh = '';
	if(g_url.indexOf('#') != -1){
		g_hsh = g_url.slice(g_url.indexOf('#'),g_url.length).replace('#','');
		fShowHash(g_hsh);	
		};
	};

function fSetEle(g_hsh){
	$('#sub_nav li').removeClass('select').css({'font-size':'14px'});								  
	$('#sub_nav li a').each( function(i,x){
		var chk = $(x).attr('rel');
		var act_frm = $(x).parent('li').attr('class'); // Check to see if it's an Action Box link
		if(chk == g_hsh && act_frm.indexOf('act_frm') == -1){
			$(x).parents('li').addClass('select');
			
			// Picture Change
			var g_chk = $(x).parents('li').attr('class');
				if (g_chk.indexOf('pic') != -1){
					$('.wrp_out img').hide();
					$('.wrp_out img#pic_' + g_hsh).fadeIn(800);
					};
					
			// Header Text Change
				var g_txt = $('.wrp_out img#pic_' + g_hsh).attr('title');
				$('#idHr_Txt h1').html(g_txt)
					.css({'margin-left':'-10px'})
					.stop(true,true)
					.animate({'margin-left':'0px'},1000)
					;
			
			}; // End if(chk == g_hsh)
		}); // End $('#sub_nav li a').each
	};

// Links with Hash - Any link with rel
$('a').click( function(){
	g_hsh = $(this).attr('rel');
	if(g_hsh == 'clr_bx'){g_hsh = 'Photo_Gallery'};
	if( g_hsh != 'undefined' && g_hsh != false ){  
		fPutHash(g_hsh);
		fShowHash(g_hsh);
		};
	$(this).blur();	 						  
	});

$('li.act_frm').click( function(){
	g_hsh = $(this).children().attr('rel');
	if(g_hsh == 'clr_bx'){g_hsh = 'Photo_Gallery'};
	if( g_hsh != 'undefined' && g_hsh != false ){  
		fPutHash(g_hsh);
		fShowHash(g_hsh);
		};
	$(this).blur();	 						  
	});


// Sub Paging Effect

$('#idEnergy li').first().addClass('select'); 
$('#idMobile li,').first().addClass('select'); 

$('.sub_page li a').click( function(){
									
	var g_sub_page_id  = $(this).parents('div').attr('id');
	
	$('#' + g_sub_page_id + ' li').removeClass('select'); 	// Reset Effect									  
	$(this).parents().addClass('select'); 
	$(this).blur();
	
	var g_id  = $(this).attr('id').replace('a','sbpg');	
	var g_num = g_id.replace(/\D/g,'');
	var scrl  = -1*(Number(g_num)*250) + 250;
	$('#' + g_sub_page_id + ' .sub_page_disp_inner').animate({'margin-top':scrl + 'px'},500);

	return false;
	});

$('.sub_page_cntl').click( function(){
	var g_sub_page_id  = $(this).parents('div').attr('id');
	var g_class  = $(this).attr('class');
	var g_num = $('#' + g_sub_page_id + ' .sub_page_disp_inner').css('margin-top').replace(/\D/g,'');
		g_num = Number(g_num)/250 +1;
	var i = $('#' + g_sub_page_id + ' li').length;

	if(g_class.indexOf('up') == -1 && g_num < i){ g_num = Number(g_num)+1;};
	if(g_class.indexOf('down') == -1 && g_num > 1){ g_num = Number(g_num)-1;};
	
	var scrl  = -1*(Number(g_num)*250) + 250;
	$('#' + g_sub_page_id + ' .sub_page_disp_inner').animate({'margin-top':scrl + 'px'},500);
	$('#' + g_sub_page_id + ' li').removeClass('select'); 	// Reset Effect									  
	$('#' + g_sub_page_id + ' #a_' + g_num).parents('li').addClass('select'); 
	});

//  Color Box Functions

	$("a.clr_bx").colorbox({transition:"elastic"}); // single
	$("a[rel='clr_bx']").colorbox({transition:"elastic"}); // group

// Contact Page

$('img.eml').css({'cursor':'pointer'});
$('img.eml').click( function(){
	var g_rel = $(this).attr('rel');
	$('.eml_add').hide();
	$('#eml_' + g_rel).show();
	$('#eml_tit').html(g_rel);
	$('#eml_form').show();
	});

}); // $(document).ready(function()
}); // $(function()


