$(document).ready(function() {
	
	$('html').addClass('js-on');  
	
	$("input").focus(function () {
	if ($(this).val() == $(this).attr("title")){
		$(this).val("");
	}
	});
	$("input").blur(function () {
		if ($(this).val() == ""){
			$(this).val($(this).attr("title"));
		}
	});

	$("a#open-login").fancybox();
	
	/* fotoboek */
	$(".fancybox-view-01 ul a").fancybox();
	
	$(".fancybox-view-02 ul a").fancybox({
			titlePosition: 'over'
	});
	if( $(".kijkglas-nieuws a:first").length > 0) {
		/* url ophalen om kop van kijkglas link te geven naar module */
		var str1 = $(".kijkglas-nieuws a:first").attr("href");
		var iLastSlash1 = str1.lastIndexOf('/');
		str1 = str1.slice(0, iLastSlash1);
		$(".kijkglas-nieuws h3").html('<a href="' + str1 + '">Nieuws</a>');
	}
	if( $(".kijkglas-agenda a:first").length > 0) {	
		/* url ophalen om kop van kijkglas link te geven naar module */
		var str2 = $(".kijkglas-agenda a:first").attr("href");
		var iLastSlash2 = str2.lastIndexOf('/');
		str2 = str2.slice(0, iLastSlash2);
		$(".kijkglas-agenda h3").html('<a href="' + str2 + '">Agenda</a>');
	}
	/* beheerbutton fotoboek */
	if($("table.maintenanceButtons").length > 0) {
		$("span.delete").css('display','block');
		$("span.edit").css('display','block');
		$("a.add-item").css('display','block');
	}
	$(".banner-icons a").each(function(i){
		$(this).addClass("icon" + ++i);
	}); 
	/* smoelenboek */
	$(".smoelenboek a").fancybox();
	
	/* fold back last menu item */
	$(".navigation.main>ul>li:last").addClass("last");
	
	
	/* nieuws slide */
	$(".news .item h3").click(function () { 
		$(this).next('a').slideToggle("slow").next('div').slideToggle("slow");
	});
   
	$(".uitklappen").click(function () { 
		$(".item div").slideDown("slow");
		$(".item a").slideUp("slow");
	});
   
	$(".inklappen").click(function () { 
		$(".item div").slideUp("slow");
		$(".item a").slideDown("slow");
	});
	
	/* nieuws slide */
	$(".faq .item h3").click(function () { 
		$(this).next('div').slideToggle("slow");
	});
	
	if ( $("#ImagesDiv.ImagesSpecificDiv").size()==1 ) {
		var sDataUrl = "/" + sInitCustomerDir + "/ceData.asp"
			+ "?CustID=" + sInitCustomerID
			+ "&ComID=" + sInitCommunityID
			+ "&ModID=" + sInitModuleID
			+ "&ItemID=" + sInitItemID
			+ "&SessionID=" + sInitSessionID
			+ "&Action=FileList"
			+ "&Template=ceUploaddataThumbWidth"
			+ "&ThumbWidth=152"
			+ "&Dir=" + "/" + sInitCustomerDir + "/UploadData/images/" + sInitCommunityID + "/" + sInitModuleID + "/" + sInitItemID
			+ "&Output=JSON"
			+ "&Time=" + sInitTime
		;
		$.getJSON(
			sDataUrl
		,	function (jsonData) {
				var sHtml="";
				for (var i=0; i<jsonData.length; i++) {
					sHtml += "<li><a href ='" + jsonData[i].url + "' rel='ImagesSpecific' target=_new>"
						+ "<img src='" + jsonData[i].ceDataThumbW152 + "'></a></li>\n";
				}
				sHtml += "\n";
				$("#imagescroll").html( sHtml );

				window.setTimeout('$("#imagescroll a").fancybox()', 100);	
			
				if ( jsonData.length > 4 ) {
					$(".ImagesSpecificDiv").jCarouselLite({
						btnPrev: ".back",
						btnNext: ".next",
						scroll: 1,
						speed: 500,
						circular:true
					});
				} else {
					$( "#ImagesDiv .button").remove();
				}
			}
		);
	}
	
	//alert( $("#ItemsUl.list.smoelen").size() );
	if ($("#ItemsUl.list.smoelen").size()==1) {
		$("#ItemsUl span").each(
			function () {
				var sSpanID = this.id.replace("span","");
				var sDataUrl = "/" + sInitCustomerDir + "/ceData.asp"
					+ "?CustID=" + sInitCustomerID
					+ "&ComID=" + sInitCommunityID
					+ "&ModID=" + sInitModuleID
					+ "&ItemID=" + sSpanID
					+ "&SessionID=" + sInitSessionID
					+ "&Action=FileList"
					+ "&Template=ceUploaddataThumbWidth"
					+ "&ThumbWidth=152"
					+ "&Count=1"
					+ "&Dir=" + "/" + sInitCustomerDir + "/UploadData/images/" + sInitCommunityID + "/" + sInitModuleID + "/" + sSpanID
					+ "&Output=JSON"
					+ "&Time=" + sInitTime
				;
				$.getJSON(
					sDataUrl
				,	function (jsonData) {
						if ( jsonData && jsonData.length==1 ) $("#span" + sSpanID ).html( "<img src='" + jsonData[0].ceDataThumbW152 + "'>" );
					}
				);
			}
		);
	}
	
	//alert( $("#ItemsUl.list.group").size() );
	if ($("#ItemsUl.list.group").size()==1) {
		$("#ItemsUl span").each(
			function () {
				var sSpanID = this.id.replace("span","");
				var sDataUrl = "/" + sInitCustomerDir + "/ceData.asp"
					+ "?CustID=" + sInitCustomerID
					+ "&ComID=" + sInitCommunityID
					+ "&ModID=" + sInitModuleID
					+ "&ItemID=" + sSpanID
					+ "&SessionID=" + sInitSessionID
					+ "&Action=FileList"
					+ "&Template=ceUploaddataThumbWidth"
					+ "&ThumbWidth=152"
					+ "&Count=-1"
					+ "&Dir=" + "/" + sInitCustomerDir + "/UploadData/images/" + sInitCommunityID + "/" + sInitModuleID + "/" + sSpanID
					+ "&Output=JSON"
					+ "&Time=" + sInitTime
				;
				$.getJSON(
					sDataUrl
				,	function (jsonData) {
						if ( jsonData && jsonData.length==1 ) $("#span" + sSpanID ).html( "<img src='" + jsonData[0].ceDataThumbW152 + "'>" );
					}
				);
			}
		);
	}

	// dit was de mooiste fix geweest, maar css werkt niet goed in IE7
	//$("#M_1 .nivo2>li:even").css("clear", "left");
	//$("#M_2 .nivo2>li:even").css("clear", "left");
	//$("#M_3 .nivo2>li:even").css("clear", "left");
	
	
	$(".main>ul>li").each(function() {
		var blabla = 0;
		$(this).find(".nivo2>li").each(function() {
			++blabla;
			if(blabla == 2){
				$(this).after("<li style='width:100%;height:1px;' />");
				blabla = 0;
			}
		})
	})
	
});
