


Cufon.replace('#nav li');
Cufon.replace('h4');


var scrSpeed = 1000;

$(document).ready( function () {
	
	
	$(window).scroll(function(){
		if ($(window).scrollLeft() > 0) {
			$("#back").fadeIn("slow");
		}
		else {
			$("#back").fadeOut("slow");
		}
	});
    
   
   
	$('#nav1').click(function(){
		$.scrollTo( "#m1", scrSpeed, { axis:'x', offset: { left: -200 } } );
	});
    
	$('#nav2').click(function(){
		$.scrollTo( "#m2", scrSpeed, { axis:'x', offset: { left: -200 } } );
	});
    
	$('#nav3').click(function(){
		$.scrollTo( "#m3", scrSpeed, { axis:'x', offset: { left: -200 } } );
	});
    
	$('#nav4').click(function(){
		$.scrollTo( "#m4", scrSpeed, { axis:'x', offset: { left: -200 } } );
	});
    
	$('#nav5').click(function(){
		$.scrollTo( "#m5", scrSpeed, { axis:'x', offset: { left: -200 } } );
	});
    
	
	
	
	shortcut.add("Home",function() {
		$.scrollTo( 0, scrSpeed, { axis:'x' } );
	});
	shortcut.add("End",function() {
		$.scrollTo( "#container div:last", scrSpeed, { axis:'x' } );
	});
	shortcut.add("Right",function() {
		$.scrollTo( '+=500px', 500, { axis:'x' } );
        },
	 	{ 'disable_in_input':true
	});
	shortcut.add("Left",function() {
		$.scrollTo( '-=500px', 500, { axis:'x' } );
         },
	 	{ 'disable_in_input':true
	});
    shortcut.add("Up",function() {
		$.scrollTo( '-=500px', 500, { axis:'x' } );
         },
	 	{ 'disable_in_input':true
	});
    shortcut.add("Down",function() {
		$.scrollTo( '+=500px', 500, { axis:'x' } );
        },
	 	{ 'disable_in_input':true
	});
    shortcut.add("B",function() {
		$.scrollTo( 0, scrSpeed, { axis:'x' } );
        },
	 	{ 'disable_in_input':true
	});
	
	
	
	$('#back a').click(function(){
		$.scrollTo( 0, scrSpeed, { axis:'x', easing:'easeOutQuint' } );
	});
	
	
	
	
	(function($) {
		$.fn.cfadeIn = function(speed, callback) {
			$(this).fadeIn(speed, function() {
				if(jQuery.browser.msie)
					$(this).get(0).style.removeAttribute('filter');
				if(callback != undefined)
					callback();
			});
		};
		$.fn.cfadeOut = function(speed, callback) {
			$(this).fadeOut(speed, function() {
				if(jQuery.browser.msie)
					$(this).get(0).style.removeAttribute('filter');
				if(callback != undefined)
					callback();
			});
		};
	})(jQuery);
    
    
    
    var excerpt = $("#blog a").next("p");
    var dTop = - excerpt.height();
    excerpt.css('top', dTop-80);
    $("#blog a").hover(function() {
		excerpt.animate({opacity: "show", top: dTop - 60}, "slow");
	}, function() {
		excerpt.animate({opacity: "hide", top:dTop - 70}, "fast", function () {
               // $("#blog a").unbind('mouseover').unbind('mouseout');   
        });
	});
    
    
    
    $('#gallery ul').hide();
    $('#loading').remove();
    $('#gallery').append('<img src="/images/bullet-loading.gif" id="loading" />');
    $('#loading').fadeIn('normal'); 
    $('#gallery ul').load('/gallery.cfm li', {f : 'all'}, function () {
    	var galWidth = (Math.ceil($('#gallery ul').children().size() / 3) * 175) - 15;
        $('#gallery').width(galWidth);
        $("div#container").setWidth();
        if(jQuery.browser.msie)	
        	$('#gallery').prev('h2').width(galWidth);
        $('#loading').fadeOut('normal', function () {
        	$('#gallery ul li a, .video').nyroModal();
        	$('#gallery ul').show();
        });
    });
    
    $('.filter a:not(.video), .showall').click( function() {
    	$('#gallery ul').hide();
        $('#loading').remove();
        $.scrollTo( "#m1", 800, { axis:'x', offset: { left: -35 } } );
        var str = $(this).text();
        $('h2 em').html('{ ' + str + ' }');
        $('#gallery').append('<img src="/images/bullet-loading.gif" id="loading" />');
        $('#loading').fadeIn('normal');
        var f =  $(this).attr('rel');
        $('#gallery ul').load('/gallery.cfm li', {f : f}, function () {
            galWidth = (Math.ceil($('#gallery ul').children().size() / 3) * 175) - 15;
            $('#gallery').animate({width: galWidth}, 800, function () {
            	$('#loading').fadeOut('normal', function () {
                	$('#gallery ul li a, .video').nyroModal();
                    $('#gallery ul').show();
                });
            });
            if(jQuery.browser.msie)
            	$('#gallery').prev('h2').animate({width: galWidth}, 800);
        });
    });
    
    
    	$("#helper").effect("pulsate", { times:3 }, 1000);
        $("#helper a").click(function() {
        	var loc = "#" + $(this).attr("rel");
            $.scrollTo(loc, 1000, { axis:'x', offset: { left: -35 }} );
        });
        $(window).scroll(function(){
        	$("#helper").fadeOut("slow");
        });
        
    
    	
    $.fn.setWidth = function() {
    	var totalWidth = 1650
        $('div#container').children(".module").each(function() {
            totalWidth = totalWidth + $(this).width();	
        });
        $("#container").width(totalWidth);
    }
    
    $("div#container").setWidth();    
    
					
});

