// 2010.01.14 - 2010.01.31 - For IDGroup/CVDL
// Grendelfly - A Division of SC&G Technology Solutions
//
// Requires JQuery: jquery-1.3.2.min.js or above



$(function(){
$(document).ready(function() {

// Search (in header)
	$('#idTop_Hdr input').focus(function(){
		$(this).val('')
		}); // $('#idTop_Hdr input').click

	$('#srch_form img.srch_btn').click(function(){
		$('#srch_form form').submit();
		});


// Sign Up (in footer)
$('input.input').focus(function(){
	$(this).val('');
	}); // $('#idTop_Hdr input').click

$('#idBdy_Wrp').click(function(){ // reset
	$('input.input').val('Stay connected by joining our mailing list');
	}); // $('#idTop_Hdr input').click

// Tooltips (for Social Strip)
$('#idSocial a').hover(function(){
	this.t = this.title;
	this.title = "";
	
	var css_marginRight
	if(this.id == "in"){css_marginRight = "78px"};
	if(this.id == "v"){css_marginRight = "58px"};
	if(this.id == "g"){css_marginRight = "38px"};
	if(this.id == "t"){css_marginRight = "18px"};
	if(this.id == "rss"){css_marginRight = "-2px"};
		
	$("div#idSocial p.tooltip span").html(this.t);

	$('div#idSocial p.tooltip span').fadeIn(300)
		.css({'margin-right':css_marginRight});
			},function(){
				this.title = this.t;		
				$('div#idSocial p.tooltip span').hide();

	}); // $('#idSocial img').hover(function() - Tooltips (for Social Strip)


// Tooltips (for Control Strip)
$('#idCntrl a').hover(function(){
	this.t = this.title;
	this.title = "";
	
	var css_marginRight
	if(this.id == "soc_prt"){css_marginRight = "298px"};
	if(this.id == "soc_eml"){css_marginRight = "19px"};
	//if(this.id == "soc_eml"){css_marginRight = "103px"}; when all the social icons in place
	if(this.id == "soc_rss"){css_marginRight = "-2px"};
	//if(this.id == "soc_txt"){css_marginRight = "18px"}; ' remove?
		
	if(this.id == "soc_f"){css_marginRight = "82px"};
	if(this.id == "soc_in"){css_marginRight = "61px"};
	if(this.id == "soc_t"){css_marginRight = "40px"};
	if(this.id == "soc_yt"){css_marginRight = "19px"};

$("#idCntrl_tooltip span").html(this.t);

	$('#idCntrl_tooltip span').fadeIn(300)
		.css({'margin-right':css_marginRight});
			},function(){
				this.title = this.t;		
				$('#idCntrl_tooltip span').hide();

	}); // $('#idCntrl img').hover(function() - Tooltips (for Social Strip)

// Tooltips (for Control Strip 2)
$('#idCntrl2 a').hover(function(){
	this.t = this.title;
	this.title = "";
	$("#idCntrl2 span").html(this.t);
	},function(){
	$("#idCntrl2 span").html('');
	$(this).attr({'title':this.t});
		}); 



// Banner Rotator (for Main Page)
$('#idHero div')
	.css({'position':'absolute'})
	.hide(); // hide all images
$('#idHero_Stats')
	.css({'position':'absolute','bottom':'0'})
	.hide(); // hide stats div

$('#idHero div#Pnl_1').fadeIn(300); // show first panel

var fTimer = setInterval(function(){fRotate()}, 8000); // timed at 8 seconds per rotation
function fRotate(){
	var nImg = $("#idHero div").length; nImg = nImg - 1; // Get number of divs in set
	var nPnl = $('#idHero_Stats').html(); nPnl = parseInt(nPnl) + 1; // Get what div (panel) number we're currently on and moves one forward
	if (nPnl>nImg) { nPnl=0; }; // if we've seen all panels let's start from the beginning

	$('#idHero div').fadeOut(500); // fade out current img

	$("#idHero div").each(function (index, domEle) { // index is 'number count' / domEle is 'this'
		if (index==nPnl) {
		  $(domEle).fadeIn(500);
		  $('#idHero_Stats').html(index); // record what img we're on
		  return false; // stops process			
		  }
		  }); // $("#gFly_Pic_Rotr div").each(function (index, domEle)
	  
		}; // function fRotate(){


// 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 h_img = this.title
	if(h_img !=""){
		h_img = h_img.toLowerCase();
		h_img = h_img.replace(/ /gi,"_");
		h_img = ("tx_" + h_img);
	$(this).html('<img src="/img/'+ h_img +'.gif" />');
	}; // if(h_img !="")
});

// Replace Text w/Image - Span Tag
$('span.repl').each(function(){
	var s_img = this.title
	if(s_img !=""){
		s_img = s_img.toLowerCase();
		s_img = s_img.replace(/ /gi,"_");
		s_img = ("tx_" + s_img);
	$(this).html('<img src="/img/'+ s_img +'.gif" />');
	}; // if(h_img !="")
});


// External Links - Open in new window
// Ancor tags with class of 'ext'
$('a.ext').each(function(){
	$(this).attr({'target':'_blank'});
});


//Controler Functions
// Toggle 'Email a Friend'
$('a#soc_eml').click(function(){
	var f_disp = $('#eml_frnd_wrp').css('display');
	if(f_disp == "none"){
		$('#idCntrl .tooltip').hide();
		$('#eml_frnd_wrp').slideDown(300);
		return false;
		
		}else{
			
		$('#idCntrl .tooltip').show();
		$('#eml_frnd_wrp').slideUp(300);
		return false;
		
		};						  
});

$('#eml_frnd_wrp img').click(function(){			
		$('#idCntrl .tooltip').show();
		$('#eml_frnd_wrp').slideUp(300);
		return false;
		});


// Font Size Function
$('a#txt').click(function(){

	var f_size = $('#idBdy_Box_Lt p').css('font-size');	
	if(f_size == "11px"){
		$('#idBdy_Box_Lt p').css({'font-size':'16px','line-height':'24px'});
		$('#idBdy_Box_Lt ul').css({'font-size':'16px','line-height':'30px'});
		$('a#txt').css({'background-image':'url(/img/ico_neg_gry.gif)'});
		return false;
		
		}else{
			
		$('#idBdy_Box_Lt p').css({'font-size':'11px','line-height':'18px'});
		$('#idBdy_Box_Lt ul').css({'font-size':'11px','line-height':'18px'});
		$('a#txt').css({'background-image':'url(/img/ico_pls_gry.gif)'});
		return false;
		};

});


// Certificate Diagram Effects
$('#cert_dgm_01').hover(function(){
	var h_text = $('#cert_exp_01 h2').text();
	var p_text = $('#cert_exp_01 p').text();
	
	$('#cert_dgm img').css({'background-image':'url(/img/cert_diagram_01.gif)'});
	$('#cert_exp').html('<h2>' + h_text + '</h2><p>' + p_text + '</p>')
	.css({'margin-top':'-140px','margin-left':'40px','width':'420px'})
	.fadeIn(300)
	;
	
	},function(){
		$('#cert_dgm img').css({'background-image':'url(/img/cert_diagram_00.gif)'});
		$('#cert_exp').hide();
	});

$('#cert_dgm_02').hover(function(){
	var h_text = $('#cert_exp_02 h2').text();
	var p_text = $('#cert_exp_02 p').text();
	
	$('#cert_dgm img').css({'background-image':'url(/img/cert_diagram_02.gif)'});
	$('#cert_exp').html('<h2>' + h_text + '</h2><p>' + p_text + '</p>')
	.css({'margin-top':'-80px','margin-left':'-110px','width':'240px'})
	.fadeIn(300)
	;
	
	},function(){
		$('#cert_dgm img').css({'background-image':'url(/img/cert_diagram_00.gif)'});
		$('#cert_exp').hide();
	});

$('#cert_dgm_03').hover(function(){
	var h_text = $('#cert_exp_03 h2').text();
	var p_text = $('#cert_exp_03 p').text();
	
	$('#cert_dgm img').css({'background-image':'url(/img/cert_diagram_03.gif)'});
	$('#cert_exp').html('<h2>' + h_text + '</h2><p>' + p_text + '</p>')
	.css({'margin-top':'-50px','margin-left':'385px','width':'240px'})
	.fadeIn(300)
	;
	
	},function(){
		$('#cert_dgm img').css({'background-image':'url(/img/cert_diagram_00.gif)'});
		$('#cert_exp').hide();
	});

$('#cert_dgm_04').hover(function(){
	var h_text = $('#cert_exp_04 h2').text();
	var p_text = $('#cert_exp_04 p').text();
	
	$('#cert_dgm img').css({'background-image':'url(/img/cert_diagram_04.gif)'});
	$('#cert_exp').html('<h2>' + h_text + '</h2><p>' + p_text + '</p>')
	.css({'margin-top':'100px','margin-left':'-110px','width':'240px'})
	.fadeIn(300)
	;
	
	},function(){
		$('#cert_dgm img').css({'background-image':'url(/img/cert_diagram_00.gif)'});
		$('#cert_exp').hide();
	});

$('#cert_dgm_05').hover(function(){
	var h_text = $('#cert_exp_05 h2').text();
	var p_text = $('#cert_exp_05 p').text();
	
	$('#cert_dgm img').css({'background-image':'url(/img/cert_diagram_05.gif)'});
	$('#cert_exp').html('<h2>' + h_text + '</h2><p>' + p_text + '</p>')
	.css({'margin-top':'100px','margin-left':'385px','width':'240px'})
	.fadeIn(300)
	;
	
	},function(){
		$('#cert_dgm img').css({'background-image':'url(/img/cert_diagram_00.gif)'});
		$('#cert_exp').hide();
	});

// Video (Exemplars) Info Mouseover Effect
	$('div.vid').hover(function(){
		t = '#' + this.id + ' div.vid_info'
		$(t).fadeIn(300);
		$(t + ' img.close').click(function(){$(t).hide();});
			},function(){
			$(t).hide();
	});
// Video (Exemplars) Select Function
$('#idSelect').change(function(){
	var n_loc = $(this).val();
	window.location = "?v=" + n_loc +"#vid";
	});


    /* 
// Video (Exemplars) Select Function
	$('#idVid_Slct div.trigger').hover(function(){
		$('#idVid_Slct ul').fadeIn(300);
			},function(){
			$('#idVid_Slct ul').hide();
	}); // This effect war removed but i kept the html code below
	
	<div id="idVid_Slct">
    <div class="trigger">
        <p>Select Category:</p>
        <% if request("v") = "" then dTopic = "Values-Driven Leadership" %>
        <% if request("v") = "1" then dTopic = "Ethical Practice" %>
        <% if request("v") = "2" then dTopic = "Social Contribution" %>
        <% if request("v") = "3" then dTopic = "Environmental Impact" %>
        <h2><%=(dTopic)%></h2>
        <div style="clear:both;"></div>
        <ul>
            <li><a href="?v=1#vid">Ethical Practice</a></li>
            <li><a href="?v=2#vid">Social Contribution</a></li>
            <li><a href="?v=3#vid">Environmental Impact</a></li>
            <li><a href="?v=#vid">Values-Driven Leadership</a></li>
        </ul>
    </div>
    </div><!-- // End idVid_Slct // -->
	*/
	

// Video Belt Funtionality
// Flipping Between Sets
	$('#idVid_Stats').hide(); // hide stats
	$('.v_set').hide(); // hide all sets
	$('.v_set').css({'position':'absolute','width':'770px'});
	
	$('#idVid_Set_1').fadeIn(300); // fade in first set

	// Button Right
		$('#idVid_Nav_Rt').click(function(){
			// Get Set Number
			var s_num = $('#idVid_Stats').html();
				if(s_num == ""){s_num = 1};
				s_this = parseInt(s_num);
				s_next = parseInt(s_num)+1;
					if(s_next == 5){s_next = 1};

			$('#idVid_Set_' + s_this).animate({'margin-left':'-770px'},500);
			$('#idVid_Set_' + s_next)
			.show()
			.css({'margin-left':'770px'})
			.animate({'margin-left':'0px'},500)
			;						
			$('#idVid_Stats').html(s_next);
		});

	// Button Left
		$('#idVid_Nav_Lft').click(function(){
			// Get Set Number
			var s_num = $('#idVid_Stats').html();
				if(s_num == ""){s_num = 1};
				s_this = parseInt(s_num);
				s_next = parseInt(s_num)-1;
					if(s_next == 0){s_next = 4};
		
			$('#idVid_Set_' + s_this).animate({'margin-left':'770px'},500);
			$('#idVid_Set_' + s_next)
			.show()
			.css({'margin-left':'-770px'})
			.animate({'margin-left':'0px'},500)
			;			
			$('#idVid_Stats').html(s_next);
		});

	// Mouse Over Effect
	$('.v_pnl').hover(function(){
		g_width = $('#' + this.id + ' img').attr('width'); // get image width
		g_height = $('#' + this.id + ' img').attr('height'); // get image height
		g_mt = $('#' + this.id + ' img').css('margin-top'); // get margin top info
			n_mt = parseInt(g_mt) - 8; n_mt = n_mt + 'px';
			o_mt = parseInt(g_mt) + 'px';
		g_ml = $('#' + this.id + ' img').css('margin-top'); // get margin left info
			n_ml = parseInt(g_ml) - 8; n_ml = n_ml + 'px';
			o_ml = parseInt(g_ml) + 'px';
		
		$('#' + this.id + ' img').attr({'width':g_width + 16});
		$('#' + this.id + ' img').attr({'height':g_height + 13});
		$('#' + this.id + ' img').css({'margin-top':n_mt});
		$('#' + this.id + ' img').css({'margin-left':n_ml});
	
	},function(){
		$('#' + this.id + ' img').attr({'width':g_width});
		$('#' + this.id + ' img').attr({'height':g_height});
		$('#' + this.id + ' img').css({'margin-top':o_mt});
		$('#' + this.id + ' img').css({'margin-left':o_ml});
		});

// Picture Pop Out
$('img.pop_out_img').hide(); // Hide Pop Out Pictures
$('img.pop_out').css({'cursor':'pointer'});
$('img.pop_out').attr({'title':'click on image to enlarge'});
$('img.pop_out').click(function(){
	var g_img_id = $(this).attr('rel');
	var g_img_src = $('img#' + g_img_id).attr('src');
	var g_width = $('img#' + g_img_id).width();
	var g_height = $('img#' + g_img_id).height();

	$('<div/>')
		.attr({'id':'screen'})
		.css({'width':'90%','height':'90%','background':'url(/img/scr_bck_80.png)','position':'absolute','border':'#000 solid 2px'})
		.hide()
		.appendTo('body');

	$('<div/>')
		.attr({'id':'pop_out_' + g_img_id})
		.css({'width':g_width,'border':'#FFF solid 10px','cursor':'pointer'})
		.html('<img src="' + g_img_src + '" width="' + g_width + '" height="' + g_height + '" />')
		.hide()
		.appendTo('body');

	$('div#screen').show().positionCenter();
	$('div#pop_out_' + g_img_id).animate({opacity: 'toggle'}, 400).positionCenter();

	$('div#pop_out_' + g_img_id).click(function(){
		$('div#pop_out_' + g_img_id).hide();
		$('div#screen').hide();
		});

	$('div#screen').click(function(){
		$('div#pop_out_' + g_img_id).hide();
		$('div#screen').hide();
		});
	
	$(document).scroll(function(){
		$('div#pop_out_' + g_img_id).hide();
		$('div#screen').hide();
		});
	

});

// Form Validation
	$('#idSub_Conn').click(function() {

		dErrStr = ""; $('input[type="text"]').css({'border-color':'#ccc','background-color':'white'}); // reset everything
		if($('input#dFirstName').val() == ""){dErrStr = dErrStr + "Missing: First Name\n"; $('input#dFirstName').css({'border-color':'red','background-color':'pink'});};
		if($('input#dLastName').val() == ""){dErrStr = dErrStr + "Missing: Last Name\n"; $('input#dLastName').css({'border-color':'red','background-color':'pink'});};
		//if($('input#dTitle').val() == ""){dErrStr = dErrStr + "Missing: Title\n"; $('input#dTitle').css({'border-color':'red','background-color':'pink'});};
		//if($('input#dAddress1').val() == ""){dErrStr = dErrStr + "Missing: Address\n"; $('input#dAddress1').css({'border-color':'red','background-color':'pink'});};
		//if($('input#dCity').val() == ""){dErrStr = dErrStr + "Missing: City\n"; $('input#dCity').css({'border-color':'red','background-color':'pink'});};
		//if($('input#dState').val() == ""){dErrStr = dErrStr + "Missing: State\n"; $('input#dState').css({'border-color':'red','background-color':'pink'});};
		//if($('input#dZip').val() == ""){dErrStr = dErrStr + "Missing: Postal Code\n"; $('input#dZip').css({'border-color':'red','background-color':'pink'});};
		//if($('input#dCountry').val() == ""){dErrStr = dErrStr + "Missing: Country\n"; $('input#dCountry').css({'border-color':'red','background-color':'pink'});};
		if($('input#dEmail').val() == ""){dErrStr = dErrStr + "Missing: Email Address\n"; $('input#dEmail').css({'border-color':'red','background-color':'pink'});};

		if(dErrStr != ""){
		alert("Error In Form!\nPlease fill out all required fields.\n--------------------------------------\n" + dErrStr);
		return false;
		};
		});


// Color box
$("a.clr_bx").colorbox({transition:"elastic"});

// Tabs
	$('.tab').click(function(){
		$('.sect').hide();
		$('li.tab').attr({'class':'tab'});
		
		var g_id = $(this).attr('id').replace('tab_','');
		$('#sect_' + g_id).show();
		$(this).attr({'class':'tab on'});
	});


}); // $(document).ready(function()
}); // $(function()


