
$(document).ready(function() {
	$("div.ref-photos").hide();
	$("#reference li a").click(function () {
			$(this).parent().children("div.ref-photos").toggle();
			return false;
	 });
	 $('.scroll-pane').jScrollPane();
});

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(function() {
	$("a.top").click(function () {
			backToTop();
			return false;
	 });
});


$(document).ready(function() {
	$("#search-input").focus(function () {
	  $(this).css("color","#000000");
	});
	$("#search-input").blur(function () {
	  $(this).css("color","#979797");
	});
	$('#search-input').hover(function () {
        	$(this).css("color","#000000");
    	}, function () {
        	$(this).css("color","#979797");;
   	});
});

$(document).ready(function() {

$('#search-input').focus(function(){
        var defaultText = $(this).val();
        $(this).val('');

        $("#search-input").blur( function () {
        var userInput = $(this).val();

                if (userInput == ''){
                        $(this).val(defaultText);
                }
        });

});
});
var cur = 0;
var tmp = null;
var fadeIn = function() {
	var slides = $('#slider-content .slide');
	var nav = $("#slider-nav ul li a");
	var no 	 = calcNext(cur);
	nav.removeClass('activeSlide');
	$(slides[cur]).fadeOut('slow');
	$(slides[no]).fadeIn('normal');
	$(nav[no]).addClass('activeSlide');
	cur = no;
	tmp = setTimeout("fadeIn()", 5000);
}

var calcNext = function(no) {
	var slides = $('#slider-content .slide');
	return ((slides.length -1) == no) ? 0 : (++no);
}
var calcPrev = function(no) {
	var slides = $('#slider-content .slide');
	return (0 === no) ? (slides.length -1) : (--no);
}
$(document).ready(function() {
    /*$('#slider-content').cycle({
		fx: 'fade',
		timeout: 5000
	});*/
	var nav = $("#slider-nav ul li a");
	$('#slider-content').css('position', 'relative');
	var slides = $('#slider-content .slide');
	slides.css({
		'display': 'none',
		'position': 'absolute',
		'top': 0,
		'left': 0
	});
	$(slides[0]).css('display', 'block');
	$(nav[0]).addClass('activeSlide');
	
	tmp = setTimeout("fadeIn()", 4000);
	
	nav.each(function(i) {
		var i = i;
		$(this).bind('click', function() {
			clearTimeout(tmp);
			slides.stop().fadeOut('fast');
			cur = calcPrev(i);
			fadeIn();		
			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()", 50);
    }
}


$(document).ready(function() {
	$("a.up").click(function () {
			backToTop();
			return false;
	 });
});

