

$htmlmap.initialize({
//	'scheme':'usamap',
	'load':function(){
//		console.log('html initialize: callback function');
	}
});

function custommouseoverfunc(stuff) {
	for (area in stuff.canvas) {
		var $obj=jQuery("area." + area);
		$obj.addClass('thickbox').mouseover(function(){
			jQuery('#map_desc').addClass(jQuery(this).attr('title').replace(/[^a-zA-Z]/g,'_'));
		}).mouseout(function(){
			jQuery('#map_desc').removeClass(jQuery(this).attr('title').replace(/[^a-zA-Z]/g,'_'));
		})
		tb_init($obj);
	}
}

var lastoverlaylink=false;
	
jQuery(document).ready(function(){

		var $base=jQuery('body .current_node_2'),
			$selector='.columns-frontpage .custom-tag-stylizedbox>.infobox',
			$use='.border-ml';
		var $height=0;
		if(!jQuery.browser.msie){
			if($base.length){
				$base.find($selector).each(function(){
					var o=jQuery(this);
					if(o.outerHeight()>$height){
						$height=o.height();
					}
				}).find($use).each(function(){
					var o=jQuery(this),
						myh = o.height();
						p=o.parents($selector),
						h=p.height();
						o.height(myh + $height-p.height());
				});
			}
		}

	//<!-- This is ShareThis code -->
	var switchTo5x=true;
		stLight.options({publisher:'7cff71c7-87d1-4d76-8309-46bd5e06c527'});
	//<!-- End ShareThis -->

	var galleryImages=jQuery('.content-view-full.class-gallery .content-view-children a');
	if(galleryImages.length){
		//removed <div class="info"></div> from display
		jQuery('#page').prepend('<div class="simple_overlay" id="gallery" style="height:300px"><div id="scrollable" style="position:relative;overflow:hidden;height:300px;width:200px;margin:0 auto"><div class="items" style="width:20000em;position:absolute"></div></div><a class="prev">prev</a><a class="next">next</a><img class="progress" src="http://static.flowplayer.org/tools-1.1/img/overlay/loading.gif" /></div>');
		galleryImages.overlay({
			'target':'#gallery',
			'expose':'#333333',
			'onBeforeLoad':function(){
				link = this.getTrigger();
				lastoverlaylink = link;
				link.parents('.content-view-children').find('img').each(function(){
					p = Math.round((300 - $(this).height())/2)
					im = $("<span style='float:left;width:200px;text-align:center;padding-top:"+p+"px'>" + $(this).clone().wrap('<div>').parent().html() + "</span>");
					im.appendTo($("#scrollable .items"));
				});
			},
			'onLoad':function(){
				$("#scrollable").scrollable({
					'onBeforeSeek':function(){$("#scrollable").fadeOut()},
					'onSeek':function(){$("#scrollable").fadeIn()}
				})
				galapi = $("#scrollable").data("scrollable");
				galapi.seekTo(lastoverlaylink.parent('div').index());
			},
			'onClose':function(){
				$("#scrollable .items").empty();
			}
		});
	}

	// interactive map
	jQuery('div.custom-tag-interactive_map .controls li a').click(function(){
		var o=jQuery(this),c=o.parents('div.customtag');
		c.find('>div,.controls li').toggleClass('active');
		return false;
	});

	// for search box default value
	jQuery('.default-value').each(function() {
		var default_value = this.value;
		jQuery(this).focus(function() {
			jQuery(this).addClass('on');
			if(this.value == default_value) {
				this.value = '';
			}
		});
		jQuery(this).blur(function() {
			if(this.value == '') {
				jQuery(this).removeClass('on');
				this.value = default_value;
			}
		});
	});

//	$.historyInit(history_callback);

//	initCufonFonts();

//	topmenu = $('#topmenu-firstlevel');
	jQuery('#topmenu-firstlevel').css('padding-left', (1008-jQuery('#topmenu-firstlevel').width())/2 + 'px');
	
	jQuery('#topmenu-firstlevel ul.submenu').each(function() {
	      if(jQuery(this).parent().outerWidth() >= jQuery(this).width()) {
		jQuery(this).width(jQuery(this).parent().width());
	   }
	});

	jQuery('#topmenu-firstlevel > li').each(function() {
	var prevMenuItem = jQuery(this).prev(), isCurrent = (jQuery(this).hasClass('current')||jQuery(this).hasClass('selected'));
	      if(prevMenuItem.length && isCurrent) {
		prevMenuItem.find('img').css({'visibility':'hidden'});
	   } else if(prevMenuItem.length) {
		jQuery(this).hover(function() {
			prevMenuItem.find('img').css({'visibility':'hidden'});
		},function() {
			prevMenuItem.find('img').css({'visibility':'visible'});
		});
	   }
	});

	jQuery('.home_banner_tag').each(function(){
		var _im = jQuery(this).find('img'), _fixedWidth = (Number(jQuery(this).parent('div').attr('className').replace('banner home-banners-','')%2)==0)?200:185;
		var _width = parseInt((_fixedWidth - _im.width())/2);
//	window.alert(_im.width() + '\n' + (_fixedWidth - _im.width()) + '\n' + _width);
		_im.css("margin-left", _width+'px');
	})
	
	jQuery('#tagline-back').css('opacity', '0.85');
	
	jQuery(".infobox-header").corner('top 10px');
	jQuery(".infobox").corner('bottom 10px');

});
var reloadflag = 0;

