//	---------------------------------------------------------------------------
//	FUNCTION:	fixPNG()
//	AUTHOR:		Ryan J. Salva
//
//	Enables transparecy for PNG files in IE
//	NOTE: Makes most colors a little darker than the GIF counterpart
//	
//	REQUIRED ASSETS:
//	files/site/x.gif (1x1 transparent GIF)


function fixPNG(){
	$$('img[src$=png]').each(function(el){
		var coord = el.getCoordinates();
		el.setStyles({
			width: coord.width,
			height: coord.height,
			filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + el.src + '", sizingMethod="scale")',
			visibility: 'hidden'
		});
		el.src = '_imgs/x.gif';
		el.addEvent('load',function() {
			el.setStyle('visibility','visible');
		});
	});
}
if(window.ie6) window.addEvent('domready', fixPNG);


window.addEvent('domready',function(){
var bodyElements = $$('body p');
	bodyElements.each(function(element) {
		element.effect('opacity', {duration: 500, transition: Fx.Transitions.linear}).start(0,1);
	});
});

window.addEvent('domready',function(){	
	
	$('close').effect('opacity', {duration: 100, transition: Fx.Transitions.linear}).start(0);
		
	/*Login Form*/
	$$('#loginForm input').addEvent('focus',function(){
		if(this.value == "username" || this.value == "password"){
			this.value = "";
			if(this.id == "password")
				this.type = "password";
				this.focus();
		}
	});
	$$('#loginForm input').addEvent('blur',function(){
		if(this.value == ""){
			this.value = this.id;
			this.type = "text";
		}
	});

	var top =  222;
	var closedHeight = 268;
	var zero = 0;
	var pad =  0;
	var controlsHeight = 38;
	var openHeight;
	
	var fx = new Fx.Styles('headerNav', {wait: false, duration: 800, transition: Fx.Transitions.Quad.easeOut});
	var fx1 = new Fx.Styles('header', {wait: false, duration: 1600, transition: Fx.Transitions.Quad.easeOut});
	var fx2 = new Fx.Styles('wrapper', {wait: false, duration: 1200, transition: Fx.Transitions.linear});
	
	/*Header Nav*/
	
	$$('#menuHead').addEvent('mouseenter',function(){
		
		fx.start({
		 'top': top-top-pad
		});
	})		
	
	if(window.ie){
		mouseLeave = '#header';
	}
	else{
		mouseLeave = '#headerNav';
	}
	$$(mouseLeave).addEvent('mouseleave',function(){
	
	fx.stop();
		
		fx.start({
		 'top': top
		});
	})

	/*Header Nav clicked*/
	
	$$('a.demoLink').each(
		function(a){
			a.addEvent('click',function(event){
				var lnk = this.getAttribute('href').slice(this.getAttribute('href').lastIndexOf("#")+1);
				var url = lnk+".php";
				
				// Set Height
				if(lnk == "demo1")
					openHeight = 383;
				if(lnk == "demo2")
					openHeight = 400;
				if(lnk == "demo3")
					openHeight = 432;
				
				//if(window.ie){
					window.open(url, 'demo', 'tollbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizeable=0, width=960, height='+(openHeight+controlsHeight)+', left=80, top=180');
					
					return false;
				//}
				
				// Empty Demo
				$('start').empty();
				
				var ajax = new Ajax(url, {
					method: 'post',
					update: $('start')
				});
				
				top = (openHeight+controlsHeight);
				pad = -(top);
				
				fx.start({
					'top': top
				})//.chain(function(){
					fx1.start({
					 'height': (openHeight+controlsHeight)
					})
				//});
				
				$('wrapper').addClass('TB_overlayMacFFBGHack');
				fx2.start({
					'opacity' : [0,1]
				}).chain(function(){
					ajax.request();
				})
				
				// Add Close Button
				$('close').setStyle('display', 'block');
				$('close').effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(.7);
				

				window.scroll(0,0);
			});
		}
   );
	
	
	/* Reset Header*/
	
//	$('header').addEvent('mouseleave',function(){
	$$('#close a').addEvent('click',function(){

	$('close').effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(0);
	$('close').setStyle('display', 'none');

		top = 222
		pad = 15;
		
			fx1.stop();
			fx.stop();
		
			fx1.start({
			 'height': closedHeight
			}).chain(function(){
				fx.start({
					'top': top
				})
			})
			
		fx2.start({
			'opacity' : [0]
		}).chain(function(){
			$('start').empty();
		})
   });

	/* Load Solutions */
	if($$('#solutionDesc div')[0]){
		$$('#solutionDesc div')[0].setStyle('opacity', 0);
		$$('#solutionDesc div')[0].setStyle('display', 'block');
		$$('#solutionDesc div')[0].effect('opacity', {duration: 800, transition: Fx.Transitions.linear}).start(0,1);
		$$('#solutions a')[0].addClass('active');
	}
	
	$$('#solutions a').addEvent('click',function(){
		var lnk = this.getAttribute('href').slice(this.getAttribute('href').lastIndexOf("#")+1);
		var list = $$('#solutionDesc div');
		
		list.each(function(element) {
			element.setStyle('opacity', 0);
			element.setStyle('display', 'none');
		});
		
		$$('#solutions a').removeClass('active');
		this.addClass('active');
		
		$(lnk).setStyle('opacity', 0);
		$(lnk).setStyle('display', 'block');
		$(lnk).effect('opacity', {duration: 800, transition: Fx.Transitions.linear}).start(0,1);
		
	 });
	
})