/*----------------------------------------
CCHPC Javascript
Author: Mitch Dunaway
Last Updated: February 10, 2012
Last Updated by: Kari Grooms
(c) 2011 Affiniscape, Inc.
All Rights Reserved. This JavaScript file must not be reproduced without the express written permission of Affiniscape, Inc.
For questions regarding licensing or setup please contact Affiniscape, projects @ affiniscape dot com
----------------------------------------*/

var j = jQuery.noConflict();
j(document).ready(function($){
	
	// Clickable Logo
    $('body').addClickableLogo({
        name: 'Colorado Center for Hospice & Palliative Care',
        url: 'http://www.cochpc.org'
    });
    
    /* m360 Custom Map	
	$('#map-image').attr('src','/global/css/imgs/trans1.gif');
	$('#program-map area').hover(function(){
		var a = $(this).attr('alt');
		$('#map-image').attr('src','/associations/12609/imgs/map/'+ a +'.png');
		$('#'+ a).stop(true,true).fadeIn();
	},function(){
		$('#map-image').attr('src','/global/css/imgs/trans1.gif');
		$('#'+ a).stop(true,true).hide();
	}).click(function(e){
		e.preventDefault();
		var a = $(this).attr('alt');
		selectSearch(a);
	});*/
	
	// m360 Custom Map
	$('#program-map').bind('mouseout',function(){
		$('.popup').stop(true,true).hide();
		$('#map-image').attr('src','/global/imgs/trans1.gif');
	}).children('area').bind('mouseover',function(){
		var id = $(this).attr('alt');
		$('.popup').stop(true,true).hide();
		$('body:not(.ie) #'+id).stop(true,true).delay(250).fadeIn();
		$('body.ie #'+id).stop(true,true).show();
		$('#map-image').attr('src','/associations/12609/imgs/map/'+id+'.png');
	});
	$('.popup').each(function(){
		$(this).append('<span class="tail"></span>');
	}).hover(function(){
		var id = $(this).attr('id');
		$(this).show();
		$('#map-image').attr('src','/associations/12609/imgs/map/'+id+'.png');
	},function(){
		$(this).stop(true,true).hide();
		$('#map-image').attr('src','/global/imgs/trans1.gif');
	});
	$('.popup a').click(function(e){
		e.preventDefault();
		var county = $(this).html();
		selectSearch(county);
		console.log(county);
	});
	
	if ($('#ctl00_cph1_CustomSearch1_pnlResults').length){
		$('#program-search').hide();
		$('p').hide();
	};
						   
});

function selectSearch(county) {
	var myInput = document.getElementsByName("ctl00$cph1$CustomSearch1$dynamicfield_1_0_7429")[0];
	for (i = 0; i < myInput.options.length; i++) {
		if (myInput.options[i].value.toLowerCase() == county.toLowerCase()) {
			myInput.options.selectedIndex = i;
		}
	}
	if (myInput.options.selectedIndex > 0) {
		document.getElementById("ctl00_cph1_CustomSearch1_btnSearch").click();
	} else {
		alert('There are currently no listings for '+ county +' county.');
	}
}

