// JavaScript Document

function checkContact(){
	var checkPassed = true;
	document.getElementById('nameField').style.color = 'black';
	document.getElementById('emailField').style.color = 'black';
	document.getElementById('commentsField').style.color = 'black';
	document.getElementById('titleField').style.color = 'black';
	document.getElementById('cityField').style.color = 'black';
	
	if(document.getElementById('name').value == ''){
		checkPassed = false;
		document.getElementById('nameField').style.color = 'red';
	}
	
	if(document.getElementById('email').value == ''){
		checkPassed = false;
		document.getElementById('emailField').style.color = 'red';
	}
	
	if(document.getElementById('comments').value == ''){
		checkPassed = false;
		document.getElementById('commentsField').style.color = 'red';
	}
	
	if(document.getElementById('type').value == 'endorsements'){
		if(document.getElementById('city').value == ''){
			checkPassed = false;
			document.getElementById('cityField').style.color = 'red';
		}
		
		if(document.getElementById('title').value == ''){
			checkPassed = false;
			document.getElementById('titleField').style.color = 'red';
		}
	}
	
	if(checkPassed == false) document.getElementById('errorMessage').innerHTML = 'Please fill in all required fields below.'; 
	
	return checkPassed; }
	
function showAddl(value){
	if(value == 'general'){
		document.getElementById('addlFields').style.display = 'none';
	}else{
		document.getElementById('addlFields').style.display = 'block';
	}
}

function showAnimalName(){
	$("#animalsCircle a").hover(
		function(){ //alert('fire');
			var bkgImage = $(this).attr("href"); //console.log($(this).find("img").attr('src'));
			$(this).find("img").attr('src','/images/animals/' + bkgImage.substring(15) + '-on.png'); //console.log($(this).find("img").attr('src'));
			bkgImage = 'url(images/animals/' + bkgImage.substring(15) + '.gif)'; //console.log(bkgImage);
			$("#animalsCircle").css({"background-image":bkgImage});
		},
		function (){
			var bkgImage = $(this).attr("href");
			$(this).find("img").attr('src','/images/animals/' + bkgImage.substring(15) + '.png');
			$("#animalsCircle").css({"background-image":"none"});
		}
	);
	
	$("#animalsCircle a").click(function(){
		window.open($(this).attr("href"), 'animalsPop' ,'width=469,height=579,resizable=yes,scrollbars=no');
		return false;
	});
}

function imageTitles(){
	$("p.endorsementImages img").hover(
		function(){
			$('#imageCaption').html($(this).attr("title"));
		},
		function (){
			$('#imageCaption').html('');
		}
	);
}

function returnPolicy(){
	window.open ('return-policy.htm', 'quad' ,'width=470,height=510,resizable=yes,scrollbars=yes');
	return false; }

function termsOfUse(){
	window.open ('/terms-of-use.htm', 'quad' ,'width=570,height=610,resizable=yes,scrollbars=yes');
	return false; }

function privacyPolicy(){
	window.open ('/privacy-policy.htm', 'quad' ,'width=570,height=610,resizable=yes,scrollbars=yes');
	return false; }

function intlOrders(){
	window.open ('/intl-orders.htm', 'quad' ,'width=570,height=610,resizable=yes,scrollbars=yes');
	return false; }

function specialMarkets(){
	window.open ('/special-markets.htm', 'quad' ,'width=570,height=610,resizable=yes,scrollbars=yes');
	return false; }

// starting the script on page load
$(document).ready(function(){
	showAnimalName();
	imageTitles();
	$('a.gallery-wrap').qtip({
		content: 'A &ldquo;gallery-wrapped&rdquo; canvas is stretched over a hidden frame and finished on all sides for decorative wall display-no need for a standard picture frame! ',
		show: 'mouseover',
		hide: 'mouseout',
		position: {
      corner: {
         target: 'topRight',
         tooltip: 'bottomLeft'
      }
   	},
		style: {
			width: 200,
      padding: 5,
      background: '#ffffff',
      color: 'black',
      textAlign: 'center',
      border: {
         width: 5,
         radius: 8,
         color: '#000000'
      },
      tip: 'bottomLeft',

			name: 'light' // Inherit from preset style
		}
	})
	$("a#pigs").fancybox({
		'titleShow' : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
});
