var IE = document.all?true:false

$(document).ready(function() {

	//Hoofdnavigatie mouseovers
/*	
	$("#nav img").hover(
		function(){
			var imgsrc = $(this).attr("src")
			if(imgsrc.indexOf('_o.gif')==-1){
				imgsrc = imgsrc.replace('.gif','_o.gif');
				$(this).attr('src',imgsrc);
			}
		},
		function(){
			var thisclass = $(this).attr("class")
			if(thisclass.indexOf('active')==-1){
				var imgsrc = $(this).attr("src").replace('_o.gif','.gif');
				$(this).attr('src',imgsrc);
			}
		}
	);



	$(".main_menu_item_act").each(function() {
		var img_name=$(this).attr('id');
		$(this).parent().parent().css("padding","0px");
		$(this).html("<img src='/static/project/images/nav/"+img_name+"_act.gif' style='float:left;'>");
	});
*/
	$(".main_menu_item").each(function() {
		var this_name=$(this).attr('id');
		//$(this).parent().parent().css("padding","0px");
		//$(this).html("<img src='/static/project/images/nav/"+this_name+".gif' id='main_menu_"+this_name+"' style='float:left;'>");
		$(this).parent().parent().bind("mouseenter",function(){
				t=setTimeout("showSubMenu('"+this_name+"')",200);
			}).bind("mouseleave",function(){
				hideSubMenu(this_name);
	    });

	});



	//Menu mouseovers
	$("#menu li").hover(
		function(){
			var addClass = '';
			if($(this).attr('class').indexOf('first')>-1) {addClass=' first'}
			if($(this).attr('id').indexOf('activestate')==-1){
				$(this).attr('class','active' + addClass);
				var imgsrc = $(this).find('img').attr("src").replace('_active.gif','.gif').replace('.gif','_active.gif');
				if(imgsrc.indexOf('.png')==-1 && imgsrc.indexOf('blank')==-1){ //geen pngs doen...
					$(this).find('img').attr('src',imgsrc);
				}
			}
		},
		function(){
			var addClass = '';
			if($(this).attr('class').indexOf('first')>-1) {addClass=' first'}
			var thisid = $(this).attr("id")
			if(thisid.indexOf('activestate')==-1 && thisid.indexOf('activestatesub')==-1){
				$(this).attr('class','nonactive' + addClass);
				var imgsrc = $(this).find('img').attr("src").replace('_active.gif','.gif');
				$(this).find('img').attr('src',imgsrc);
			}
		}
	);

	
	//article mouseovers
	$(".content .image_article").hover(
		function(){
			$(this).children('div').attr('class','active');
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				if(imgsrc.indexOf('_o.gif')==-1){
					imgsrc = imgsrc.replace('.gif','_o.gif');
					$(this).find('.button').attr('src',imgsrc);
				}
			}
		},
		function(){
			$(this).children('div').attr('class','border');
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				imgsrc = imgsrc.replace('_o.gif','.gif');
				$(this).find('.button').attr('src',imgsrc);
			}
		}
	);

	//article mouseovers
	$(".content .image_cat").hover(
		function(){
			$(this).children('div').attr('class','active');
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				if(imgsrc.indexOf('_o.gif')==-1){
					imgsrc = imgsrc.replace('.gif','_o.gif');
					$(this).find('.button').attr('src',imgsrc);
				}
			}
		},
		function(){
			$(this).children('div').attr('class','border');
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				imgsrc = imgsrc.replace('_o.gif','.gif');
				$(this).find('.button').attr('src',imgsrc);
			}
		}
	);

