var y = 0;
var old_width;
var delta = 0;
var new_delta;
$(document).ready(function() {
	
	$('div.wpcf7-response-output').replaceWith('');
	$('.wpcf7').prepend('<div class="wpcf7-response-output wpcf7-display-none"></div>');
	
	$('UL#menu-main-menu>LI:last').addClass('last');
	$('UL#menu-main-menu UL LI:last').addClass('sub-last');
	$('UL#menu-footer-bottom LI:last, UL#menu-footer-top LI:last').addClass('last');
	

	$('#slider').cycle({ 
		fx: 'scrollDown',
		speedIn: 900,
		speedOut: 900,
		timeout: 7000,
		continuous: 0,
		pager: '.controls' 
	})
	$('.controls A').each(function(){y = y + 1;});
	var max = $('.controls A').width();
	max = (max + 10) * y;
	$('.controls').width( max );
	$('a.read').click(function(){
		if ($(this).html() == 'read more'){
			$(this).prev().show();
			$(this).html('hide more');
		} else {
			$(this).prev().hide();
			$(this).html('read more');
		}
		
		return false;
	});
	
	
	/*  FOOTER  */
	var old_height = $(window).height();
	var header_h = $('#header').height();
	var content_h = $('#content').height();
	var footer_h = $('#footer').height();
	var all_h = header_h + content_h +footer_h + 17;
	if (old_height > all_h){
		delta = old_height - all_h;
		$('#footer').css('marginTop' , delta );
	}

	window.onresize = function() {
		var window_w = $(window).height();
		if (old_height > window_w){
			var xy = (old_height - window_w);
			new_delta = delta - xy;
			if (delta < 30){
				$('#footer').css('marginTop' , 30 + 'px' );
				} else{
				$('#footer').css('marginTop' , new_delta );
				}
			}else 
			if (old_height < window_w){
				var xy = (window_w - old_height);
				new_delta = delta + xy;
				/*console.log(new_delta);*/
				if (delta < 30){
				$('#footer').css('marginTop' , 30 + 'px' );
				} else{
				$('#footer').css('marginTop' , new_delta );
				}
			
			}	
		old_height = window_w;
		delta = new_delta;
	}	
});