// ----------------------------------------------------------------------

// Center Funtionality
$(document).ready(function() {
(function($){	  
	$.fn.positionCenter = function(options){
		var pos = {
			sTop : function(){return window.pageYOffset || document.documentElement && document.documentElement.scrollTop ||	document.body.scrollTop;},
			wHeight : function(){return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight;}
			};
	
		return this.each(function(index){
			if (index == 0) {
				var $this = $(this);
				var elHeight = $this.outerHeight();
				var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
				$this.css({'position':'absolute','margin':'0','top':elTop,'left':(($(window).width() - $this.outerWidth()) / 2) + 'px'});
				}
			});
		}; // $.fn.positionCenter
})(jQuery); // function($)
}); // $(document).ready(function()


// Email AJax for e-Newsletter sign up
var xmlhttp
function fSignUP(){
	xmlhttp=GetXmlHttpObject(); // AJAX Functionality Test
	if (xmlhttp==null){alert ("Your browser does not support AJAX!"); return;};
		
	var str = document.getElementById('dEmail_ft').value;
	var eml_chk = str.indexOf("@");
	if(eml_chk=="-1"){
		document.getElementById('dEmail_ft').value = "Please supply a proper email address.";
		}else{
	var url="/fSignUp.asp";
		url=url+"?dEmail="+str;
		
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	document.getElementById('dEmail_ft').value = "Thank you for joining our mailing list.";
	}; return false;
	};
	
