// add stylesheet when javascript is enabled
var h=document.getElementsByTagName('head')[0];var y=document.createElement('link');y.type='text/css';y.rel='stylesheet';y.href='/style/script-on.css';y.media='screen,projection';h.appendChild(y);

$(document).ready(function() {
	
	// give certain form inputs default values
	$('input#txtSearch').defaultvalue('Search');
	$('input#txtUsername').defaultvalue('Username');
	$('input#txtPassword').defaultvalue('Password');
	$('input#txtEmail').defaultvalue('Email Address');
	
	// add rule to bottom of #content, except on homepage
	$('body:not(#home) #content').append('<div class="btm-bar-content"></div>');
	
	// create target="_blank" equivalent
	$('a[rel="external"]').click(function(){
		window.open(this.href);
		return false;
	});
	
	// make the login dropdown form function
	var flip = 0;
	$('form#login fieldset legend a').click(function() {
		$('#login-form').slideToggle(300);
		
		if (flip++ % 2 == 0)
			$(this).fadeTo('normal',.33);
		else
			$(this).fadeTo('normal',1);
		
		return false;
	});
	

	
	// attach class to navigation items for fixing ie :hover pseudo-class
	if (document.all && document.getElementById) {
		cssdropdownRoot = document.getElementById('nav');
		for (x=0; x < cssdropdownRoot.childNodes.length; x++) {
			node = cssdropdownRoot.childNodes[x];
			if (node.nodeName == 'LI') {
				node.onmouseover	= function() {this.className += ' over';}
				node.onmouseout		= function() {this.className = this.className.replace(' over', '');}
			}
		} // [for]
	} // [if]
	
	/*$('ul#nav > li ul').mouseover(function () {
		$(this).siblings('a.rounded').addClass('pooty');
	});
	$('ul#nav > li ul').mouseout(function () {
		$(this).siblings('a.rounded').removeClass('pooty');
	});*/
	
	// preload images
	jQuery('<img>').attr('src','/images/sprite-socials-on.png');
	jQuery('<img>').attr('src','/images/bg-dropdown.jpg');
	
	
	
	
	
	var flashWidth	= 960;
	var flashHeight	= 263;
	
	/*if ($('body').attr('class') == '') {
		$('#flash').flash({
			src:'/include/flash/intro.swf',
			wmode:'transparent',
			width:flashWidth,
			height:flashHeight
		});
	}*/
	
	
	// initiate slide show
	$('#slideshow').before('<ul id="slidenav">').cycle({
        fx:					'fade',
        speed:				1000,
        timeout:			5000,
        pager:				'#slidenav'
    });
	
	
	
	/*$('body.answering-service #flash').flash({
		src:'/include/flash/answering_intro.swf',
		wmode:'transparent',
		width:flashWidth,
		height:flashHeight
	});
	
	$('body.software-solutions #flash').flash({
		src:'/include/flash/software_intro.swf',
		wmode:'transparent',
		width:flashWidth,
		height:flashHeight
	});
	
	$('body.inbound-services #flash').flash({
		src:'/include/flash/inbound_intro.swf',
		wmode:'transparent',
		width:flashWidth,
		height:flashHeight
	});
	
	$('body.outbound-services #flash').flash({
		src:'/include/flash/outbound_intro.swf',
		wmode:'transparent',
		width:flashWidth,
		height:flashHeight
	});
	
	$('body.nobrand #flash').flash({
		src:'/include/flash/intro_nobrand.swf',
		wmode:'transparent',
		width:flashWidth,
		height:flashHeight
	});*/

/*	
	$('#testimonial-video').flash({
		src:'http://www.youtube.com/v/MxDrRzp2cDQ&hl=en&fs=1&rel=0',
		width:285,
		height:190
	});
*/
	
	// initialize the testimonial ticker on right nav bar
	$('#testimonial-ticker').innerfade({
		animationtype: 'slide',
		speed: 'normal',
		timeout: 5000,
		type: 'sequence',
		containerheight: '125px'
	});
	
});

// Some things work better when you wait until all images loaded
$(window).load(function(){
	// for ie, target	 only the top-level navigation items for rounded corners (not children which makeup the dropdowns)
	// **** Clay Simmons ****
	// Commented out b/c it doesn't seem to be adding the class in IE.  Just added the class="rounded" in the markup.
	// $('ul#nav li a').addClass('rounded');

	// add classes for styling dropdown menus
	$('ul#nav li ul li:first-child a').addClass('dropdown-bg');
	$('ul#nav li ul li:last-child a').addClass('dropdown-corner');

	// replace certain text with special font
	Cufon.replace('.homebox h3, #nav-wrapper #navigation ul#nav li a, #right h3, #mailing-list legend, #homequote, #right-wrapper h4 a, #content h1, .contact-form a, #social-media h3, a.ql-anchor');
});