
/* - ibc_theme.js - */
var selectedSearchButton;

function setSearchButtonSelected(elId, clicked) {
    var children;

    //alert('setSearchButtonSelected elId = ' + elId);

    var el = document.getElementById(elId);

    if (el == null) {
	return 0;
    }
    
    el.style.backgroundPosition = "0 0";
    children = el.childNodes;
    for (i in children) {
	if (children[i].tagName == "DIV") {
	    children[i].style.marginTop = "1px";
	    break;
	}
    }
	
    if (clicked) {
	selectedSearchButton = elId;
    }
}

function setSearchButtonUnselected(elId, clicked) {
    //alert('setSearchButtonUnselected elId = ' + elId)

    var el = document.getElementById(elId);

    if (el == null) {
	return 0;
    }

    if (selectedSearchButton != elId) {
	var children;
	el.style.backgroundPosition = "0 -29px";
	children = el.childNodes;
	for (i in children) {
	    if (children[i].tagName == "DIV") {
		children[i].style.marginTop = "0";
		break;
	    }
	}
    }
}

function getSelectedSearchButtonId() {
    return selectedSearchButton;
}

function addSelectedAndSubmit(formId) {
    var form = document.getElementById(formId);
    var input = document.createElement('input');
    input.type = 'hidden';
    input.name = 'search_type';
    input.value = selectedSearchButton;
    form.appendChild(input);
    form.submit();
}

function selectSearch(elId) {
    var unsetEl;

    //alert('selectSearch elId = ' + elId);

    var el = document.getElementById(elId);

    var searchButtonIds = new Array();
    searchButtonIds[0] = "fp-search-keyword";
    searchButtonIds[1] = "fp-search-location";
    searchButtonIds[2] = "fp-search-date";

    // Set element to be selected
    setSearchButtonSelected(elId, true);

    // Unset other buttons
    for (i in searchButtonIds) {
	//alert(searchButtonIds[i]);
	if (searchButtonIds[i] != elId) {
	    setSearchButtonUnselected(searchButtonIds[i]);
	}
    }

    if (elId == 'fp-search-date') {
	document.getElementById('fp-text-search').style.display = "none";
	document.getElementById('fp-date-search').style.display = "block";
	document.getElementById('fp-search-advanced').style.display = "none";
	document.getElementById('fp-location-search').style.display = "none";
    } else if (elId == 'fp-search-location') {
	document.getElementById('fp-date-search').style.display = "none";
	document.getElementById('fp-text-search').style.display = "none";
	document.getElementById('fp-search-advanced').style.display = "block";
	document.getElementById('fp-location-search').style.display = "block";
    } else {
	document.getElementById('fp-date-search').style.display = "none";
	document.getElementById('fp-text-search').style.display = "block";
	document.getElementById('fp-search-advanced').style.display = "block";
	document.getElementById('fp-location-search').style.display = "none";
    }	
}

function initialiseSearch(elId) {
    selectSearch(elId);
}

// Taken from http://www.dustindiaz.com/getelementsbyclass/
function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
	node = document;
    if ( tag == null )
	tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
	if ( pattern.test(els[i].className) ) {
	    classElements[j] = els[i];
	    j++;
	}
    }
    return classElements;
}

jq(document).ready(function(){
    //alert('Initialising gallery');
    jq('#front-page-event-feature-gallery').galleryView({
        gallery_width: 485,
        gallery_height: 180,
        panel_width: 485,
        panel_height: 180,
        frame_width: 0,
        frame_height: 0,
		frame_gap: 0,
		filmstrip_size: 0,
        pause_on_hover: true,
        show_filmstrip: false,
        transition_speed: 5,
	transition_interval: 9000,
		filmstrip_position: 'bottom',
        nav_theme: ''
    });

    //alert('Initialising TV Feature');
    jq('#front-page-tv-feature-inner').cycle({
        fx: 'fade',
	timeout: 7000,
	cleartype:  1 // enable cleartype corrections
    }); 

    //alert('Initialising Testimonials');
    jq('#front-page-testimonials-feature').cycle({ 
        fx: 'scrollUp',
	timeout: 6000,
	cleartype:  1 // enable cleartype corrections
    }); 

});



