var URLregex = new RegExp();
URLregex.compile("(^|[ \t\r\n])((ftp|http|https|gopher|mailto|news|nntp|telnet|wais|file|prospero|aim|webcal):(([A-Za-z0-9$_.+!*(),;/?:@&~=-])|%[A-Fa-f0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?([A-Za-z0-9$_+!*();/?:~-]))","g");

function slidemeer() {
    var $leesmeerhoogte = $(window).height();
    $leesmeerhoogte2 = $leesmeerhoogte-430;
    // $("#footertop_r2").html($leesmeerhoogte2);
    
    if ( $(".slidemeer").css("height") != "0px") {
	    $(".slidemeer").css( { height:$leesmeerhoogte2 } );
	}    
}

function slideshow(pn) {
	clearTimeout(t);
	var $slidescroll = $('#slideshow').scrollLeft();
	var $slidewidth = $('#slides').width();

	if ( pn == 'prev' ) {
		if ($slidescroll != '0') { 
			var $slidescrollto = $slidescroll-970;
			}
		else {
			var $slidescrollto = $slidewidth-970;
			}
		}
	else {
		var $slidescrollto = $slidescroll+970;
		if ($slidescrollto == $slidewidth) { 
			$slidescrollto = '0';
			}
		}
	$('#slideshow').animate({scrollLeft: $slidescrollto}, {duration:500, easing:"easeInOutExpo"});
	t=setTimeout("slideshow()", 8000); 
}

$(window).resize(function() {
	slidemeer();
});

