/**
 *
 * Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */

(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */

	$.fn.equalizeCols = function(){
		var height = 0,
			reset = $.browser.msie && $.browser.version < 7 ? "1%" : "auto";

		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, this.offsetHeight);
			})
			.css("height", height)
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});

	};

})(jQuery);

/*******************************************************************************

	CSS on Sails Framework
	Title: HCIN
	Author: XHTMLized (http://www.xhtmlized.com/)
	Date: March 2011

*******************************************************************************/

function counter() {
	$.get('/_ui/js/counter.txt', function(data) {
		$('.home #content .middle .box2 .counter .digit.d1').text(data[0]);
		$('.home #content .middle .box2 .counter .digit.d2').text(data[1]);
		$('.home #content .middle .box2 .counter .digit.d3').text(data[2]);
		$('.home #content .middle .box2 .counter .digit.d4').text(data[3]);
		$('.home #content .middle .box2 .counter .digit.d5').text(data[4]);
		$('.home #content .middle .box2 .counter .digit.d6').text(data[5]);
		// $('.home #content .middle .box2 .counter .digit.d7').text(data[6]);
		// $('.home #content .middle .box2 .counter .digit.d8').text(data[7]);
		// $('.home #content .middle .box2 .counter .digit.d9').text(data[8]);
		// console.log(data)
	});
};

$(document).ready(function() {

	$('#selection div.sorting a').not('.active').click( function(){
	
		var theCheckbox = $(this).attr('id').substr(1);
		$('#' + theCheckbox).attr('checked', true);
		$('#selection').submit();

		});

	//
	if ( $('body').hasClass('home') ) {

		//
		$('.home .top .carousel-wrapper').cycle({pause: 1, timeout: 6000, next: '.nextSlide', prev: '.prevSlide'});

		// tjs:20110504 : comment out, going to handle via php on index.html
		// counter();
		// setInterval(function() { counter(); }, 60000);
	}

	// commenting out because we are going to use mail to: tjs 20110412
	//$('#header .nav-bottom li:first-child a').live('click', function(){
	//	$('#toplayer-contact-us').removeClass('toplayer-off');
	//	return false;
	//});
	
	// commenting out because we are going to use a link to the site: tjs 20110412
	//$('#header .nav-bottom li:last-child a').live('click', function(){
	//	$('#toplayer-sign-in').removeClass('toplayer-off');
	//	return false;
	//});
	
	
	//
	$('.toplayer-wrapper .toplayer-content .close').live('click', function(){
		$('.toplayer-wrapper').addClass('toplayer-off');
	});

	//
	if (($.browser.mozilla)){
		//
		$('html').addClass('firefox');
	}

	//
	if (($.browser.opera)){
		//
		$('html').addClass('opera');
	}

	//
	if (($.browser.webkit)){
		//
		$('html').addClass('webkit');
	}

	//
	if (($.browser.msie) && ($.browser.version <= "8.0")){

		// CSS3PIE
		var CSS3PIE_selectors = [
			'.aboutus #content .timeline tbody tr th p',
			'.resources #content .links2 li',
			'.members #content .members-list .member img',
			'#content .wrapper-inner .h3 img',
			'.solution #content .img',
			'#content .wrapper-inner p.button2 span a',
			'#content .wrapper-inner p.button2 span',
			'#content .wrapper-inner p.button span a',
			'#content .wrapper-inner p.button span',
			'#content .wrapper-inner h2',
			'.toplayer-wrapper .toplayer-content',
			'.home #content .bottom .box img',
			'.home #content .middle .box3',
			'.home #content .middle .box1',
			'.home #content .middle .box2 .counter',
			'.home #content .middle .box2 .counter .over',
			'.home #content .middle',
			'.home #content .top .whoweare span a',
			'.home #content .top .whoweare span',
			'.home #content .top .whoweare p',
			'.home #content .top .carousel-wrapper .carousel .carousel-content .info .more a',
			'.home #content .top .carousel-wrapper .carousel .carousel-content .info .more',
			'.home #content .top .carousel-wrapper .carousel .carousel-content .info img',
			'.home #content .top .carousel-wrapper',
			'.content-wrapper',
			'#navigation dl',
			'#header .nav-bottom li a',
			'#header .hcin',
			'.container'
		];
		$( CSS3PIE_selectors.join(',') ).each(function() {
			PIE.attach(this);
		});
	}

	//
	if (($.browser.msie) && ($.browser.version == "8.0")){
	}

	//
	if (($.browser.msie) && ($.browser.version == "7.0")){
	}

	//
	if (($.browser.msie) && ($.browser.version == "6.0")){

		//
		var windowWidth = $(window).width();
		var windowHeight = $(window).height();
		$('.toplayer-wrapper .toplayer-bg').css({'width': windowWidth+'px', 'height': windowHeight+'px'})
		$('.toplayer-wrapper .toplayer-content').css({'left': (windowWidth/2)+'px', 'top': (windowHeight/2)+'px'})

	}

});

$(window).load(function() {

	//
	$('#navigation dl').equalizeCols();

	//
	$('#content .wrapper-inner .h3 h3').each(function(){
		var h3Width = $(this).outerWidth();
		//console.log(h3Width);
		$(this).parent().css({'background-position': 8+h3Width+'px 100%'});
		//
	});

});