//article mouseovers
	$(".content .article").hover(
		function(){
			$(this).children('div').attr('class','active');
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				if(imgsrc.indexOf('_o.gif')==-1){
					imgsrc = imgsrc.replace('.gif','_o.gif');
					$(this).find('.button').attr('src',imgsrc);
				}
			}
		},
		function(){
			$(this).children('div').attr('class','border');
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				imgsrc = imgsrc.replace('_o.gif','.gif');
				$(this).find('.button').attr('src',imgsrc);
			}
		}
	);

	$(".content .locations").hover(
		function(){
			$(this).children('div').attr('class','active');
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				if(imgsrc.indexOf('_o.gif')==-1){
					imgsrc = imgsrc.replace('.gif','_o.gif');
					$(this).find('.button').attr('src',imgsrc);
				}
			}
		},
		function(){
			$(this).children('div').attr('class','border');
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				imgsrc = imgsrc.replace('_o.gif','.gif');
				$(this).find('.button').attr('src',imgsrc);
			}
		}
	);

	$(".content .photos").hover(
		function(){
			$(this).children('div').attr('class','active');
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				if(imgsrc.indexOf('_o.gif')==-1){
					imgsrc = imgsrc.replace('.gif','_o.gif');
					$(this).find('.button').attr('src',imgsrc);
				}
			}
		},
		function(){
			$(this).children('div').attr('class','border');
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				imgsrc = imgsrc.replace('_o.gif','.gif');
				$(this).find('.button').attr('src',imgsrc);
			}
		}
	);

	$(".content .videos").hover(
		function(){
			$(this).children('div').attr('class','active');
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				if(imgsrc.indexOf('_o.gif')==-1){
					imgsrc = imgsrc.replace('.gif','_o.gif');
					$(this).find('.button').attr('src',imgsrc);
				}
			}
		},
		function(){
			$(this).children('div').attr('class','border');
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				imgsrc = imgsrc.replace('_o.gif','.gif');
				$(this).find('.button').attr('src',imgsrc);
			}
		}
	);

	//article mouseovers
	$(".content .exercise").hover(
		function(){
			$(this).children('div').attr('class','active');
			/*
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				if(imgsrc.indexOf('_o.gif')==-1){
					imgsrc = imgsrc.replace('.gif','_o.gif');
					$(this).find('.button').attr('src',imgsrc);
				}
			}
			*/
		},
		function(){
			$(this).children('div').attr('class','border');
			/*
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				imgsrc = imgsrc.replace('_o.gif','.gif');
				$(this).find('.button').attr('src',imgsrc);
			}
			*/
		}
	);

	//article mouseovers
	$(".content .training").hover(
		function(){
			$(this).children('div').attr('class','active');
			/*
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				if(imgsrc.indexOf('_o.gif')==-1){
					imgsrc = imgsrc.replace('.gif','_o.gif');
					$(this).find('.button').attr('src',imgsrc);
				}
			}
			*/
		},
		function(){
			$(this).children('div').attr('class','border');
			/*
			var imgsrc = $(this).find('.button').attr("src")
			if(imgsrc){
				imgsrc = imgsrc.replace('_o.gif','.gif');
				$(this).find('.button').attr('src',imgsrc);
			}
			*/
		}
	);

	//homepage toplist mouseactions
	$(".tabs li").click(
		function(){
			var thisid = $(this).attr('id');
			$(this).parent().children().each(
				function(){
					var thisid = $(this).attr('id');
					if(thisid){
						$(this).attr('class','tab');
					}
					//verberg alle containers
					$('#container_'+ thisid).css('display','none');
				}
			)
			if(thisid == 'top1') {
				try {
					player_2.sendEvent('STOP');
				}
				catch(err) {
				}
			}
			else {
				try {
					player_1.sendEvent('STOP');
				}
				catch(err) {
				}
  			}
			$('#container_'+ thisid).css('display','block');
			$(this).attr('class','active tab');
		}
	);

	//Footer mouseovers
	$(".footer_logos img").hover(
		function(){
			var imgsrc = $(this).attr("src");
			if(!imgsrc) imgsrc = '';
			if(imgsrc.indexOf('_mo.gif')==-1){
				imgsrc = imgsrc.replace('.gif','_mo.gif');
				$(this).attr('src',imgsrc);
			}
		},
		function(){
			var imgsrc = $(this).attr("src");
			if(imgsrc) $(this).attr('src',imgsrc.replace('_mo.gif','.gif'));
		}
	);

	$(".player_players tr").hover(
		function(){
			$(this).addClass('over');
		},
		function(){
			$(this).removeClass('over');
		}
	);

});

function showMessage(id){
	display('item-'+ id +'-ok','item-'+ id)
	setTimeout("display('item-"+ id +"','item-"+ id +"-ok')",3000)
}

function mOn(obj) {
	var ext = obj.src.slice(-3)
	if(obj.src.indexOf('_o.'+ ext)==-1){
		if(obj.src.indexOf('_a.gif')==-1){
			obj.src=obj.src.replace('.'+ ext,'_o.'+ ext)
		}
	}
}
function mOut(obj) {
	var ext = obj.src.slice(-3)
	obj.src=obj.src.replace('_o.'+ext,'.'+ext)
}


function toggleCheckbox(id, show, checked){
	//wanneer undefined, bepaal of checkbox aan of uitgezet moet worden...
	if(checked===undefined){
		if(document.getElementById('check_'+id).src.indexOf('_o.gif')>-1){
			checked = false;
		}else{
			checked = true;
		}
	}
	if(checked){
		$('#'+ id).attr('value','1');
		mOn(document.getElementById('check_'+ id));
		$('#'+ show).css('display','block');
	}else{
		$('#'+ id).attr('value','');
		mOut(document.getElementById('check_'+ id));
		$('#'+ show).css('display','none');
	}
}

function increaseAmount(textid) {
    if (isNaN($('#' + textid).val())) {
        $('#' + textid).val(1);
    } else {
        if (eval($('#' + textid).val()) < 99) {
            $('#' + textid).val(eval($('#' + textid).val()) + 1);
        }
    }
	
	var strTotalPrice = $('#' + textid).val() * $('#product_price').val();
	strTotalPrice = getMoney(strTotalPrice);
	$('#totalPrice').html('&euro; '+strTotalPrice);	
	$('#subtotal').html('&euro; '+strTotalPrice);	
	
    return false;
}

function decreaseAmount(textid) {
    if (isNaN($('#' + textid).val())) {
        $('#' + textid).val(1);
    } else {
        if (eval($('#' + textid).val()) > 1) {
            $('#' + textid).val(eval($('#' + textid).val()) - 1);
        }
    }

	var strTotalPrice = getMoney($('#' + textid).val() * $('#product_price').val());
	$('#totalPrice').html('&euro; '+strTotalPrice);	
	$('#subtotal').html('&euro; '+strTotalPrice);	

    return false;
}
function getMoney(value) {
	return replace(cent(roundNumber(value)),'.',',')
}

function cent(amount) {
    amount -= 0;
    return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

function roundNumber(num) {
	var result = Math.round(num*Math.pow(10,2))/Math.pow(10,2);
	return result;
}

function replace(string,text,by) {
// Replaces text with by in string
	string += '';
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;

	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;

	var newstr = string.substring(0,i) + by;

	if (i+txtLength < strLength)
	newstr += replace(string.substring(i+txtLength,strLength),text,by);
	
	return newstr;
}

