var htmlroot = '/kevin/lancier/html';

function openLogin() {
	$(".openLog").click( function(e) {
		$("#logForm").animate( { marginLeft: "0" }, 'normal', 'linear', function(){
				$("#expandArrow").css( { display: 'none' } );
				$("#collapseArrow").css( { display: 'block' } );
			} );
			e.preventDefault();
		}
	);
}

function closeLogin() {
	$(".closeLog").click(
		function() {
			$("#logForm").animate( { marginLeft: "-290px" }, 'normal', 'linear', function() {
				$("#collapseArrow").css( { display: 'none' } );
				$("#expandArrow").css( { display: 'block' } );
			} );
			
		}
	);
}

function registerToggle() {
	$(".registerToggle").toggle(
		function() {
			$("#loginSlideForm").fadeOut( 'normal', function(){
				$("#registerSlideForm").fadeIn( 'normal' );
				$("#logForm span").html( 'login' );
			} );
		},
		function(){
			$("#registerSlideForm").fadeOut('normal', function(){
				$("#loginSlideForm").fadeIn('normal');
				$("#logForm span").html( 'start a new account' );
			});
		});
}

function animateQuote() {
	$("#quotebox .quote").click( function(e) {
		$("body").append('<div id="darkWrap"></div>');
		$("body").append( $("#quoteForm") );
		var newLeft = $("body").width()/2;
		$("#quoteForm").css({ left: newLeft + 'px' });
		$("#darkWrap").css({ top: '0px', left: '0px', position: 'fixed', zIndex: 2000, width: '100%', height: '100%', paddingBottom: '271px', backgroundColor: 'black', opacity: 0 });
		$("#darkWrap").animate({ opacity: .6 }, 'fast', 'linear' );
		$("#quoteForm").animate( { height: '500px', marginTop: '100px' }, 'normal', 'linear', function() {
			$(this).animate( { width: '600px', left: newLeft - 282 + 'px' }, 'normal', 'linear', function() {
				$("#quoteForm .innerQuoteForm").children().fadeIn();
				$("#qouteFormHtml1").fadeIn();
			} );
		} );
		
		e.preventDefault();
		
		$("#quoteForm .close").click(function(){
			$("#quoteForm .innerQuoteForm").children().fadeOut( 'fast', function() {
				$('#quoteForm').animate({ width: '20px', left: newLeft + 'px', height: '10px', marginTop: '-10px' }, 'fast', 'linear' );
				$("#darkWrap").fadeOut( 'fast', function() {
					$(this).remove();
				} );
			} );
			
			$("#quoteForm .innerQuoteForm form > :visible").hide();
		});
	});
}

function quoteNavigation() {
	$(".innerQuoteForm .next").click( function(){
		$(this).parent().parent().fadeOut( 'fast', function() {
			$(this).next().fadeIn();
		} );
	} );
	$(".innerQuoteForm .previous").click( function() {
		$(this).parent().parent().fadeOut( 'fast', function() {
			$(this).prev().fadeIn();
		} );
	} );
}

function ieHacks() {
	
	// handle img tags with transparent PNGs
	$("img[@src$='png']").each( function() {
		
		// define some variables
		var imgWidth = $(this).width();
		var imgHeight = $(this).height();
		var imgSource = $(this).attr( 'src' );
		
		// create wrapper div
		$(this).wrap( "<div class='pngImg' style='height:" + imgHeight + "px; width:" + imgWidth + "px;'></div>" );
		$(this).parent().css( 'filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src="' + imgSource + '")' );
		$(this).parent().css({ 
			'margin-left' : $(this).css( 'margin-left' ), 
			'margin-right' : $(this).css( 'margin-right' ), 
			'margin-top' : $(this).css( 'margin-top' ), 
			'margin-bottom' : $(this).css( 'margin-bottom' ), 
			'padding-top': $(this).css( 'padding-top' ), 
			'padding-bottom': $(this).css( 'padding-bottom' ),
			'padding-left': $(this).css( 'padding-left' ),
			'padding-right': $(this).css( 'padding-right' ),
			'float' : $(this).css( 'float' ), 
			'clear' : $(this).css( 'clear' ) });
		
		// remove original image
		$(this).css( 'display', 'none' );

	} );
	
	// handle double-margin bug
	re = /(-?)(\d+)px/;
	$('body *').each( function() {
		
		// check for floated elements
		if ( $(this).css( 'float' ) == ( 'left' || 'right' ) ) {
			
			// initialize internal variables
			var update = $(this);
			var floatStyle = update.css( 'float' );
			
			// check for positive side margins assigned in pixels and retrieve numerical value
			if ( sideMargin = re.exec( update.css( 'margin-' + floatStyle ) ) ) {
				
				// only alter positive margins
				if ( sideMargin[1] != '-' ) {
					
					// reassign side margin with half its value
					var newSideMargin = Math.round( sideMargin[2] / 2 );
					update.css( 'margin-' + floatStyle, newSideMargin + 'px' );
				}
			}
		}
	});
	
	// handle min-height bug
	$('#wrapper *').each( function() {
		
		if ( minHeight = re.exec( $(this).css( 'min-height' ) ) ) {
			
			// initialize internal variables
			var update = $(this);
			minHeightValue = minHeight[2];
			
			// assign height hack to element if needed
			if ( update.height() < minHeightValue ) {
				update.css( 'height', minHeightValue + 'px' );
			}
			
		}
		
	});
	
}



$(document).ready(function(){
	openLogin();
	closeLogin();
	registerToggle();
});

$(document).ready(function(){
	if (document.all && !window.opera && !window.XMLHttpRequest) {
		ieHacks();
	}
	else {
		animateQuote();
		quoteNavigation();
	}
});