$(document).ready(function(){
	
	/* $('.scroll').scrollbarPaper(); */
	var docHeight = $(document).height();
	var windowHeight = $(window).height();

	$('.scroll').css('height', windowHeight-190 +'px');
	
	$(window).resize(function() {
		var docHeight = $(document).height();
		var windowHeight = $(window).height();
		$('.scroll').css('height', windowHeight-190 +'px');
	});

	
	$('#slideshow').cycle({ 
		fx:     'fade', 
		speed:  'slow', 
		timeout: 3500, 
		pager:  '#slide-nav' 
	});
	
	$('#news-list li div.news-title a').click(function(){
		if($('.news-content')) {
			$('.news-content').slideUp('fast', function(){
				var parent = $('.news-content').parent();
				$(parent).removeClass('current-news');
				
				$('.news-meta', parent).removeClass('hide').slideDown('fast');
				$('.news-content').remove();
			});
		}
		else $('.hide').removeClass('hide').slideDown('fast');
		
		url = $(this).attr('href');
		vars = getUrlVars(url);
		
		target = $(this).closest('li');
		$.get('news-functions.php', {'id': vars['id']}, function(data){
			$('.news-meta', target).addClass('hide');
			$(target).addClass('current-news');
			$(target).append('<div class="animating">' + data + '</div>');
			$('.animating', target).css('display', 'none').slideDown('fast', function(){
				$(this).addClass('news-content').removeClass('animating')
			});
		});
		
		return false;
	});
	
	$('#contact-form input[type="submit"]').click(function(){
		var formError = false;
		$('#contact-form :input.required').each(function(key, value){
			if(value.value == '') {
				$(value).addClass('form-error');
				formError = true;
			}
			else $(value).removeClass('form-error');
		});
		if (formError) return false;
	});
});

function getUrlVars(url) {
    var vars = [], hash;
    var hashes = url.slice(url.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
