jQuery(function($){

	oldHeight = $('#slide-content').height();
	$('#slide-content').slideUp(1);
	$('#main-content').animate({'marginTop':oldHeight+50},1);
	$(this).addClass('up-arrow').removeClass('down-arrow');
	$('.show-image').html('Show Text');

	setTimeout(function(){
		$('.show-image').trigger('click');
	},1500)

/*	$('#menu-header-nav li:not(".menu-item-139") a').click(function(){
		if($(this).parent().children('ul').size() < 1){
			return true;
		} else {
			if($(this).parent().children('ul:visible').size() < 1){
				$('.on').removeClass('on').parent().children('ul').slideUp();

				$(this).parent().children('a').addClass('on');
				$(this).parent().children('ul').slideDown();
			} else {
				$(this).parent().children('a').removeClass('on');
				$(this).parent().children('ul').slideUp();
			}
			return false;
		}
	})
*/

	if ($('.quote-item').size()>0) {
		setTimeout(function(){
			$('.quote-item:first').fadeIn(1000);
		},1000);


		if ($('.quote-item').size()>1) {
			(function loopsiloop(){
				setTimeout(function(){
					$('.quote-item:visible').fadeOut(1000)
					if($('.quote-item:visible').next('.quote-item').size() >0){
						$('.quote-item:visible').next('.quote-item').fadeIn(1000);
					} else {
						$('.quote-item:first').fadeIn(1000);
					}
					loopsiloop(); 
				}, 10000);
			})();
		}
	};

	$('#header-right li > div').hide();

	$('#header-right li h3:not(".link-needed")').click(function(e){
		e.preventDefault();
		if($(this).parent().children('div:visible').size() < 1){
			$('#header-right').find('.on').removeClass('on').parent().children('div').slideUp();

			$(this).parent().children('div').slideDown();
			$(this).addClass('on');
		} else {
			$(this).parent().children('div').slideUp();	
			$(this).removeClass('on');
		}
	})

	$('.show-image').click(function(e){
		e.preventDefault();
		if($('#slide-content:visible').size() < 1){
			$('#slide-content').slideDown(500);
			$('#main-content').animate({'marginTop':50},500);
			$(this).addClass('down-arrow').removeClass('up-arrow');
			$('.show-image').html('Show Image');
		} else {
			oldHeight = $('#slide-content').height();
			$('#slide-content').slideUp(500);
			$('#main-content').animate({'marginTop':oldHeight+50},500);
			$(this).addClass('up-arrow').removeClass('down-arrow');
			$('.show-image').html('Show Text');
		}
	})

	$('.show-offers').click(function(e){
		e.preventDefault();
		if($('#rotating-offers').height() == 0){
			$('#rotating-offers').animate({'height':oldOfferHeight});
			$(this).addClass('down-arrow').removeClass('up-arrow');
		} else {
			oldOfferHeight = $('#rotating-offers').height();
			$('#rotating-offers').animate({'height':0});
			$(this).addClass('up-arrow').removeClass('down-arrow');
		}
		if($('#google-map').height() == 0){
			$('#google-map').animate({'height':oldOfferGoogleHeight});
			$(this).addClass('down-arrow').removeClass('up-arrow');
		} else {
			oldOfferGoogleHeight = $('#google-map').height();
			$('#google-map').animate({'height':0});
			$(this).addClass('up-arrow').removeClass('down-arrow');
		}
	})

	if ($('.offer-item').size()>5) {
		itemWidth = $('.offer-item').width() + parseInt($('.offer-item').css('margin-right').replace('px',''));
		$('#rotating-offers ul').width($('.offer-item').size() *  itemWidth);
		
		$('#arrows .left-arrow').click(function(e){
			e.preventDefault()
			if(parseInt($('#rotating-offers ul').css('marginLeft').replace('px','')) < 25) {
				$('#rotating-offers ul:not(:animated)').animate({'marginLeft':'+='+ itemWidth + 'px'})
			}
		});
		$('#arrows .right-arrow').click(function(e){
			e.preventDefault()
			if(parseInt($('#rotating-offers ul').css('marginLeft').replace('px','')) > -($('#rotating-offers ul').width() - (itemWidth * 5)-25)) {
				$('#rotating-offers ul:not(:animated)').animate({'marginLeft':'-='+ itemWidth + 'px'})
			}
		});
	};
	if ($('.offer-item').size()<=5) {
		$('#arrows').remove();
	}

	if ($('#gallery-thumbs-container').size()>0) {
		itemGalleryWidth = $('ul.gallery li').width() + parseInt($('ul.gallery li').css('margin-right').replace('px',''));
		
		$('#arrows .left-arrow').click(function(e){
			e.preventDefault()
			if(parseInt($('#gallery-thumbs-container ul').css('marginLeft').replace('px','')) < 25) {
				$('#gallery-thumbs-container ul:not(:animated)').animate({'marginLeft':'+='+ itemGalleryWidth + 'px'})
			}
		});
		$('#arrows .right-arrow').click(function(e){
			e.preventDefault()
			if(parseInt($('#gallery-thumbs-container ul').css('marginLeft').replace('px','')) > -($('#gallery-thumbs-container ul').width() - (itemGalleryWidth * 8)-25)) {
				$('#gallery-thumbs-container ul:not(:animated)').animate({'marginLeft':'-='+ itemGalleryWidth + 'px'})
			}
		});
	}

	if($('#experience').size()>0){
		itemExpWidth = $('.experience-item').width() + parseInt($('.experience-item').css('margin-right').replace('px',''));
		$('#experience').width($('.experience-item').width()*$('.experience-item').size());
		
		$('#experience-arrows .left-arrow').click(function(e){
			e.preventDefault()
			if(parseInt($('#experience').css('marginLeft').replace('px','')) < 0) {
				$('#experience:not(:animated)').animate({'marginLeft':'+='+ itemExpWidth + 'px'})
			}
		});
		$('#experience-arrows .right-arrow').click(function(e){
			e.preventDefault()
			if(parseInt($('#experience').css('marginLeft').replace('px','')) > -($('#experience').width() - itemExpWidth)) {
				$('#experience:not(:animated)').animate({'marginLeft':'-='+ itemExpWidth + 'px'})
			}
		});
	}

	$('.current-menu-item').children('a').addClass('on').parent().parent().slideDown().parent('li').children('a').addClass('on');
	$('.current-menu-item').children('ul').slideDown();
//gallery
$('#gallery-main-image').propGallery();


    $('input[type=text]').each(function(){
        $(this).attr('title',$(this).val());
    })

    var clearMePrevious ='';

    // clear input on focus
    $('input[type=text]').focus(function () {
        if ($(this).val() == $(this).attr('title')) {
            clearMePrevious = $(this).val();
            $(this).val('');
        }
    });

    // if field is empty afterward, add text again
    $('input[type=text]').blur(function () {
        if ($(this).val() == '') {
            $(this).val(clearMePrevious);
        }
    });
	$('#background-images').css({
		'height': $(document).height()
	})

	if ($('.gallery').size()>0) {
		$('.gallery img').each(function(){
			imgLeft = parseInt(($(this).width() - $(this).parent().parent().width()) / 2);
			imgTop = parseInt(($(this).height() - $(this).parent().parent().height()) / 2);
			imgRight = parseInt(imgLeft + $(this).parent().parent().width());
			imgBottom = parseInt(imgTop + $(this).parent().parent().height());
			$(this).css({
				'clip':'rect('+imgTop+'px,'+imgRight+'px,'+imgBottom+'px,'+imgLeft+'px)',
				'left':-imgLeft+'px',
				'top':-imgTop+'px'
			})
		})
		$('#arrows').after('<div id="image-number">'+$('.gallery img').size()+'</div>')
	}


	if ($('.home').size()>0) {
		if ($.cookie("homeCookie")==null) {
			$.cookie('homeCookie', '1');

			$('#menu-item-534 ul').hide();
		};
	};
	$( ".datepicker" ).datepicker({
		"dateFormat":"yy-mm-dd"
	});

	if ($('#experiences-container').size()>0) {
		var experienceHeight = 0;
		var itemExpWidth = ($('.experience-item:first').width() + parseInt($('.experience-item:first').css('margin-right')));

		$('.experience-item').each(function(){
			if($(this).height() > experienceHeight) {
				experienceHeight = $(this).height();
			}
		});
		$('#experiences-container').find('#slide-content').css({
			'width': ($('.experience-item').size() * ($('.experience-item:first').width() + parseInt($('.experience-item:first').css('margin-right'))))
		});
		$('#experiences-container, .experience-item').height(parseInt(experienceHeight));

		$('#experience-arrows .left-arrow').click(function(e){
			e.preventDefault()
			if(parseInt($('#slide-content').css('left').replace('px','')) < 0) {
				$('#slide-content:not(:animated)').animate({'left':'+='+ itemExpWidth + 'px'})
			}
		});
		$('#experience-arrows .right-arrow').click(function(e){
			e.preventDefault()
			if(parseInt($('#slide-content').css('left').replace('px','')) > -($('#slide-content').width() - (itemExpWidth * 3))) {
				$('#slide-content:not(:animated)').animate({'left':'-='+ itemExpWidth + 'px'})
			}
		});
	};
})//end jquery

