$().ready(function(){
	if ($('#carousel')[0]) {
		$('#carousel #slides').cycle({
			timeout: 7500,
			pager: '#pager'
		});
		console.log('hello');
	}
	
	//open external links in new browser
	$('a[rel=external]').each(function() {
		$(this).removeAttr('rel');
		$(this).attr('target', '_blank');
	});
	
	//make the drop-down select of cat/dogs work
	$('#select-pet').change(function(){
		if ($(this).val() == 'cat') {
			window.location = '/adoptable-cats/';
		}
		else if ($(this).val() == 'dog') {
			window.location = '/adoptable-dogs/';
		}
	});
	
	//show the 1st option for the archives
	//$('li.jaw_years:first a:first').click();
	
	//lightboxes
	$('.fancybox').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
	$('.video').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
		'type'			:	'iframe',
		'width'			:	580,
		'height'		:	360
	});
	
	
	//run the google map on the contact page.
	if ($('#contact-google-map')[0]) {
		showMap();
	}
	
	//if we're on the donation page, update the amount
	$('#donation-paypal input[type=radio]').click(function(){
		if ($(this).val() != 0) {
			$('#donate-amount').val($(this).val());
		}
		else {
			$('#donate-amount').val('0.00');
		}
	});
	$('#a3_open_text').blur(function(){
		if ($(this).val() > 0) {
			$('#a3_open').attr('checked', 'checked');
			$('#donate-amount').val($(this).val());
			$(this).focus();
		}
	});
	
	//donation page sponsor an animal
	$('#sponsor-paypal input[type=radio]').click(function(){
		$('#sponsor-amount').val($(this).val());
		if ($(this).val() == 25) {
			$('#item-name').val('CCHS 1-Month Pet Sponsorship');
		}
		else if ($(this).val() == 75) {
			$('#item-name').val('CCHS 3-Month Pet Sponsorship');
		}
	});
	$('.sponsor-animal').click(function() {
		$('#tab-cats div, #tab-dogs div').removeClass('sponsor-animal-selected');
		$(this).addClass('sponsor-animal-selected');
		val = $(this).children('p').html();
		$('#item-number').val(val);
	});
	$('.sponsor-animal').hover(function(){
		$(this).addClass('sponsor-animal-hover');
	}, function(){
		$(this).removeClass('sponsor-animal-hover');
	});
	
	//on the donation page, let's hide the cats
	if ($('#tab-cats')[0]) {
		$('#tab-cats').hide();
	}
	$('.tabs a').click(function(){
		if ($(this).attr('href') == '#tab-cats') {
			$('#tab-dogs').hide();
			$('#tab-cats').show();
		}
		else {
			$('#tab-cats').hide();
			$('#tab-dogs').show();
		}
		$('.tabs a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	});
	
	//run the fancybox on the flickr images
	$('.slickr-flickr-gallery ul li a').fancybox();
	
	//add url hashes to the url when you click on a share-this button so the links work.
	//figured out how to do this with "share this"
	/*$('.shareme>span').click(function(){
		petid = $(this).parent().parent().parent().attr('id');
		console.log(petid);
		window.location.hash = petid;
	});*/
});

function showMap() {
	//var myLatlng = new google.maps.LatLng(47.102829,-88.56788);
	var myLatlng = new google.maps.LatLng(47.10465,-88.519112);
    var myOptions = {
      zoom: 13,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("contact-google-map"), myOptions);
    
    var marker = new google.maps.Marker({
        position: myLatlng, 
        map: map,
        title:"Copper Country Humane Society"
    });
}
