// Contact form Slide
$(document).ready(function(){
	$("#contactLink").click(function(){
		if ($("#contactForm").is(":hidden")){
			$("#contactForm").slideDown("slow");
			$("input:text:first").focus();
		}
		else{
			$("#contactForm").slideUp("slow");
		}
	});
});
function closeForm(){
	$("#messageSent").show("slow");
	setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
}


// Language Switcher and Zoomer
$(document).ready(function(){
	//$("div#lang").click(function(){$("div#content").load("es.html");});
	$('#lang a').langSwitcher();


	$("a[rel='popbox']").colorbox();
	
	// Add jQ Lightbox on load
	//$('a[@href$=".jpg"]').lightBox();
	//$('.lightbox').lightBox();
});



// Source: Thomas Maloney @ photoshoplab.com
// Correct PNG Images for IE 6
var pngFix = {
	init : function() {
		var imgs = $("img[@src*=png]");
		imgs.each(
			function() {
				var newSrc = $(this).attr('src'), newID = $(this).attr('id'), newClass = $(this).attr('class'), newTitle = $(this).attr('alt'), newStyle = $(this).attr('style'), newAlign = $(this).attr('align'), newW = $(this).attr('width'), newH = $(this).attr('height'), dfilter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,src='"+ newSrc +"',sizingMethod=image)";
				
				var span = document.createElement('span');
				$(span).attr({ 'id':newID, 'class':newClass, 'title':newTitle, 'style':newStyle });
				$(span).css({'display':'inline-block', 'background':'none', width:newW+'px', height:newH+'px', filter:dfilter});
				if( newAlign ) $(span).css({'float':newAlign});
				if( $(this).parent('a') ) $(span).css({'cursor':'hand'});
				$(this).after(span).remove();
			}
		)
	}
}
if( $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent) )
	$(document).ready(pngFix.init);


// Smooth Scroll Back to Top
var scrollToTop = function(){ $('a[@href$=#top]').click(function(){ backToTop(); return false;} ) };
function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}
$(document).ready(scrollToTop);