if (typeof PGE=="undefined"||!PGE){var PGE={};}
PGE.hybrid = {}; //for Module specific methods, vars, and objects

(function ($) {

	var ua = navigator.userAgent;
	var ie = /MSIE/.test(ua) && ua.replace(/.*?MSIE (.).*/,"$1");
	var ff = /Firefox/.test(ua) && ua.replace(/.*?Firefox\/(.)\.(.).*/,"$1_$2");
	var safari = /Safari/.test(ua) && ua.replace(/.*?Version\/(.).*/,"$1");
	var chrome = /Chrome/.test(ua) && ua.replace(/.*?Chrome\/(.).*/,"$1");
	var opera = /Opera/.test(ua) && ua.replace(/.*?Opera\/(.).*/,"$1");
	document.getElementsByTagName("html")[0].className="js"+(ie?" ie ie"+ie : ff?" ff ff"+ff : chrome?" chrome chrome"+chrome : safari?" safari safari"+safari : opera?" opera opera"+opera : "");

	/*************************************
	PNG Fix
	*************************************/
	PGE.hybrid.pngFix = function () {
		DD_belatedPNG.fix('.png_fix');
	};
	
	/*************************************
	HYBRID - ACCORDION
	*************************************/
    PGE.hybrid.initAccordions = function () {

        // accomodate non-JS users: by default all accordian elements open, then use JS to hide all but the first
        $('.accordion h3.hdr-open').each(function(index) {if (index!=0) $(this).removeClass('hdr-open')});
        $('.accordion div.content').each(function(index) {if (index!=0) $(this).removeClass('open')});

        $('.accordion li.expand-all').click(function () {
            $('.accordion div.content').addClass('open').removeClass('close');
            $('.accordion h3').addClass('hdr-open').removeClass('hdr-closed');
            return false;
        });
        $('.accordion li.collapse-all').click(function () {
            $('.accordion div.content').addClass('close').removeClass('open').css('display','none');
            $('.accordion h3').addClass('hdr-closed').removeClass('hdr-open');
            return false;
        });
        $('.accordion h3').click(function () {
    
            if ($(this).hasClass('hdr-open')) {
                $(this).addClass('hdr-closed').removeClass('hdr-open');
            } else {
                $(this).addClass('hdr-open').removeClass('hdr-closed');
            }
    
            $(this).next('div.content').slideToggle(300).toggleClass('open');
            return false;
        });
    };
	
	/*************************************
	HYBRID - INITMODAL
	@desc	creates modal window from hybrid template
	@auth	m1k6, Morye Kim
	*************************************/
	PGE.hybrid.initModal = function() {
		var modal_id = "wmodal"; // dom id for modal container
		var trigger_class = ".pge_modal"; // id for dom that triggers modal
		var modal = "<div class=\"jqmWindow\" id=\""+modal_id+"\"><div class=\"box-close\"><a class=\"jqmClose png_fix\" href=\"javascript:void(0)\"><span>Close</span></a></div><div class=\"modal_content\"></div></div>";
		$('#main_column').after(modal);
		var on_modal_open = function(hash){ hash.w.fadeIn('2000'); 	}; //hash.w.css('opacity',0.88).fadeIn('2000');
		var on_modal_close = function(hash){ hash.w.fadeOut('2000',function(){ hash.o.remove(); }); setTimeout(function(){$("#"+modal_id+" .modal_content").html('')},500); };
		$("#"+modal_id).jqm({trigger:trigger_class, onShow:on_modal_open, onHide:on_modal_close });
		$(trigger_class).click(function(){
			$("#"+modal_id+" .modal_content").load($(this).attr('href'), function(response, status, xhr) {
			  if (status == "error") {
				var msg = "Unable to load the content: ";
				$("#"+modal_id+" .modal_content").html("<p>"+msg + xhr.status + " " + xhr.statusText+"</p>");
			  }
			});
		});
	};
	
	/*************************************
	HYBRID - CENTER_MODAL
	@desc	place the modal window in the center of the screen
	@param	id - id or class of dom window to center, width - width of dom window
	@auth	m1k6, Morye Kim
	*************************************/
	PGE.hybrid.center_modal = function(id,width) {
		if (window.innerHeight) { //@hack for browsers other than ie6
		  $(id).css("left",(($(window).width()-width)/2) + "px");
		} else { //@hack for ie6
		  $(id).css("left",(document.documentElement.offsetWidth-width)/2 + "px");
		}
	};
	
	/*************************************
	HYBRID - COUNTY SEARCH
	@desc	Create options for County dropdown and returns result when a county is selected
	@param	file - json object file path, id - dropdown option id or class, pdf - path where the pdf files are at
	@auth	m1k6, Morye Kim
	*************************************/
	PGE.hybrid.countypdf = function(file,id,pdf) {
		var content = "";
		var pdfpath = pdf;
		var result_class = ".results";
		var options = "";
		$.getJSON(file, function(json){
			content = json;
			for (var x=0; x<content.length; x++){
				options += "<option value='"+content[x].name+"'>"+content[x].name+"</option>";
			}
			$(id).append(options);
		});
		$(id).change(function(){
			var pdfs = [];
			var results = "";
			for ( var x=0; x<content.length; x++){
				if (content[x].name == $(this).val()) pdfs = content[x].file;
			}
			if ( pdfs.length > 0) {
				results = "<ul>";
				for ( var y=0; y<pdfs.length; y++){
//					results += "<li><a href='"+pdfpath+pdfs[y]+"' target='_blank'>"+$(this).val()+" "+(y+1)+"</a></li>";
					results += "<li style='margin-left: 0;'><a href='"+pdfpath+pdfs[y]+"' target='_blank'>Download the "+$(this).val()+" map</a></li>";
				}
				results += "</ul>";
				$(result_class).html(results);
			}
		});
	};
		
}($));
