/* LISTENERS */

$(document).ready(function() {
	
	if($('.cycle').length > 0) {
		$('.cycle').cycle({
			fx : 'fade'
		});
	}

	if('#home') {
		outlineBorders('#hotnews > .list', '#highlights > .list');
		outlineMrEvolta();
	}

	jumpBox();
	IE6warning();
	smoothToTop();
});

$(window).resize(function() {
});
/* FUNCTIONS */

function outlineBorders(a, b) {
	var aheight = $(a).height()
	var bheight = $(b).height()

	if(aheight < bheight)
		$(a).css('height', bheight);
	else
		$(b).css('height', aheight);
}

function outlineMrEvolta() {
	$("#mrevolta").css('top', $("#highlights").height() - 393 + 21);
	$("#mrevolta").css('left', $("#highlights").width() - 230 + 30);
}

function updateMSIE() {
	jQuery.each(jQuery.browser, function(i) {
		if($.browser.msie) {
			alert('load rico/corner 2');

			Rico.loadModule('Corner');
			Rico.onLoad(function() {
				alert('round ie corner');
				//   var roundCorners = Rico.Corner.round.bind(Rico.Corner);
				//   roundCorners('nav1', {color:"transparent"});
			});
			return false;
		}
	});
}

function smoothToTop() {
	$('a[href*=#]').click(function() {
		if(location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');

			if($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({
					scrollTop : targetOffset
				});
				return false;
			}
		}
	});
}

function jumpBox() {

	$('select.jumpbox').change(function() {
		top.location.href = $(this).val();
	});
}

function IE6warning() {
	if(jQuery.browser.msie && jQuery.browser.version.substr(0, 1) == '6') {
		var warningText = 'Please update your browser for a safer and richer experience.'

		$('body').prepend($('<a/>', {
			id : 'IE6warning',
			text : warningText,
			href : 'http://www.browserchoice.eu/',
			target : '_blank'
		}));

		$('#IE6warning').css({
			'display' : 'block',
			'position' : 'relative',
			'z-index' : '2'
		}).hide().slideDown();
	}
}

jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs : true,
		backgrounds : true,
		shim : 'img/blank.gif',
		apply_positioning : true
	}, settings);

	return this.each(function() {
		if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i, obj) {
				var self = jQuery(obj);
				// background pngs
				if(settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5, bg.length - 2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter' : "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image' : 'url(' + settings.shim + ')'
					};
					self.css(styles);
				};
				// image elements
				if(settings.imgs && self.is('img[src$=png]')) {
					var styles = {
						'width' : self.width() + 'px',
						'height' : self.height() + 'px',
						'filter' : "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if(settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')) {
					self.css('position', 'relative');
				};
			});
		};
	});
};