$(document).ready(function() {

	slidemeer();
	
	///
	/// SLIDESHOW
	///
	
	t=setTimeout("slideshow()", 8000);	
	
	$('#slideshow a').mouseover(function(){ 

		$(this).closest('td').find('a').stop().animate({ color:'#FFFFFF' }, 250);
		$(this).closest('td').find('.leesmeeron').stop().animate({ width:'900px'}, 250);
		$(this).closest('td').find('.leesmeeroff').stop().animate({ width:'0px', 'background-position':'-900px bottom', marginLeft:'900px'}, 250);

		clearTimeout(t);
	});
	$('#slideshow a').mouseout(function(){ 

		$(this).closest('td').find('h3').find('a').stop().animate({ color:'#f64f16' }, 250);
		$(this).closest('td').find('h4').find('a').stop().animate({ color:'#989898' }, 250);
		$(this).closest('td').find('.leesmeeron').stop().animate({ width:'0'}, 250);
		$(this).closest('td').find('.leesmeeroff').stop().animate({ width:'900px', 'background-position':'0px bottom', marginLeft:'0px'}, 250);

		/*
		$(this).stop().animate({ color:'#c9c9c9;'}, 250);
		$(this).siblings('.leesmeeron').stop().animate({ width:'0px'}, 250);
		$(this).siblings('.leesmeeroff').stop().animate({ width:'112px', 'background-position':'0px', marginLeft:'0px'}, 250);
		*/
		if ($('.slidemeer').height() == '0') { 
			t=setTimeout("slideshow()", 8000);	
		}
	});

	$('#btn_prev').mouseover(function(){ 
		$(this).children('.btn_slide_bg').stop().animate({ marginLeft:'0px'}, 100);
		$(this).children('.btn_off').stop().animate({ width:'0px'}, 100);
		$(this).children('.btn_on').stop().animate({ width:'10px', 'background-position':'0px', marginLeft:'5px'}, 100);
	});
	$('#btn_prev').mouseout(function(){ 
		$(this).children('.btn_slide_bg').stop().animate({ marginLeft:'-20px'}, 250);
		$(this).children('.btn_off').stop().animate({ width:'10px'}, 250);
		$(this).children('.btn_on').stop().animate({ width:'0px', 'background-position':'-10px', marginLeft:'15px'}, 250);
	});
	$('#btn_prev').click(function(){ 
		slideshow('prev');
	});

	$('#btn_next').mouseover(function(){ 
		$(this).children('.btn_slide_bg').stop().animate({ marginLeft:'0px'}, 100);
		$(this).children('.btn_off').stop().animate({ width:'0px', 'background-position':'-10px', marginLeft:'15px'}, 100);
		$(this).children('.btn_on').stop().animate({ width:'10px'}, 100);
	});
	$('#btn_next').mouseout(function(){ 
		$(this).children('.btn_slide_bg').stop().animate({ marginLeft:'20px'}, 250);
		$(this).children('.btn_off').stop().animate({ width:'10px', 'background-position':'0px', marginLeft:'5px'}, 250);
		$(this).children('.btn_on').stop().animate({ width:'0px'}, 250);
	});
	$('#btn_next').click(function(){ 
		slideshow();
	});

	///
	/// CASES
	///

	$('.case .casethumblink, .case a.caseballonlink').mouseover(function(){ 
		$(this).siblings('.overlay').stop().animate({ width:'185px'}, 100);
		$(this).parent().children('a').children('.caseballon').stop().animate({ width:'140px'}, 100);
	});
	$('.case .casethumblink, .case a.caseballonlink').mouseout(function(){ 
		$(this).siblings('.overlay').stop().animate({ width:'0px'}, 250);
		$(this).parent().children('a').children('.caseballon').stop().animate({ width:'0px'}, 100);
	});

	$('.case a.caseballonlink').mouseover(function(){ 
		$(this).children('.caseballon').children('h5').stop().animate({ color:'#FFFFFF;' }, 100, 'linear');
		$(this).children('.caseballon').children('.case_off').stop().animate({width:'0px',marginLeft:'141px'}, 100);
		$(this).children('.caseballon').children('.case_on').stop().animate({width:'141px'}, 100);
	});
	$('.case a.caseballonlink').mouseout(function(){ 
		$(this).children('.caseballon').children('h5').stop().animate({color:'#222222;' }, 250);
		$(this).children('.caseballon').children('.case_off').stop().animate({width:'141px',marginLeft:'0px'}, 250);
		$(this).children('.caseballon').children('.case_on').stop().animate({width:'0px'}, 250);
	});

	/// 
	/// BERICHTEN
	///
	
	$('#bericht1').stop().animate({'background-position':'0px'}, 100);
	$('#berichtimg_1').stop().animate({marginLeft:'0'}, 100);

	$('.bericht').mouseover(function(){ 
		$(this).stop().animate({'background-position':'0px'}, 100);
		$('.bericht').not(this).stop().animate({'background-position':'-370px'}, 250);
    	//$('.bericht[background-position="0px"]').stop().animate({'background-position':'-370px'}, 250);

    	
    	if ( $('.bericht').css("background-position") == "-370px 0%") {
			// $(this).stop().animate({'background-position':'0px'}, 100);
    		// $("#footertop_r2").html( 'ja!' ); // "-370px 0%"
    	}
    	else { 
    		// $("#footertop_r2").html( 'nee!' ); 
    	}
    	// $("#footertop_r2").html( $('#bericht1').css("background-position") ); 
    	
	});

	$('#bericht1').mouseover(function(){ 
		$('.berichtimg').not('#berichtimg_1').stop().animate({marginLeft:'-172px'}, 100);
		$('#berichtimg_1').stop().animate({marginLeft:'0px'}, 100);
	});

	$('#bericht2').mouseover(function(){ 
		$('.berichtimg').not('#berichtimg_2').stop().animate({marginLeft:'-172px'}, 100);
		$('#berichtimg_2').stop().animate({marginLeft:'0px'}, 100);
	});

	$('#bericht3').mouseover(function(){ 
		$('.berichtimg').not('#berichtimg_3').stop().animate({marginLeft:'-172px'}, 100);
		$('#berichtimg_3').stop().animate({marginLeft:'0px'}, 100);
	});

	$('#bericht4').mouseover(function(){ 
		$('.berichtimg').not('#berichtimg_4').stop().animate({marginLeft:'-172px'}, 100);
		$('#berichtimg_4').stop().animate({marginLeft:'0px'}, 100);
	});

	///
	/// TWITTERSTREAM
	///

	/*
	$.jTwitter('mmreclamebureau', 3, function(posts){
	
	  for(var i=0; i<posts.length; i++){
	  	 var posttext = posts[i].text;
	  	 var posttime = posts[i].created_at;
	  	 var postid   = posts[i].id;
	  	 n = posttime.lastIndexOf('+');
		 posttime1 = posttime.substring(0,n);
	
	        posttext2 = posttext.replace(URLregex, ' <a href="$2" target="_blank">$2</a> ');
	
		//TOEVOEGEN AAN ID / CLASS
	     $('#twitterkader').append(
	     	'<div class="tweet">'
	     	+ posttext2
	     	+ '<br>'
	     	+ '<a href="http://twitter.com/MMreclamebureau/status/'+postid+'" class="tweetlink" target="_blank">'
	     	+ posttime1
	     	+ '</a>'
	     	+ '</div><!-- <div class="twitterlijn"></div> -->'
	     );
	  }
	  
	  var accountlink = '<div class="tweet_footer"><a href="http://twitter.com/'
	  	+ posts[0].user.screen_name
	  	+ '">@'
	  	+ posts[0].user.screen_name
	  	+ "</a></div>"
	  $('#twitterkader').append(accountlink);
	
	});
	*/

	
});
