/**
 *
 * 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);


//
$.extend($.fn.disableTextSelect = function() {
	return this.each(function(){
		if($.browser.mozilla){//Firefox
			$(this).css('MozUserSelect','none');
		}else if($.browser.msie){//IE
			$(this).bind('selectstart',function(){return false;});
		}else{//Opera, etc.
			$(this).mousedown(function(){return false;});
		}
	});
});

/*******************************************************************************

	CSS on Sails Framework
	Title: Playcore.com
	Author: XHTMLized (http://www.xhtmlized.com/)
	Date: March 2011

*******************************************************************************/

$(document).ready(function() {

	//
	$('.community-form-wrapper form fieldset 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;
			}
		});
	});

	//
	Cufon.replace('.promotitles div h4, #navigation > li > a, .boxes .box .text strong, .topic-wrapper .nav dd a strong, .topic-wrapper .text-wrapper h2 strong, .our-companies-wrapper .text-wrapper h2, .our-companies-wrapper .nav li a, .section-wrapper .nav li a, .section-wrapper .text-wrapper h2, .section-wrapper .text-wrapper .text h4, .community-form-wrapper h2, .community-form-wrapper form h3, .slideshow-wrapper .text-wrapper h2', { fontFamily: 'Gotham-Bold' });
	Cufon.replace('.promotitles div p, #navigation li ul li a, .topic-wrapper .text-wrapper .text h4, .inner-wrapper .inner h4, .our-companies-wrapper .text-wrapper .text h4, .section-wrapper .text-wrapper p.big, .sidebar-style .link-wrapper p a', { fontFamily: 'Gotham-Medium' });
	Cufon.replace('.boxes .box .text span, .topic-wrapper .nav dd a span, .topic-wrapper .text-wrapper p.big, .topic-wrapper .text-wrapper .text p, .our-companies-wrapper .text-wrapper .text p, .section-wrapper .text-wrapper .text p, .community-form-wrapper > p', { fontFamily: 'Gotham-Book' });
	Cufon.replace('.topic-wrapper .text-wrapper h2 span', { fontFamily: 'Gotham-Light' });
	Cufon.replace('.inner-wrapper .inner p .button', { fontFamily: 'Gotham-Bold', textShadow: '0 1px rgba(0, 0, 0, .5)' });
	Cufon.replace('.section-wrapper .researchnav li a, .section-wrapper .partnernav li a', {fontFamily: 'Gotham-Bold'});
	Cufon.replace('.news-wrapper .leftColumn h3', { fontFamily: 'Gotham-Light' });
	Cufon.replace('.news-wrapper .community_form .followBox .iconArea .subtitle', { fontFamily: 'Gotham-Bold' });
	Cufon.replace('.news-wrapper .community_form .followBox .formArea .subtitle', { fontFamily: 'Gotham-Bold' });
	Cufon.replace('.news-wrapper .newsArticles h3', { fontFamily: 'Gotham-Light' });
	Cufon.replace('#oneColumnContent h2', { fontFamily: 'Gotham-Bold' });
	Cufon.replace('.news-wrapper .newsArticles .addCommentBox h3', { fontFamily: 'Gotham-Bold' });
	Cufon.replace('.slideshowList h3', { fontFamily: 'Gotham-Bold' });
	//
	$(".boxes .box1 .text").hover(
		function () {
			$('.boxes .box1 .text').animate({'height':'190px'});
			$('.boxes .box1 .text p:first-child').animate({'padding-bottom':'13px', 'padding-top': '17px'});
		},
		function () {
			$('.boxes .box1 .text').animate({'height':'79px'});
			$('.boxes .box1 .text p:first-child').animate({'padding-bottom':'33px', 'padding-top': '21px'});
		}
	);
	$(".boxes .box2 .text").hover(
		function () {
			$('.boxes .box2 .text').animate({'height':'174px'});
			//$('.boxes .box2 .text p:first-child').animate({'padding-bottom':'13px', 'padding-top': '17px'});
		},
		function () {
			$('.boxes .box2 .text').animate({'height':'77px'}); //77
			//$('.boxes .box2 .text p:first-child').animate({'padding-bottom':'33px', 'padding-top': '17px'});
		}
	);
	$(".boxes .box3 .text").hover(
		function () {
			$('.boxes .box3 .text').animate({'height':'174px'});
			//$('.boxes .box3 .text p:first-child').animate({'padding-bottom':'13px', 'padding-top': '17px'});
		},
		function () {
			$('.boxes .box3 .text').animate({'height':'76px'});
			//$('.boxes .box3 .text p:first-child').animate({'padding-bottom':'33px', 'padding-top': '17px'});
		}
	);
	$(".boxes .box4 .text").hover(
		function () {
			$('.boxes .box4 .text').animate({'height':'190px'});
			//$('.boxes .box4 .text p:first-child').animate({'padding-bottom':'13px', 'padding-top': '17px'});
		},
		function () {
			$('.boxes .box4 .text').animate({'height':'79px'});
			//$('.boxes .box4 .text p:first-child').animate({'padding-bottom':'33px', 'padding-top': '17px'});
		}
	);

	//
	$("#navigation li").hover(
		function () {
			$('#header').addClass('hover');
		},
		function () {
			$('#header').removeClass('hover');
		}
	);

	//
	$(".carousel-wrapper").jcarousel({
		scroll: 1
	});

	if (($.browser.msie) && ($.browser.version <= "8.0")){

		// CSS3PIE
		var CSS3PIE_selectors = [
			'.community-form-wrapper h2',
			'.community-form-wrapper form fieldset textarea',
			'.community-form-wrapper form fieldset input',
			'.sidebar-style .link-wrapper img',
			'.inner-wrapper .inner p .button',
			'.section-wrapper',
			'.carousel-wrapper ul li a img',
			'.carousel-wrapper',
			'.our-companies-wrapper .text-wrapper h2',
			'.our-companies-wrapper .text-wrapper .text',
			'.slideshow-wrapper .text-wrapper .slideshow-text',
			'.topic-wrapper .text-wrapper h2',
			'.topic-wrapper .nav dt img',
			'.topic-wrapper',
			'.boxes',
			'.boxes .box a',
			'.promotitles div a',
			'.promotitles div img',
			'.promotitles div',
			'#footer .footer-top',
			'#navigation li ul',
			'#header .playcore',
			'#header .header-top-wrapper'
		];
		$( CSS3PIE_selectors.join(',') ).each(function() {
			PIE.attach(this);
		});
	}

	
	if (($.browser.webkit)){
		$('html').addClass('webkit');

		//
		$('.carousel-wrapper .jcarousel-prev, .carousel-wrapper .jcarousel-next').disableTextSelect();

	}

	//
	if (($.browser.msie) && ($.browser.version == "8.0")){
	}

	//
	if (($.browser.msie) && ($.browser.version == "7.0")){
	}

	//
	if (($.browser.msie) && ($.browser.version == "6.0")){
	}

});

$(window).load(function() {

	//
	$('#footer .footer-bottom dl').equalizeCols();

	//
	$('.carousel-wrapper ul li a img').each(function(){
		var imgHeight = $(this).height();
		//console.log(imgHeight);
		$(this).parent().css({'margin-top': '-'+(imgHeight/2)+'px'});
	});

});
