var $j = jQuery.noConflict();
if (!TP) { var TP = {}; }
if (!TP.components) { TP.components = {}; }

$j(document).ready(function(){
	
	if ( $j.browser.msie ) {
		//swap png for a web safe bg color
		$j('#slider-wrapper .pagination a').each(function(){
			$j(this).css('background-image', 'none');	
			$j(this).css('background-color', '#666');
		});
		
		// In IE, margins are sometimes not computed correctly with odd dimensions
		$j('.rc-module').each(function(){
			var w = parseInt($j(this).width());
			if ((w % 2)===1) {
				$j(this).attr('width',w+1);
			}
			delete w;
		});
		
		$j('.callout img').each(function(i){
			var h = parseInt($j(this).height());
			if ((h % 2)===1) {
				$j(this).attr('height',h+1);
			}
			delete h;
		});
	}

	$j('.popup-careers').click(function() {

	    TL.components.Popup.open({
	        href: this.href,
	        wname: 'Careers',
	        features: {
	            width: 750,
	            height: 600,
	            resizable: true,
	            scrollbars: false
	        }
	    });

	    return false;
	});

	$j('.wide-promo h2.bg').cornerz({radius:7, background: '#F7F8F8'});
	
	if($j('#cross-links').length > 0) {
		Gallery.rotate(10);
	}
	
});

Gallery = function(){
	var currentImage = 1;
	var totalImages = 0;
	var interval;
	return {
		rotate:function(s){
			interval = s*1000;
			totalImages = $j('#cross-links li').length;
			if (location.hash && parseInt(location.hash.slice(1)) <= totalImages) {
				currentImage = parseInt(location.hash.slice(1));
			} else { 
				var currentImage = 1;
			};
			
			setTimeout(Gallery.loop, interval);
			
		},
		loop:function(){
			if ((currentImage+1) > totalImages) {
				currentImage = 1;	
			} else {
				currentImage += 1;
			}
			$j('#cross-links li a').eq(currentImage-1).click();
			window.location = '#'+currentImage;
			setTimeout(Gallery.loop, interval);
		}
	}
} ();

TP.components.Popup = function() {
    return {
        open: function(opts) {
            var options = new Array();
            for (feature in opts.features) {
                options.push(feature + '=' + opts.features[feature]);
            }
            var popup = window.open(opts.href, opts.wname, options.join(','));
            popup.focus();
        }
    }
} ();