

$(document).ready(function(){
	// LIST

	$(".table .item_clickable").click(function() {
		var url=$(this).parent().attr("url");
		window.location.href=url;
	});

	$(".table .row_clickable").hover(function() {

		$(this).addClass("row_clickable_over");	
		},
		function() {
		$(this).removeClass("row_clickable_over");	
		});	

	$('.table tr:odd').addClass('row0');
	$('.table tr:even').addClass('row1');
	
	$(".table .legend .sortable").click(function() {
		var url=$(this).find("a").attr("href");

		window.location.href=url;

	});

	// ImagePopup
	
	$(".mediaPopup").click(function() {
		var url=$(this).attr("src");
		url=url.replace(/size=0/, "size");
		url=url.replace(/size=1/, "size");
		url=url.replace(/size=2/, "size");
		url=url.replace(/size=3/, "size");
		url=url.replace(/size/, "size="+$(this).attr("targetSize"));
		
		$.ImagePopup.show(url);
	});

	// ImagePopup
	
	$(".imagePopup").click(function() {
		$.ImagePopup.show($(this).attr("image"));
	});


	// Email
	$('.emailLink').each(function(i) {
		var at = / at /;
		var dot = / dot /g;
		var addr = $(this).text().replace(at,"@").replace(dot,".");
		$(this).html('<a href="mailto:'+addr+'">'+ addr +'</a>');
	});
	
	

	// TabInline
	$('.tabInline .tabContent').hide();

	$('.tabInline .tabLinkSel').each(function(i) {
  	$('#'+$(this).attr('tabId')).show();
  });
  
  
  
	$('.tabInline .tabLink').click(function() {
    $(this).parents(".tabInline").find('.tabLinkSel').removeClass('tabLinkSel');
    $(this).addClass('tabLinkSel');
    $(this).parents(".tabInline").find('.tabContent').hide();

   	$('#'+$(this).attr('tabId')).show();
   }
  );
  	
  	
	$('.tabInline .tabLink').mouseover(function() {
     	$(this).addClass('tabLinkOver');	
	});


	$('.tabInline .tabLink').mouseout(function() {
     	$(this).removeClass('tabLinkOver');	
	});
	
	
		
	// TabList
	$('.tabList .itemContent').hide();

	$('.tabList .itemLinkSel').each(function(i) {
  	$('#'+$(this).attr('itemId')).show();
  });
  

	$('.tabList .itemLink').click(function() {

  
    $(this).parents(".tabList").find('.itemLinkSel').removeClass('itemLinkSel');
    $(this).addClass('itemLinkSel');
    $(this).parents(".tabList").find('.itemContent').hide();

   	$('#'+$(this).attr('itemId')).show();
   }
  );
  	
  	
	$('.tabList .itemLink').mouseover(function() {
     	$(this).addClass('itemLinkOver');	
	});


	$('.tabList .itemLink').mouseout(function() {
     	$(this).removeClass('itemLinkOver');	
	});
	

	// contentSelect
	$('.contentSelect .itemContent').hide();
  
	$('.contentSelect .contentSelector :selected').each(function(i) {
  	$('#'+$(this).val()).show();
  });
  


	$('.contentSelect .contentSelector').change(function() {
  
    $(this).parents(".contentSelect").find('.itemContent').hide();
    $("#"+$(this).find(':selected').val()).show();

   }
  );
	
	// Confirmlink
	$('.confirmLink').click(function() {
      var answer = confirm('Weet u zeker dat u deze actie wilt uitvoeren?');
      return answer;
  });
	
	// Form

  $('.frm .fieldSms').keyup(function() {
				validChar='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,?!@-()\/:;{}[]<=>?¡èéùìòÇØøÅåÄÖÑÜ§¿äöñüà \r\n';
				
				var text=$(this).val();

				newstring="";
				for (i=0;i<text.length;i++){
					char=text.charAt(i);
					if(validChar.indexOf(char)>=0){
						newstring=newstring+char;
					}
				}

				if (text.length > 160) {
					newstring=newstring.substr(0,160)
				}

				if (newstring.length!=text.length) {
					$(this).val(newstring);
				}


				var left = 160 - newstring.length;
				
				$("#"+$(this).attr("id")+"_chars").html(left+" ");
		
			
  });

  // Default field value
	$('.formFieldDefault').each(function(i) {
	 if ($(this).val()=="") {
    $(this).val($(this).attr("basicText"));
    $(this).addClass("formFieldDefaultValue");
   }
	});

  $('.formFieldDefault').focus(function() {
	 if ($(this).val()==$(this).attr("basicText")) {
    $(this).val("");
    $(this).removeClass("formFieldDefaultValue");

   }
  });

  $('.formFieldDefault').blur(function() {
	 if ($(this).val()=="") {
	  
    $(this).val($(this).attr("basicText"));
    $(this).addClass("formFieldDefaultValue");

   }
  });


});






/*****************************************************************************
   *
   * IMage popup
   *  
   ****************************************************************************/
  $.ImagePopup= {
	
    show: function(img) {


	// Hide objects that are always on top
  	$("object").css("visibility","hidden");
  	$("embed").css("visibility","hidden");
      	$("select").css("visibility","hidden");

	
	// Create background
	var background = $('<div/>');
	$(background).attr('class', 'ImagePopupBackground');
	$(background).css("opacity","0");
	$(background).animate({'opacity' : '.7'}, 300);

	var height=$(document.body).height();
	if (height<$(window).height()) {
		var height=$(window).height();	
	}

	$(background).css(
		{
		'width' : $(document).width(),
		'height' : height

		});

	$('body').append(background);

	// Create image 

	var newImage = $('<img/>');
	var width = $('body').width();
	$(newImage).attr('src',img);
	$(newImage).attr('class', 'ImagePopupImg').css(
		{
	
		});
	


	$('body').append(newImage);
	

	// Wait for image to load
 
	$(newImage).css('visibility','hidden');
	$(newImage).load(function () {
		
		$(newImage).css('visibility','visible');
		var top=$(newImage).vCenter();

		
		
 		$(this).css("left",$(document).width()/2-$(this).width()/2);

		$(this).css({'opacity' : '.1'});
		$(this).animate({'opacity' : '1'}, 300, function() {

			$(this).bind('click', function() {



				$(this).fadeOut(400, function() {
					$(this).remove();
					$("object").css("visibility","visible");
		  			$("embed").css("visibility","visible");
		      			$("select").css("visibility","visible");

				});
				$('.ImagePopupBackground').fadeOut(400, function() {
					$(this).remove();
				});
			});
		});
	});
    }

  };



  