//var initCufonFonts=function() {
//	Cufon.replace('#topmenu li a', {'fontFamily':'Gotham','fontSize':'20px','hover': { 'color':'#fefb00'}});
//	Cufon.replace('div.attribute-header h1', {'fontFamily':'Gotham'});
//	Cufon.replace('div.infobox-header h2', {'fontFamily':'Gotham','fontSize':'20px'});
//	Cufon.replace('div.custom-tag-joinus h2', {'fontFamily':'Gotham','fontSize':'20px'});
//	Cufon.replace('div.custom-tag-interactive_map div.lower h2, div.custom-tag-interactive_map div.upper h2', {'fontFamily':'Gotham','fontSize':'1.8em'});
//}

function poi_search() {
	var target = 'ajax_target';
	if (arguments[0]) target = arguments[0];
	var qstring = '?';
	jQuery('#subnav_filter .sendme').each(function(){
		qstring += jQuery(this).attr('name') + '=' + jQuery(this).getValue().replace(/ /g, '+') + '&';
	});
	qstring += 'target=' + target;
	
	var rnode = parseInt(jQuery("#custom_select").getValue());
	if (isNaN(rnode)) rnode = 2;
	
	var loadme = '/layout/set/poi_search/content/view/full/' + rnode + qstring;
	jQuery.historyLoad(loadme.replace(/^.*#/, ''));
	return false;
}

function history_callback(hash) {
	if (hash) {
		var target = hash.split('target=')[1]
		jQuery("#"+target).load(hash, function(responseText, textStatus, XMLHttpRequest){if (textStatus == 'success') paginate(hash);});
	} else if (reloadflag) {
		location.reload(true);
	}
	reloadflag = 1;
}

paginate = function(hash) {
//	rebuild_poi_search_form(hash, true);
	var target = hash.split('target=')[1]
	offset = parseInt(jQuery("#ajax_offset").getValue());
	limit = parseInt(jQuery('#ajax_limit').getValue());
	html = "<div class='pagwrapper'><div class='pagination'>";
	total = parseInt(jQuery('#ajax_results').attr('searchcount'));
	if (limit < total) {
		if (offset > 0) { 
			html += "<a class='next' href='javascript: offsetjump(" + (offset - limit) + ", \"" + target + "\")'>Prev</a>"; 
		} else {
			html += "<span class='next'>Prev</span>";
		}
		var i = 0;
		var myclass = '';
		var inrange = true;
		while (i*limit < total) {
			myclass = ''
			if (i*limit == offset) myclass = " class='current'";
			if (Math.abs(i-(offset/limit)) < 6 || i==0 || (i+1)*limit > total) {
				html += "<a " + myclass + "href='javascript: offsetjump(" + (i*limit) + ", \"" + target + "\")'>" + (i + 1) + "</a>"
				inrange = true;
			} else {
				if (inrange) html += "<span class='pagrange'>. . .</span>";
				inrange = false;
			}
			i++;
		}
		if (offset < (total - limit)) {
			html += "<a class='prev' href='javascript: offsetjump(" + (offset + limit) + ", \"" + target + "\")'>Next</a>"; 
		} else {
			html += "<span class='prev'>Next</span>";
		}
		html += "</div</div>";
		jQuery('#'+target).append(html);
	}
}


offsetjump = function(offset, target) {
	jQuery("#ajax_offset").setValue(offset);
	poi_search(target);
}

function reset_poi_search() {
	if (arguments[0]) jQuery("select[name='cat_select']").setValue(arguments[0]); 
	if (arguments[1]) var subselect = arguments[1];
	jQuery("#cat_keywords").setValue(""); 
	if (jQuery('#cat_select').getValue() != '0') jQuery('#sub_cat_select').load('/Directory/options/' + jQuery('#cat_select').getValue(), "", function(){if (subselect) jQuery('#sub_cat_select').setValue(subselect)})
}


function jslides_callback(i) {
	jQuery('#tagline').html(tag_content[i]);
	jQuery('#image-area-name img').attr('src', banner_names[i].src);
	jQuery('#image-area-name img').css('width', banner_names[i].width + 'px');
	jQuery('#image-area-name img').css('height', banner_names[i].height + 'px');
}

