var window_w = 0;
var r = true;

$(document).ready(function(){

	/* slideshow */

	$('#photos_wrapper').css('visibility', 'visible');

	$('#photos ul').carouFredSel({

		align				: false,
		items				: 10,

		scroll				: {

			items			: 1,
			duration		: 10000,
			timeoutDuration	: 0,
			easing			: 'linear',
			pauseOnHover	: 'immediate'

		}

	});


	$(window).bind('resize.example', function() {

		var nw = $(window).width();

		if (nw < 990) {

			nw = 990;

		}

		$('#slideshow ul').width(nw * 3);
		$('#slideshow ul').parent().width(nw);

	}).trigger('resize.example');



	/* preload images */

	$([

		template_url + '/assets/img/nav_item_about_alt.png',
		template_url + '/assets/img/nav_item_auctions_alt.png',
		template_url + '/assets/img/nav_item_contact_alt.png',
		template_url + '/assets/img/nav_item_home_alt.png',
		template_url + '/assets/img/nav_item_locations_alt.png',
		template_url + '/assets/img/nav_item_resources_alt.png'

	]).each(function() {

		var image = $('<img />').attr('src', this);

	});


	/* responsiveness */

	responsiveness();


	/* navigation */

	$('.nav li').mouseover(function(){

		$('.nav li').removeClass('has_sub_menu');

		if($(this).find('.sub-menu:first').length > 0){

			$(this).addClass('has_sub_menu');

		}

		$(this).find('.sub-menu:first').show();

	}).mouseout(function(){

		$('.nav li').removeClass('has_sub_menu');

		$(this).find('.sub-menu:first').hide();

	});

	$('#nav select').change(function(){

		if($(this).val() !== ''){

			window.location = $(this).val();

		}

	});


	/* fancybox */

	$('.fancybox, .fancybox_video').fancybox({

		cyclic 				: true

	});


	/* search */

	$('#search_submit').mouseover(function(){

		$(this).attr('src', $(this).attr('src').replace('.png', '_alt.png'));

	}).mouseout(function(){

		$(this).attr('src', $(this).attr('src').replace('_alt.png', '.png'));

	});


	/* placeholder fallback */

	$('.placeholder').focus(function(){

		if($(this).attr('placeholder') == $(this).val()){

			$(this).val('').removeClass('placeholder');

		}

	}).blur(function(){

		if($(this).val() == ''){

			$(this).val($(this).attr('placeholder')).addClass('placeholder');

		}

	});


	/* scrollto anchors */

	$('a[href*=#]').click(function() {

		if($('a[name="'+ $(this).attr('href').replace('#','') +'"]').length > 0){

			$('html, body').animate({

				scrollTop: $('a[name="'+ $(this).attr('href').replace('#','') +'"]').offset().top - 96

			}, 1000);

		}

	});


	/* donate */

	$('.donate_amount').click(function(){

		r = true;

		if($(this).data('amount') == 'other'){

			var other = prompt('Please enter your donation amount below.', '5');

			if(other !== null && other !== ''){

				$(this).data('amount', other);

			} else if(parseInt(other) >= 5){

				alert('You must enter a donation amount of atleast $5!');

				r = false;

			} else{

				r = false;

			}

		}

		$('#donate_form_amount').val($(this).data('amount'));

		if(r){

			$('#donate_form').submit();

		}

	});

/*
	$('.amount-other').on('click', function (event) {
		event.preventDefault();
		$('p.oErrLinks').toggleClass('display');
	});
*/

});

function responsiveness(){

	/* responsive videos */

	$('iframe, embed, object').each(function(){

		if($(this).is(':visible')){

			$(this).width($(this).parent().width()).height(Math.ceil($(this).width() / 1.777));

		}

	});


	/* 1200px */

	if($(window).width() >= 1200){


	/* 960px */

	} else if($(window).width() < 1200 && $(window).width() > 768){



	/* tablet */

	} else if($(window).width() < 768 && $(window).width() > 480){


	/* mobile */

	} else{


	}

}

$(window).resize(function(){

	/* responsiveness */

	responsiveness();

});

$(window).scroll(function(){

});

$(window).error(function(){

	/* make the browser ignore errors */

	return true;

});