// Load jQuery
google.load("jquery", "1.4.2");
google.load("swfobject", "2.2");

// set onload
google.setOnLoadCallback(function() {
	
	LazyLoad=function(){var f=document,g,b={},e={css:[],js:[]},a;function j(l,k){var m=f.createElement(l),d;for(d in k){if(k.hasOwnProperty(d)){m.setAttribute(d,k[d])}}return m}function h(d){var l=b[d];if(!l){return}var m=l.callback,k=l.urls;k.shift();if(!k.length){if(m){m.call(l.scope||window,l.obj)}b[d]=null;if(e[d].length){i(d)}}}function c(){if(a){return}var k=navigator.userAgent,l=parseFloat,d;a={gecko:0,ie:0,opera:0,webkit:0};d=k.match(/AppleWebKit\/(\S*)/);if(d&&d[1]){a.webkit=l(d[1])}else{d=k.match(/MSIE\s([^;]*)/);if(d&&d[1]){a.ie=l(d[1])}else{if((/Gecko\/(\S*)/).test(k)){a.gecko=1;d=k.match(/rv:([^\s\)]*)/);if(d&&d[1]){a.gecko=l(d[1])}}else{if(d=k.match(/Opera\/(\S*)/)){a.opera=l(d[1])}}}}}function i(r,q,s,m,t){var n,o,l,k,d;c();if(q){q=q.constructor===Array?q:[q];if(r==="css"||a.gecko||a.opera){e[r].push({urls:[].concat(q),callback:s,obj:m,scope:t})}else{for(n=0,o=q.length;n<o;++n){e[r].push({urls:[q[n]],callback:n===o-1?s:null,obj:m,scope:t})}}}if(b[r]||!(k=b[r]=e[r].shift())){return}g=g||f.getElementsByTagName("head")[0];q=k.urls;for(n=0,o=q.length;n<o;++n){d=q[n];if(r==="css"){l=j("link",{href:d,rel:"stylesheet",type:"text/css"})}else{l=j("script",{src:d})}if(a.ie){l.onreadystatechange=function(){var p=this.readyState;if(p==="loaded"||p==="complete"){this.onreadystatechange=null;h(r)}}}else{if(r==="css"&&(a.gecko||a.webkit)){setTimeout(function(){h(r)},50*o)}else{l.onload=l.onerror=function(){h(r)}}}g.appendChild(l)}}return{css:function(l,m,k,d){i("css",l,m,k,d)},js:function(l,m,k,d){i("js",l,m,k,d)}}}();
	
	// remove no_JS class from body tag
	$('body').removeClass('no_JS');
	
	$("div#sidebar a").filter(function() {
		//Take the current URL and split it into chunks at each slash
		var currentURL = window.location.toString().split("/");
		//return true if the bit after the last slash is the current page name
		return $(this).attr("href") == currentURL[currentURL.length-1];
		//when the filter function is done, you're left with the links that match.
	}).addClass("active");
	
	$("p.graphic").hover(
		function () {
			$(this).next("h4").find("a").addClass("over");
		},
		function () {
			$(this).next("h4").find("a").removeClass("over");
		}
	);
	
	$("div#info h4").hover(
		function () {
			$(this).prev("p.graphic").find("img").addClass("over");
		},
		function () {
			$(this).prev("p.graphic").find("img").removeClass("over");
		}
	);
	
	$('a.jump').click(function(){
		var tlink = $(this).attr('href').replace(/#/g,'');
		$('a.anchor>span').remove();
		$('a.anchor').css({'color':'#463e33'});
		$('a.anchor').filter('[name='+tlink+']').css({'color':'#4e6a30'}).prepend('<span>&raquo; </span>');
	});

	$("a.mt").attr('href', function(){
		return "mailto:" + $(this).attr('href').replace(/.*emailgen\/([a-z0-9._%-]+)\+([a-z0-9._%-]+)\+([a-z.]+)/i, '$1' + '@' + '$2' + '.' + '$3').replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});
	});
	
	if($('a.enlarge').length != 0){
		LazyLoad.js(['/includes/js/fancyzoom.min.js'], function () {
			$('a.enlarge').fancyZoom({scaleImg: true, closeOnClick: false});
		});
	}
	
	if($('#fblb').length != 0){
		LazyLoad.js(['http://static.ak.connect.facebook.com/connect.php/en_US'], function () {
			FB.init("7a5b3a2b603c101f0e532d8635ca2237", "http://opcc.codav.com/includes/js/xd_receiver.htm", { permsToRequestOnConnect : "publish_stream", });
		});
	}

});

function strm_pub() {
	FB.ensureInit(function () {
		FB.Facebook.apiClient.pages_isFan(110320478981253, FB.Connect.get_loggedInUser(), function(result){
			if (result) {
				FB.Facebook.apiClient.users_hasAppPermission("publish_stream",function(has){
					if (has == 0) {
						FB.Connect.showPermissionDialog("publish_stream", function(granted){
							FB.Connect.streamPublish('', null, null, 110320478981253, 'Let us know what&rsquo;s up!');
						});
					}
					else {
						FB.Connect.streamPublish('', null, null, 110320478981253, 'Let us know what&rsquo;s up!');
					}
				});
			}
			else{
				$('#fblb').html('<fb:fan profile_id="110320478981253" stream="0" connections="0" width="200" height="66"></fb:fan>');
				FB.XFBML.Host.parseDomTree();
			}
		});
	});
}

Function.prototype.defaults = function(){
	var _f = this;
	var _a = Array(_f.length-arguments.length).concat(Array.prototype.slice.apply(arguments));
	return function(){
		return _f.apply(_f, Array.prototype.slice.apply(arguments).concat(_a.slice(arguments.length, _a.length)));
	}
}

var write_ytvid = function(c,y,w,h){
	var flash_version = "8.0.0",
		params = {
			allowScriptAccess: "always",
			allowFullScreen: true,
			wmode: "transparent"
		},
		attributes = {
			'id': c,
			'class': $('#'+c).attr('class')
		},
		yvidurl = "http://www.youtube.com/v/" + y + "?enablejsapi=1&playerapiid=ytplayer&fs=1";

	if (swfobject.hasFlashPlayerVersion(flash_version)){
		// has Flash
		swfobject.embedSWF(yvidurl, c, w, h, flash_version, null, null, params, attributes);
	}
}.defaults('', '', 425, 344);

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16419786-1']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackPageLoadTime']);
(function() {
	var thisurl = document.location.href;
	if(thisurl.indexOf('opccag.org') > -1){
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	}
})();
