/**
 *
 * 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: TOPS
  Author: XHTMLized (http://www.xhtmlized.com/)
  Date: November 2010

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

$(document).ready(function() {

	//
	$('input[type="text"]').each(function() {
		var defaultValue = this.value;
		$(this).focus(function() {
			if(this.value == defaultValue) {
				this.value = '';
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
				this.value = defaultValue;
			}
		});
	});

	//
	$('a[rel=colorbox]').colorbox();

	$('.td_body .td_ctwrap .td_main .td_portal .td_team .td_person > img').each(function() {
		$(this).colorbox({
			width:"453px", inline:true, href: $(this).parent().children('.td_toplayer').children('.td_personinfo'),
			opacity: 0.60
		});
	});


	//
	$(".td_slideshow .td_slideshow_nav").tabs(".td_slideshow .td_slides > div", {
		effect: 'default',
		fadeOutSpeed: "slow",
		rotate: true
	}).slideshow({
		autoplay: true,
		interval: 5000
	});

	//
	$(".td_slideshow2 .td_slideshow_nav").tabs(".td_slideshow2 .td_slides > div", {
		effect: 'default',
		fadeOutSpeed: "slow",
		rotate: true
	}).slideshow({
		autoplay: true,
		interval: 5000
	});

	//
	$(".td_slideshow3 .td_slideshow_nav").tabs(".td_slideshow3 .td_slides > div", {
		effect: 'default',
		fadeOutSpeed: "slow",
		rotate: true
	}).slideshow({
		autoplay: true,
		interval: 5000
	});

	//
	$(".td_slideshow4 .td_slideshow_nav").tabs(".td_slideshow4 .td_slides > div", {
		effect: 'default',
		fadeOutSpeed: "slow",
		rotate: true
	}).slideshow({
		autoplay: true,
		interval: 5000
	});

	//
	if (($.browser.mozilla)){

		//
		$('html').addClass('firefox');

	}

	//
	if (($.browser.opera)){

		//
		$('html').addClass('opera');

	}

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

		//
		$('html').addClass('ie');

	}

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

		//
		$('html').addClass('ie8');

	}

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

		//
		$('html').addClass('ie7');

	}

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

		//
		$('html').addClass('ie6');

		// DD_belatedPNG fix for IE6
		var PNG_fix_selectors = [
			'.td_body .td_ctwrap .td_main .td_portal .td_table .td_table_item .image img',
			'.platformarticle .td_body .td_ctwrap .td_main .td_portal h2 img',
			'.img',
			'.td_body .td_ctwrap .td_main .td_portal .td_platform .td_platform_item .image img',
			'.td_twitter',
			'.td_footer .td_ctwrap p a',
			'.td_nav_main ul li a'
		];
		DD_belatedPNG.fix(PNG_fix_selectors.join(','));

	}

});

$(window).load(function() {

	$('.td_platform_row .td_platform_item').equalizeCols();

	$('.td_table_row .td_table_item').equalizeCols();

	$('.td_body .td_ctwrap .td_main .td_portal .td_table .td_table_item .image img').each(function() {
		var height = $(this).height();
		var marginTop = height/2;
		$(this).css({'margin-top':'-'+marginTop+'px'})
	});



});
