function loadPage(url){
	if (url){
		if (!$('#content').html()){
			$('#content').hide().load(url, function(){
				$('#dcontent').fadeOut('slow', function(){
					$('#content').fadeIn('slow');
					$('#dcontent').html('');
					initLinks();
					initJS(url);
				});
			});
		} else {
			$('#dcontent').hide().load(url, function(){
				$('#content').fadeOut('slow', function(){
					$('#dcontent').fadeIn('slow');
					$('#content').html('');
					initLinks();
					initJS(url);
				});
			});
		}
	}
}
var demoSlider_2, effectsDemo2;
function initJS(url){
	switch (url){
		case 'home.html':
            $('#demo2').thumbnailSlider({
                thumb_width    : 130,
                thumb_height: 90,
                easing        : 'easeOutExpo',//easeInBack
                speed        : 600
            });
            $('.ts_container a').click(function(){
                var imgName = $(this).attr('href');
                if (!$('#dbg').is('img')){
                    $('#bg').clone().attr({id: 'dbg', src: 'img/spacer.gif'}).hide().insertAfter($('#bg'));
                }
                if ($('#bg').attr('src') == 'img/spacer.gif'){
                    $('#bg').attr('src', imgName).ready(function(){
                        $('#bg').fadeIn('slow');
                        $('#dbg').fadeOut('slow', function(){
                            $('#dbg').attr('src', 'img/spacer.gif');
                        });
                    });
                }
                if ($('#dbg').attr('src') == 'img/spacer.gif'){
                    $('#dbg').attr('src', imgName).ready(function(){
                        $('#dbg').fadeIn('slow');
                        $('#bg').fadeOut('slow', function(){
                            $('#bg').attr('src', 'img/spacer.gif');
                        });
                    });
                }
                return false;
            });
            $("#tS1").thumbnailScroller({ 
                scrollerType:"hoverAccelerate", 
                scrollerOrientation:"horizontal", 
                scrollSpeed:2, 
                scrollEasing:"easeOutCirc", 
                scrollEasingAmount:600, 
                acceleration:4, 
                scrollSpeed:800, 
                noScrollCenterSpace:10, 
                autoScrolling:0, 
                autoScrollingSpeed:2000, 
                autoScrollingEasing:"easeInOutQuad", 
                autoScrollingDelay:500 
            });
            $('#newsSlider').loopedSlider({
                autoHeight: 330
            });
			break;
        case 'about.html':
            $('.scroll-pane').jScrollPane({showArrows: true});
            break;
        case 'services.html':
            $('.scroll-pane').jScrollPane({showArrows: true});
            break;
        case 'contacts.html':
        	$('.scroll-pane').jScrollPane({showArrows: true});
        	break;
	}
}
function initLinks(){
	$('.aj').click(function(){
		loadPage($(this).attr('href'));
		return false;
	});
}
function debug(str) {
	if(window.console && window.console.log && jQuery.browser.mozilla) {
	  console.log(str);
	} else {
	  $('#debug').show().val($('#debug').val() + str +'\n');
	}
}
$(document).ready(function(){
	loadPage('home.html');
	$('.logo').click(function(){
		loadPage($(this).attr('href'));
		return false;
	});
});
