// ######### Page Load Events ###########
//addEvent(window, 'load', preLoadImages);
// ######################################
function SourceElement(e) {
    var el
    if (e && e.target) el = e.target;
    else el = event.srcElement;
    return el;
}

function addEvent(obj, evType, fn) {
    var toReturn=false;
    
    if (obj.addEventListener){
        obj.addEventListener(evType, fn, true);
        toReturn= true;
    } else if (obj.attachEvent){
        toReturn = obj.attachEvent("on" + evType, fn);
    } else {
        toReturn = fallbackAddEventListener(obj, evType, fn);
    }
    return toReturn;
}
/***************************************************
Hover Images
 ***************************************************/
function preLoadImages(){
 MM_preloadimages ( "../images/cob_theme_green/nav_service_on.gif",
					"../images/cob_theme_green/nav_peace_on.gif",
					"../images/cob_theme_green/nav_world_on.gif",
					"../images/cob_theme_green/nav_church_life_on.gif",
					"../images/cob_theme_green/nav_life_stages_on.gif",
					"../images/cob_theme_green/nav_leadership_on.gif");
 }
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadimages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadimages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
} 




$(document).ready(function() {		
	preLoadImages();
	//Load the slideshow
	$('#cob_header_photo').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 5000,
		cleartypeNoBg: true,
		random:1
	});
	BDM_SlideShow();
	enableToolTip(".qtip");
	$(".appArea td[width='20%'],.appArea td[width='2%']").hide();
});


function BDM_SlideShow(){
	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
		$(pager).find('li').removeClass('activeLI')
			.filter('li:eq('+currSlideIndex+')').addClass('activeLI');
		$(".Captions").html($(".Caption:eq("+currSlideIndex+")").html());
	};

	$(function() {
		$('.Slides').cycle({
			timeout: 6000,
			fx: 'turnDown',
			pager:  '#SlidesNav',
			slideExpr: 'img',
			pagerAnchorBuilder: function(idx, slide) {
				return '<li><a href="#"><img src="' + slide.src + '" width="95" height="74" /></a></li>';
			}
		});
	});
}

function enableToolTip(selector){
	$(selector).each(function(){
		$(this).qtip({
			content: {
				title: {
					text: $(this).attr("name")
				},
				text: ($(this).parent().children('span').html() == '')?'-':$(this).parent().children('span').html()
			},
			show: {
				delay: 0
			},
			position: {
				corner: {
					target: 'topRight',
					tooltip: 'bottomLeft'
				}//,
				//target:'mouse',
				//adjust:{
				//    mouse:true,
				//    screen:true
				//}

			},
			style: {
				width: 400,
				padding: 5,

				border: {
					width: 7,
					radius: 5

				},
				tip: true,
				name: 'cream' // Inherit the rest of the attributes from the preset dark style
			}
		});	
	});
}

function getUrlParamter(paramterName)
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars[paramterName];
}
