﻿//Custom Accordion menu
//if the persistent option is set to true then the last visited tab is re-opened when the user goes back in their browser history
//if openByDefault is set then if a tab has not been previously selected then the first tab is opened

function accordion(speed, persistent, openByDefault) {
    $('.accordioncontent').hide();
    var y = $('ul#accordion li a');
    y.click(
        function() {
            var current = $(this).next();
            if ((current.is('div')) && (!current.is(':visible'))) {
                y.removeClass('selected');
                $(this).addClass('selected');
                $('.accordioncontent:visible').slideUp(speed);
                current.slideDown(speed);
            } else if ((current.is('div')) && (!current.is(':hidden'))) {
                $(this).removeClass('selected');
                current.slideUp(speed);
            }
        }
    );
    if (persistent) {
        if (location.href.indexOf('.aspx#') !== -1) {
            var str = location.href.split('.aspx#');
            var i = $('#content' + str[1]).slideDown('normal');
            i.siblings('a').addClass('selected');
        }
    }
    if (openByDefault) {
        var i = $('#content1').slideDown('normal');
        i.siblings('a').addClass('selected');
    }
}

function casestudies(speed, persistent, openByDefault) {
    $('.caseStudyContent').hide();
    var y = $('ul.caseStudies li a');
    y.click(
        function() {
            var current = $(this).next();
            if ((current.is('div')) && (!current.is(':visible'))) {
                y.removeClass('selected');
                $(this).addClass('selected');
                $('.caseStudyContent:visible').slideUp(speed);
                current.slideDown(speed);
            } else if ((current.is('div')) && (!current.is(':hidden'))) {
                $(this).removeClass('selected');
                current.slideUp(speed);
            }
        }
    );
    if (persistent) {
        if (location.href.indexOf('.aspx#') !== -1) {
            var str = location.href.split('.aspx#');
            var i = $('#content' + str[1]).slideDown('normal');
            i.siblings('a').addClass('selected');
        }
    }
    if (openByDefault) {
        var i = $('#content1').slideDown('normal');
        i.siblings('a').addClass('selected');
    }
}

	
/* The following code (loadFlashVid, embedSwf, and destroyVid) deals with embedding and removing flash videos in the javascript accordion - James F  */
var params = {
    menu: "false",
	scale: "noScale",
	wmode: "opaque",
	allowFullscreen: "true",
	allowScriptAccess: "always",
	bgcolor: "#FFFFFF"
};

var attributes = {};
var current = '';

function loadFlashVid() {
    var flvs = ['504_Rebecca_Brigden_short_version.flv', 
                '506_Adam_Hitchcock_short_version.flv',
                '508_Luke_Davidson_short_version.flv',
                '510_Jan_Carter_short_version.flv'
               ];

    if(current == '') {
        embedSwf('504_Rebecca_Brigden_short_version.flv', 'flashVid1');
        current = 'flashVid1';
    }
    var link = $('ul#accordion li a.videotab');
    link.click(
        function() {
            var id = this.id;
            id = id.replace('accordion', '');
            id=(parseInt(id));
            destroyVid(current);
            embedSwf(flvs[id -1], 'flashVid'+id);
            current = 'flashVid'+id;
        }
    );
    
    var nonvidlink = $('ul#accordion li a.novideo');
    nonvidlink.click(
        function() {
            destroyVid(current);
        }
   );
}

function embedSwf(swfident,embedDiv) {
    var flashvars = {};
    flashvars.video_path = swfident;
	swfobject.embedSWF("../Flash/video_comp.swf", embedDiv, "320", "180", "9.0.159", "false", flashvars, params, attributes);
}


function destroyVid(id) {
    var allobjects = document.getElementsByTagName('object');
	for(var i=0; i< allobjects.length; ++i) {
        if (allobjects[i].id === id) {
			var div = document.createElement('div');
			div.id= id;
		    var parent = allobjects[i].parentNode;
			parent.replaceChild(div,allobjects[i]);
		}
	}
}

function imageRotate() {
    $('#image_rotate').innerfade({
        speed: 'slow',
        timeout: 4000,
        type: 'sequence',
        containerheight: '326px'
    });
}



$(document).ready(function() {   

    $("#breadcrumb span a[href=./]").css('display', 'none');
    $("#breadcrumb span a[href=./]").parent().parent().find("span").eq(1).css('display', 'none');
    $("#navigation ul li a[title=Match-Me Tool]").parent().css('display', 'none');
    $("#navigation ul li a[title=Sitemap]").parent().css('display', 'none');
    $("#navigation ul li a[title=Accessibility]").parent().css('display', 'none');
    $("#navigation ul li a[title=Terms of Use and Privacy]").parent().css('display', 'none');

});

