//init accordion w/ options
$(function() {
	$( "#accordion" ).accordion({
		fillSpace: true,
		collapsible: true,
		active:false
	});
	$( "#accordion-short" ).accordion({
		fillSpace: false,
		collapsible: true,
		active:false
	});
});
//init industry tabs
$(function() {
	$( "#tabs-auto,#tabs-construction,#tabs-consult,#tabs-edu,#tabs-gov,#tabs-hc,#tabs-mdr,#tabs-np" ).tabs();
});
//listen for click on close button within tabs
$(document).ready(function(){
	$('.close').click(function() {
		$( "#accordion" ).accordion( "option", "active", false );
		$( "#accordion-short" ).accordion( "option", "active", false );
	});
	$("#expanded li:parent, .plusl, .plusr").click(function(){
		$('#expanded').toggleClass('opened');
	}); 
});

//homepage carousel1
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
		var index = $(this).attr('id').split('_');
		carousel.scroll(jQuery.jcarousel.intval(index[1]));
        //carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		$('.jcarousel-control a').removeClass('active');
		$(this).addClass('active');

		return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
		$('.jcarousel-control a.active:not(:last-child)').next().addClass('active');
		$('.jcarousel-control a.active + a.active').prev().removeClass('active');
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
		$('.jcarousel-control a.active:not(:first-child)').prev().addClass('active');
		$('.jcarousel-control a.active + a.active').removeClass('active');
        return false;
    });
};

//hompeage carousel whats_new
function mycarousel2_initCallback(carousel) {
    jQuery('.jcarousel-control2 a').bind('click', function() {
		var index = $(this).attr('id').split('_');
		carousel.scroll(jQuery.jcarousel.intval(index[1]));
        //carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		$('.jcarousel-control2 a').removeClass('active');
		$(this).addClass('active');

		return false;
    });

    jQuery('#whats_new-next').bind('click', function() {
        carousel.next();
		$('.jcarousel-control2 a.active:not(:last-child)').next().addClass('active');
		$('.jcarousel-control2 a.active + a.active').prev().removeClass('active');
        return false;
    });

    jQuery('#whats_new-prev').bind('click', function() {
        carousel.prev();
		$('.jcarousel-control2 a.active:not(:first-child)').prev().addClass('active');
		$('.jcarousel-control2 a.active + a.active').removeClass('active');
        return false;
    });
};

$(document).ready(function() {
	//default 3 items scroll
    jQuery('#mycarousel').jcarousel({
		vertical:true,
		initCallback: mycarousel_initCallback,
		buttonNextHTML:null,
		buttonPrevHTML:null
    });
	
	//single item scroll variation for construction homepage
	jQuery('#mycarousel1').jcarousel({
		vertical:true,
		initCallback: mycarousel_initCallback,
		buttonNextHTML:null,
		buttonPrevHTML:null,
		scroll: 1
    });
	
	//custom scroll for 2 itmes on homepage
		jQuery('#mycarousel2').jcarousel({
		vertical:true,
		initCallback: mycarousel_initCallback,
		buttonNextHTML:null,
		buttonPrevHTML:null,
		scroll: 2
    });
	
	//whats new s
	
	$('#whats_new_jc').jcarousel({
		initCallback: mycarousel2_initCallback,
		buttonNextHTML:null,
		buttonPrevHTML:null
	});
});

//window size fix for flash

var isFireFox=new Boolean();
if (navigator.userAgent.indexOf("Firefox")!=-1) {
    if (navigator.platform == "MacIntel" || navigator.platform == "MacPPC") {
        isFireFox = true;
    } else {
        isFireFox = false;
    }
} else { 
    isFireFox = false;
}
function isEven(value){
    if (value%2 == 0)
        return true;
    else
        return false;
}
var width;
window.onresize = function() {
    if (isFireFox) {
        width = window.innerWidth;
        if (isEven(width)) {
          self.resizeTo(width-1, window.outerHeight);
        }
    }
};

$(document).ready(function(){
	$("#enews").click(function()
	{ $('#enews:text').val(""); });
	$("#search").click(function()
	{ $('#search:text').val(""); });
}); 
