$slideshow = {
    context: false,
    tabs: false,
    timeout: 0,      // time before next slide appears (in ms)
    slideSpeed: 1000,   // time it takes to slide in each slide (in ms)
    tabSpeed: 700,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'scrollHorz',   // the slide effect to use
    
    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#content');
        
        // set tabs to current hard coded navigation items
        this.tabs = $('ul#services-nav li', this.context);
        
        // remove hard coded navigation items from DOM 
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();
        
        // prepare slideshow and jQuery cycle tabs
        this.prepareSlideshow();
    },
    
    prepareSlideshow: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to: 
        // http://malsup.com/jquery/cycle/options.html
        $("div#services > ul", $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $("ul#services-nav", $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true
        });            
    },
    
    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return $slideshow.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);
        
        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            $slideshow.tabs.removeClass('on');
            
            // add active styling to active button
            activeTab.parent().addClass('on');
        }            
    }            
};


$(function() {
    // initialise the slideshow when the DOM is ready
    $slideshow.init();
});

$(function() {
    // add a 'js' class to the body
    $('body').addClass('js');
    
    // initialise the slideshow when the DOM is ready
    $slideshow.init();
});    

$(document).ready(function(){

	$(".home-banner").cycle({
		fx: 'scrollHorz',
		speed: '1600',
		timeout: '6000'
	});

});

//if($('#sidebar-flash-home').length)
//{
var flashvars = {};
var params = {};
params.wmode = "transparent";
params.allowscriptaccess = "always";
var attributes = {};
attributes.id = "banner";
swfobject.embedSWF(JSHome+"swf/TopInterface.swf", "banner", "940", "124", "9.0.0", false, flashvars, params, attributes);
//}

var flashvars = {};
var params = {};
params.wmode = "transparent";
params.allowscriptaccess = "always";
var attributes = {};
attributes.id = "banner_index";
swfobject.embedSWF(JSHome+"swf/animation2.swf", "banner_index", "940", "250", "9.0.0", false, flashvars, params, attributes);

Shadowbox.init();

var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	
	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
	id = $(" a",this).attr("id");
	$(" a",this).addClass(id + '-mouseover');
}

function jsddm_close()
{	
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
	if(ddmenuitem) ddmenuitem.parent().find('a').removeClass();
}

function jsddm_timer()
{	
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{	$('#header-nav > li').bind('mouseover', jsddm_open);
	$('#header-nav > li').bind('mouseout',  jsddm_timer)
});

document.onclick = jsddm_close;


// contact form field stuff

$(document).ready(function() {
	$('form input[name=buildingtext[]]').click(function(){
		// disable other fields if 4 or more selected
		if (this.checked && $('form input[name=buildingtext[]]:checked').size() >=4){
			$('form input[name=buildingtext[]]').each(function(){
					if (!this.checked) this.disabled = true;
				});
		} else {
			$('form input[name=buildingtext[]]').each(function(){
				if (this.disabled) this.disabled = false;
			});
		}
	});

	$('form input[name=referralother_text]').click(function(){
		// clear radio's
		var radios = ['referral_text_referral','referral_text_magazine','referral_text_internet','referral_text_customkitbuilding']
		$.each(radios,function(){
				$('input[name='+this+']').each(function(){ this.checked = false; });
			});
		
		

	});

});