// Email AJax for send link to friend

var xmlhttp
function fEmlFrnd(){
	xmlhttp=GetXmlHttpObject(); // AJAX Functionality Test
	if (xmlhttp==null){alert ("Your browser does not support AJAX!"); return;};
		
	var eml_yr_nme = $('input#eml_yr_nme').val();
	var eml_frnd_nme = $('input#eml_frnd_nme').val();
	var eml_frnd_eml = $('input#eml_frnd_eml').val();
	var eml_link = $('input#eml_link').val();
	var eml_chk = eml_frnd_eml.indexOf("@");
	if(eml_chk=="-1"){
		$('#eml_frnd p').html('<strong>Email this page to a friend:</strong> <span style="color:red;">Please supply proper email address.</span>');
		}else{
	var url="/fEmlFrnd.asp";
		url=url+"?eml_yr_nme="+eml_yr_nme;
		url=url+"&eml_frnd_nme="+eml_frnd_nme;
		url=url+"&eml_frnd_eml="+eml_frnd_eml;
		url=url+"&eml_link="+eml_link;
			
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
		$('#eml_frnd p').html('<strong>Email this page to a friend:</strong> <span style="color:red;">Thank you for sharing.</span>');
		$('input#eml_yr_nme').val('');
		$('input#eml_frnd_nme').val('');
		$('input#eml_frnd_eml').val('');
	}; return false;
	};

// AJAX Functionality Test
function GetXmlHttpObject(){ 
	if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();};
	if (window.ActiveXObject){ // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	}return null;
	};
