jQuery(document).ready(function($) {
	fix_mobiles();
	
	$('.mobileImageForLive').live('click', function(){
		var mobileStream = $(this).attr('href');
		window.parent.location = mobileStream;
	});
	
	$(".footerInfo .adminWelcome b").not(":contains('sitefuze')").each(function(){
		$('.adminWelcome .admin, .pagetool, #divAddModule_placeholderbody').remove();
		$('#ctl00_placeholderBody_ctl101_panelLinks').prev().remove();
		$('#ctl00_placeholderBody_ctl101_panelLinks').remove();
	});

	
	$('.tab-box .head li a:not(".tab-resources")').click(function() {
		
		jQuery('.tab-box .head li a').removeClass('active');
		jQuery(this).addClass('active');
		
		var href = jQuery(this).attr('href');
		jQuery('.tab-box .tab').hide();
		jQuery(href).show();
		
		return false;
	});
	
	$('.tab-box [href=#tab-archives]').click(function() {
		$('#player, .video-box iframe').hide();
		$('#player2').show();
		$('.video-list a:first').click();
	});
	$('.tab-box [href=#tab-chat]').click(function() {
		$('#player2').hide();
		$('#player, .video-box iframe').show();
	});
	$('.tab-box [href=#tab-resources]').click(function() {
		$('div#resources').fadeIn("slow");
	});
	$('#resources div:first').click(function(){
		$("div#resources").fadeOut("slow");
	});
	
	// Version 1.0.1 -- http://assets.vimeo.com/js/embedinator.min.js
	var embedinator = function(){
	    var objects = document.getElementsByTagName('object'),
	    object, params, param, name, value, clip_id, paramsArr, finds;
	
	    for( var i=0; i<objects.length; i++ ) {
	        object = objects[i],
	        params = object.getElementsByTagName('param');
	        finds = 0;
	
	        for( var ii=0; ii<params.length && finds == 0; ii++) {
	            param = params[ii];
	            name = param.getAttribute('name');
	
	            if( name == 'src' || name == 'movie' ) {
	                value = param.getAttribute('value');
	
	                if(/moogaloop/.test(value)) {
	                    finds++;
	
	                    paramsArr = value.split('?')[1].split('clip_id=')[1].split('&');
	                    clip_id = paramsArr[0];
	                    qparams = paramsArr[1];
	
	                    replace(object, clip_id, qparams, object.getAttribute('width'), object.getAttribute('height'));
	                }
	            }
	        }
	    }
	
	    function replace(target, clip_id, params, width, height) {
	        var iframe = document.createElement('iframe');
	        iframe.setAttribute('width', width);
	        iframe.setAttribute('height', height);
	        iframe.setAttribute('src', 'http://player.vimeo.com/video/'+clip_id+'?'+params);
	        iframe.setAttribute('frameborder', 0);
	
	        //insert iframe
	        target.parentNode.insertBefore(iframe, target);
	
	        //remove original
	        target.parentNode.removeChild(target);
	    }
	}
	
	$('.video-list a').click(function() {
		$('#player2').html($('<object width="478" height="321"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /> <param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' + $(this).attr('rel') + '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=' + $(this).attr('rel') + '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1"  type="application/x-shockwave-flash"  allowfullscreen="true"  allowscriptaccess="always"  width="478"  height="321"></embed></object>'));
		$('.video-list a').removeClass('playing');
		$(this).addClass('playing');
		embedinator.call();
		return false;
	});
	embedinator.call();
});

// Check if is mobile browser
var mobile_clients = [
	"iphone",
	"ipad"
];

function is_mobile(){
	var uagent = navigator.userAgent.toLowerCase();
	for (var i in mobile_clients) {
		if (uagent.indexOf(mobile_clients[i]) != -1) {
			return true;
		}
	}
    return false;
}

function fix_mobiles(){
	if( is_mobile() || !FlashDetect.installed ){
		$('iframe#liveStreamFrame').replaceWith('<a href="http://livestream.sitefuze.net:1935/live/6627/mp4:1979uAHu81NfXD8aUh1F/playlist.m3u8" class="mobileImageForLive"><img src="/resources/1/cathedral/countdown-plugin/css/images/watch-live.jpg" /></a>');
	}
}

var FlashDetect=new function(){var self=this;self.installed=false;self.raw="";self.major=-1;self.minor=-1;self.revision=-1;self.revisionStr="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj.AllowScriptAccess="always";version=getActiveXVersion(obj);}catch(err){}
return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){}
return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){obj={activeXError:true};}
return obj;};var parseActiveXVersion=function(str){var versionArray=str.split(",");return{"raw":str,"major":parseInt(versionArray[0].split(" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str.split(/ +/);var majorMinor=descParts[2].split(/\./);var revisionStr=descParts[3];return{"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str.replace(/[a-zA-Z]/g,""),10)||self.revision;};self.majorAtLeast=function(version){return self.major>=version;};self.minorAtLeast=function(version){return self.minor>=version;};self.revisionAtLeast=function(version){return self.revision>=version;};self.versionAtLeast=function(major){var properties=[self.major,self.minor,self.revision];var len=Math.min(properties.length,arguments.length);for(i=0;i<len;i++){if(properties[i]>=arguments[i]){if(i+1<len&&properties[i]==arguments[i]){continue;}else{return true;}}else{return false;}}};self.FlashDetect=function(){if(navigator.plugins&&navigator.plugins.length>0){var type='application/x-shockwave-flash';var mimeTypes=navigator.mimeTypes;if(mimeTypes&&mimeTypes[type]&&mimeTypes[type].enabledPlugin&&mimeTypes[type].enabledPlugin.description){var version=mimeTypes[type].enabledPlugin.description;var versionObj=parseStandardVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revisionStr=versionObj.revisionStr;self.revision=versionObj.revision;self.installed=true;}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var version=-1;for(var i=0;i<activeXDetectRules.length&&version==-1;i++){var obj=getActiveXObject(activeXDetectRules[i].name);if(!obj.activeXError){self.installed=true;version=activeXDetectRules[i].version(obj);if(version!=-1){var versionObj=parseActiveXVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revision=versionObj.revision;self.revisionStr=versionObj.revisionStr;}}}}}();};FlashDetect.JS_RELEASE="1.0.4";
