$(document).ready(function(){
	
	$("#menu-home, #menu-audio, #menu-video, #menu-artikelen, #menu-forum, #menu-webshop").mouseover(function(){
	
		$("#menu-home, #menu-audio, #menu-video, #menu-artikelen, #menu-forum, #menu-webshop").removeClass('active');
		
		$(this).addClass('active');
		
		$("#submenu-home, #submenu-audio, #submenu-video, #submenu-artikelen, #submenu-forum, #submenu-webshop").removeClass('show');
		$("#submenu-home, #submenu-audio, #submenu-video, #submenu-artikelen, #submenu-forum, #submenu-webshop").addClass('hide');
		$("#sub"+this.id).addClass('show');	
			
	});
	
	$("#term").focus(function(){
	
		$(this).css("background-image", "none");
	
	});
	
	function setMenu(item){

		$("#menu-"+item).removeClass('hide');	
		$("#submenu-"+item).removeClass('hide');
		
		$("#menu-"+item).addClass('show');	
		$("#submenu-"+item).addClass('show');

	}
	
	$('.exit').mouseover(function(){
	
		$(this).css('cursor','pointer');
	
	}).click(function(){
	
		$('.exit').fadeOut('slow', function(){
		
			$('#melding').fadeOut('slow');
			
		});
	
	});
	
	$("#news-2, #news-3, #news-4, #news-5").hide();
	
	$("#newsitem-1, #newsitem-2, #newsitem-3, #newsitem-4, #newsitem-5").mouseover(function(){
	
		$(this).css('cursor', 'pointer');
	
		if($("#newsi").val() != $(this).attr('id').replace('newsitem', 'news')){
		
			$("#news-1").hide();
			$("#news-2").hide();
			$("#news-3").hide();
			$("#news-4").hide();
			$("#news-5").hide();
		
			$("#newsi").val($(this).attr('id').replace('newsitem', 'news'));
	
			var vid = $(this).attr('id').replace('newsitem', 'news');
			
			$("#" + vid).show();
			
		}
	
	});
	
	$('.trackplayer').each(
	
		function(index){}
		
	).click(function(){
	
		var track = $(this).attr('rel').split('|');
		
		//alert(track[0]);
		//alert(track[1]);
		$('#flashplayer').html('');
	    $('#flashplayer').flash(
	        { 
	          src: '/media/jw/player.swf',
	          width: 350,
	          height: 235,
	          flashvars: { foreground: '/site/icons/logo.png', backcolor: '#CEE11C', file: track[0], image: track[1], autostart: 'true', movie: '/media/JW/player.swf', allowfullscreen: 'true', allowscriptacces: 'always' }
	        },
	        { version: 8 }
	    );
	    
	    api('/api.php', 'hits', track[2], 'sethits');
	
	}).mouseover(function(){
	
		$(this).css('cursor', 'pointer');
	
	});
	
	function api(api, type, value, optie){
	
		$.post(api, { type: type, value: value }, function(data){
		
			if(!data.info){
					
				if(optie == 'sethits'){
	
					$('#hits' + data.returnID).html(data.value);
					
				}
			
			} else if(optie == 'return'){ 
			
				return data;
			
			} else {
			
				alert(data.info);
			
			}
			

		}, 'json');
	
	}
	
	$('.showhide').click(function(){
		
		if($(this).attr('src') == '/site/icons/artiestenlijst.png'){
		
			$(this).attr('src', '/site/icons/artiestenlijst2.png');

		} else {

			$(this).attr('src', '/site/icons/artiestenlijst.png');

		}
			
		var item = $(this).attr('rel');

		if($(item).css('display') == 'none'){
		
			$(item).slideToggle('slow', function() {
				
			});
			
		} else {
		
			$(item).slideToggle('slow', function() {

			});
		
		}

	}).mouseover(function(){
		
		$(this).css('cursor', 'pointer');
	
	}).mouseout(function(){
	
	});
	
	$('.dosubmit').mouseover(function(){
	
		$(this).addClass('dosubmitOver');
		$(this).css('cursor', 'pointer');
	
	}).mouseout(function(){

		$(this).removeClass('dosubmitOver');	
	
	});
	
	$("#youtubedownload").click(function(){
	
		alert($('#v').val());
		
		$.post('', { type: type, value: value }, function(data){

		});
	
	});
	
	$("*[rel^=api|]").each(function(){
	
		$(this).click(function(){
		
			var temp = $(this).attr('rel').split('|');

			if(temp[1] == 'waardering'){

				$.post('/api.php', { type: 'waardering', value: temp[2] + '|||' + temp[3]}, function(data){
				
					$('#waardering form').fadeOut(500, function(){
					
						$('#waardering').hide();
				
						$('#waardering').html(data.info).fadeIn(2500);
					
					});
				
				}, 'json');

			
			}
		
		});

	
	});
	
	$("*[rel^=location:]").each(function(){

		$(this).mouseover(function(){
		
			$(this).css('cursor','pointer');
		
		}).click(function(){
		
			var temp = $(this).attr('rel').split(':');

			if(temp[1].substr(0,7) == 'http://'){

				window.open(temp[1]);
			
			} else {

				window.location = temp[1];

			}
		
		});
	
	});
	
	function findPositions(item){
	
		area = document.getElementById(item);
		var text = area.value;
	
		if (document.selection) {
			// Internet Explorer
			var range = document.selection.createRange();
			var dpl = range.duplicate();
			
			if (range.text.length > 0) {
				dpl.moveToElementText(area);
				dpl.setEndPoint("EndToEnd", range);
				var startPosition = dpl.text.length-range.text.length;
				var endPosition = startPosition + range.text.length;
				
				return startPosition + ';' + endPosition;
				
			}
			
		} else {
			// Mozilla Firefox
			var startPosition = area.selectionStart;
			var endPosition = area.selectionEnd;
			
			return startPosition + ';' + endPosition;
			
		}
	
	}
		
	$('#reactie').ready(function(){
	
		$('.smiley').click(function(){
		
			$('#reactie').val($('#reactie').val() + $(this).attr('rel'));
			$('#reactie').focus();
		
		});
	
		$('#reactie').click(function() {
		
			var positie = findPositions('reactie');
			if(positie){
			
				$('#demo').html('Try: ' + positie );
				
			}
			
		});
	
	});
	
});
 