Array.prototype.pushIfNotIn = function(s) {
	var found = false;
	for(var i=0; i<this.length; i++){
		if(s==this[i]) {
			found = true;
			break;
		}
	}
	if (!found) this.push(s);
};

$(document).ready(function() {

	$('#column-internal .box-left').after($('#banners'));
	
	if (!$('#column-external').length) {
		$('#content').css('width','756px');

	} else {
		$('#column-external a').each(function() {
			var h = $(this).attr('href');
			if (location.pathname.indexOf(h)>-1) {
				$(this).addClass('active');
			}
		});
	}
	
	$('#container')
		.after($('#footer'))
		.find('> hr.hidden')
		.removeClass('hidden')
		.css('clear','both')
		.css('border', '1px solid #ecedee');
	
	$('#header-rainbow').rainbow({
		colors: ['#77cdd0','#00b1d9','#3d86c6','#574099','#993f98','#0054a6','#4564af','#80cbf0','#88b2df','#701f6f'],
		easing: 'backout',
		min: 3000,
		max: 4000
	});
	
	$(new Image()).load(function() {
		$(this).hide();
		$('#header-banner').html('').append(this);
		$(this).fadeIn(1000);
	}).error(function(){ $(this).attr('src', '/images/public/images/header/1.jpg'); })
		.attr('src', '/images/public/images/header/' + parseInt(Math.random()*11) + '.jpg');
	
	if ($('#sub0').length == 0) {
		var nums = [];
		while (nums.length < 4)
			nums.pushIfNotIn(parseInt(Math.random()*13));
		for (var i=0; i<nums.length-1; i++) {
			$(new Image()).load(function() {
				$(this).hide().addClass('dx');
				$('#column-external').append(this);
				$(this).fadeIn(1000);
			}).error(function(){ $(this).attr('src', '/images/public/images/thumbs/' + nums[3] + '.jpg'); })
				.attr('src', '/images/public/images/thumbs/' + nums[i] + '.jpg');
		};
	}

});
