// JavaScript Document

//var ie7 = (document.all && !window.opera && window.XMLHttpRequest);
$(document).ready(function(){
	$("div.fg-clear:contains('Powered by')").hide();
	$("iframe").not("#map").attr("scrolling","no").attr("width","920px");
	$("div#topnav li.current_page_item a").before('<img src="/wp-content/themes/gdt/images/top-nav-tab-left.png" />').after('<img src="/wp-content/themes/gdt/images/top-nav-tab-right.png" />');
	//070C32
    //flash text replacement
	$('h11').flash(
        { 
            src: '/wp-content/themes/gdt/js/Helvetica_Neue_Lt_Std_Thin_Extended.swf', 
            flashvars: { 
                css: [
                    '* { color: #CC0000 }',
                    'a { color: #ffffff; text-decoration: none; }',
                    'a:hover { text-decoration: underline; }'
                ].join(' ')
            }
        },
        { version: 7 },
        function(htmlOptions) {
            htmlOptions.flashvars.txt = this.innerHTML;
            this.innerHTML = '<div>'+this.innerHTML+'</div>';
            var $alt = $(this.firstChild);
            htmlOptions.height = $alt.height();
            htmlOptions.width = $alt.width();
            $alt.addClass('alt');
            $(this)
                .addClass('flash-replaced')
                .prepend($.fn.flash.transform(htmlOptions));						
        }
    );
	$('h21').flash(
        { 
            src: '/wp-content/themes/gdt/js/Helvetica_Neue_Lt_Std_Thin_Extended.swf', 
            flashvars: { 
                css: [
                    '* { color: #394358; }',
                    'a { color: #ffffff; text-decoration: none; }',
                    'a:hover { text-decoration: underline; }'
                ].join(' ')
            }
        },
        { version: 7 },
        function(htmlOptions) {
            htmlOptions.flashvars.txt = this.innerHTML;
            this.innerHTML = '<div>'+this.innerHTML+'</div>';
            var $alt = $(this.firstChild);
            htmlOptions.height = $alt.height();
            htmlOptions.width = $alt.width();
            $alt.addClass('alt');
            $(this)
                .addClass('flash-replaced')
                .prepend($.fn.flash.transform(htmlOptions));						
        }
    );
	$('h31').flash(
        { 
            src: '/wp-content/themes/gdt/js/Helvetica_Neue_Lt_Std_Thin_Extended.swf', 
            flashvars: { 
                css: [
                    '* { color: #002b2f; }',
                    'a { color: #ffffff; text-decoration: none; }',
                    'a:hover { text-decoration: underline; }'
                ].join(' ')
            }
        },
        { version: 7 },
        function(htmlOptions) {
            htmlOptions.flashvars.txt = this.innerHTML;
            this.innerHTML = '<div>'+this.innerHTML+'</div>';
            var $alt = $(this.firstChild);
            htmlOptions.height = $alt.height();
            htmlOptions.width = $alt.width();
            $alt.addClass('alt');
            $(this)
                .addClass('flash-replaced')
                .prepend($.fn.flash.transform(htmlOptions));						
        }
    );
	$(".fadetitle").hide();
	repositionTitles();
	$(window).resize(function(){repositionTitles()});
	
	//chrome will fire this too soon and it won't read the heights accurately so a short
	//delay will take care of it.
	setTimeout('adjustLeftColumn()',500)
	setTimeout('fadeTitle(0)',1000);
});

function repositionTitles(){
	$(".fadetitle").each(function(index){
		repositionTitle(index);						  
	});
}
function repositionTitle(i){
	var diff = ($("#body").outerWidth() - $("#content").outerWidth())/2 + $("#contentleft").outerWidth() + 14;
	
	var top = $(".fadetitle").eq(i).attr("mytop");
	top = top.replace("px","");
	var newtop = Number(top) + 111;
	newtop = newtop + "px";
	
	left = $(".fadetitle").eq(i).attr("myleft").replace("px","");
	newleft = diff + Number(left);
	$(".fadetitle").eq(i).css("top",newtop).css("left",newleft+"px");
}
//size the left column so that it extends down to the footer
function adjustLeftColumn(){
	var minHeight = 1000;
	var contentRightHeight = $("div#contentright").outerHeight();
	if(contentRightHeight < minHeight){
		$("div#contentright").height(minHeight);
		contentRightHeight = $("div#contentright").outerHeight();
	}
	var contentLeftHeight = $("div#contentleft").outerHeight();
	if(contentRightHeight > contentLeftHeight)
		$("div#contentleft").height(contentRightHeight);
	//else
	//	$("div#contentright").height(contentLeftHeight);
}
function sleep(naptime){
	 naptime = naptime * 1000;
	 var sleeping = true;
	 var now = new Date();
	 var alarm;
	 var startingMSeconds = now.getTime();
	 while(sleeping){
		 alarm = new Date();
		 alarmMSeconds = alarm.getTime();
		 if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false; }
		 //console.log(alarmMSeconds);
	 }      
 }
function fadeTitle(i){
	$(".fadetitle").fadeOut('slow');

	var x = $(".fadetitle").length;
	if(i > (x-1))
		i = 0;
	
	$(".fadetitle").eq(i).removeClass('off').addClass('on').fadeIn('slow',function(){
		if(x > 1 && !$(".fadetitle").eq(i).hasClass('stop')){
			i++;
			setTimeout('fadeTitle('+i+')',3000);
		}
	});	
	
}
