if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function(obj, start) {
     	for (var i = (start || 0), j = this.length; i < j; i++) {
         	if (this[i] === obj) { return i; }
     	}
     	return -1;
	}
}

$(document).ready(function(){
    /*
    $('.menuBox ul li a').hoverIntent(function(){
    	$(this).css({background:'white',color:'#494949 !important'});
    },function(){
    	$(this).css({'background':'inherit','color':'white !important'});
    });

    $('.menuBox ul li ul li a').hoverIntent(function(){
    	$(this).css({'color':'white !important'});
    },function(){});
*/

	//podium
	//load images
	var nr = $('.podium-item').length;
	if(nr > 0) {
		var ran = Math.floor(Math.random() * nr + 1);
		//pick random
		pi_active = $('.podium-item:nth-child('+ran+')').addClass('pi-active');
		$('.podium').html($('.pi-active').find('img').clone());
		$('.podium').prepend('<div class="podium-mask"></div><span class="podium-button">Podium</span>');
		$('.podium').prepend($('#mainCntr .menuBox').clone());
		$('.podium').prepend($('#mainCntr .searchBox').clone());
	}
	$('#browser-close').html('x');
	
	$('#browser-close').click(function () {
		$('#podium').fadeOut(500);
		return false;
	});
	$('.podium-button').click(function () {
		$('#podium').fadeIn(500);
		return false;
	});
	$('#browser-prev').click(function() {
		prev = $('.pi-active').prev('.podium-item:');
		if (prev.length > 0) {
			$('.pi-active').removeClass('pi-active');
			prev.addClass('pi-active');
		}
		return false;
	});
	$('#browser-next').click(function() {
		next = $('.pi-active').next('.podium-item:');
		if (next.length > 0) {
			$('.pi-active').removeClass('pi-active');
			next.addClass('pi-active');
		}
		return false;
	});

	$('#sendtofriend, .s2p-close').click(function () {
		//$('#newsletter-form-wrapper').toggle();
		$('.s2p-lightbox').toggle();
		return false;
	});
	
	// Do the magic for showing and hiding of submenu
	
    $('.menuBox ul li ul').parent().addClass('hasSub');
    var podclass = '';
    if ($('.podiumWrapper').is(':visible')) {
    	podclass = '.podium ';
    }
    $(podclass+'.menuBox ul li.hasSub').not('.firstlevelSelected').hoverIntent(function(){
		$(podclass+'.menuBox ul li.firstlevelSelected ul').fadeOut('slow');
		$(this).find('ul').fadeIn('slow');
    },function(){
		$(this).find('ul').fadeOut('slow');
		$(podclass+'.menuBox ul li.firstlevelSelected ul').fadeIn('slow');
    });
	
	//if ($('#loginBoxWrapper').length > 0) {
	//	//$('body > div').hide();
	//	$('body > #wrapper, body > .podiumWrapper, body > .lightbox').remove();
	//	$('#loginBoxWrapper').show();
	//}
	
	if ($('.logoBox.logo').length > 0) {
		if ($('.logoBox.logo').html().length == 0 )
			$('.logoBox.logo').remove();
	}
	
	if ($('.genericcontent  > .sidebarWrap > h2').length > 0 ){
		$('.genericcontent  > .sidebarWrap > h2').each( function (index) {
			var source = $(this).parent().parent().parent().find('>h2');
			if (source.length > 0) {
				$(this).html(source.html());
				source.remove();
			}
		});
	}
	
	if ($('.genericcontent > .event').length == 1) {
		if ($('.genericcontent > .event > div.subtitle').length == 0) {
			$('#pageInfo > span').html('');
		}
	}
		
	if ($('.browsebox').length > 0) {
		$('.browsebox > li').each(function(index)  {
			$(this).html($(this).html().replace('>Pagina ','>'));
		});
	}

	if ($('.rss-no-edge').length > 0) {
		if ( $('.rss-no-edge').parent().css('border') != "none") {
		 	$('.rss-no-edge').parent().css('border',"none");
		}

		var introLength = 58;

		$('.rss-content').each( function () {
			source = $(this).find('p').html();
			if (source.length > introLength) {				
				cutted = source.substr(0,introLength);
				lastSpacePos = cutted.lastIndexOf(' ');
				$(this).html('<p>'+ cutted.substr(0,lastSpacePos) + "&nbsp;&hellip; </p>");
			}
		});

	}

	//if (window.location.hostname == "www.liquimondo.nl"){	}
});


