var cmsSearchFacade = 'http://neo.i-engine.nl/services/remote/search/jsoncmssearchfacade.cfc?wsdl';
var websiteID = 125;
var _path = "";

function nav(url) {
	document.location.href = url;
}

$(document).ready(function(){													 

$('<div id="searchBoxHolder"></div>').appendTo($('body'));

	/* Zoekresultaten */
	if( $("#mainMenu").size() ) {
		$("ul.nav li").hover(
			function() { $("ul:not(.sublevel)", this).show(); }, 
			function() { $("ul:not(.sublevel)", this).hide(); } 
		);
		$("ul.nav li").hoverClass("hover");
		$("ul .sublevel").parent().addClass("sublevel").hover(
			function(){ $("ul", this).show(); }, 
			function() { $("ul", this).hide(); } 
		);
		$("li:has(ul)").addClass("sublevel");
	}

	$("#x").click( function(){
			var obj = $("#loading");
			if( $(obj).css("display") == 'none'){
				 $(obj).fadeIn("slow");
			} else {
				$(obj).fadeOut("slow"); } 
			}
		);
	
	var _currentItem = null;
	
	if( $("#home").size() ) {
	
	$("#portal .item").each(function(i,n){
			$(n).mouseover( function(){ 
				
					if(_currentItem != i){
						_oldItem = _currentItem;
						_currentItem = i;
						//$("li","#concept").eq(_oldItem).fadeOut().hide();
						$("li","#concept").eq(_oldItem).hide();
						//$("li","#concept").eq(i).fadeIn("slow");
						
							$("li","#concept").eq(i).show();
						if( i > 0 ){}
						$(n).siblings(".active").removeClass("active")
						if( i > 0 ){
							$(n).addClass("active");
						}
						$("#rightPortal .holder").eq(0).empty();
						//$("#rightPortal .holder").append($("p.hidden",n).html());
						$("p.hidden",n).clone().removeClass("hidden").appendTo( $("#rightPortal .holder") );
						$("span.thumbnail",n).clone().removeClass("hidden").prependTo( $("#rightPortal .holder") );
					}
				} 
			);
			$(n).click( function(){ 
					document.location.href = $(this).children("a:eq(0)").attr("href");							 
			});
			$(n).click( function(){ 
				window.location=$(this).find("a").attr("href"); return false;
			});
	});
	
		$("#portal .item:eq(0)").trigger("mouseover");
		switchChannels(0);
	}

	// execute sifr replacements
	replacements();
});

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};	

/* SIFR 2.0.2 */
fontLoc = '/media/trebuchet.swf';
var replacements = function(){
	if(typeof sIFR == "function"){
		sIFR.replaceElement(named({sSelector:"#concept h1", sFlashSrc:fontLoc, sColor:"#FFFFFF", sLinkColor:"#FFFFFF", sBgColor:null, sHoverColor:"#FFFFFF", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"h2.lightorange", sFlashSrc:fontLoc, sColor:"#FFCC66", sLinkColor:"#FFCC66", sBgColor:null, sHoverColor:"#FFCC66", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:".item h2", sFlashSrc:fontLoc, sColor:"#FFFFFF", sLinkColor:"#FFFFFF", sBgColor:null, sHoverColor:"#FFFFFF", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"h2.blue", sFlashSrc:fontLoc, sColor:"#475E70", sLinkColor:"#475E70", sBgColor:null, sHoverColor:"#475E70", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"#leftContent h2", sFlashSrc:fontLoc, sColor:"#475E70", sLinkColor:"#475E70", sBgColor:null, sHoverColor:"#475E70", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"#rightContent h2", sFlashSrc:fontLoc, sColor:"#475E70", sLinkColor:"#475E70", sBgColor:null, sHoverColor:"#475E70", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"h3", sFlashSrc:fontLoc, sColor:"#475E70", sLinkColor:"#475E70", sBgColor:null, sHoverColor:"#475E70", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0"}));
	};
}
	
var _counter = 0;
function switchChannels(){
	setTimeout("switchChannels("+_counter+")",10000)
	$("#portal .item:eq("+_counter+")").trigger("mouseover"); 
	if(_counter == 4) _counter = 0;
	else _counter++;
}


/* zoeken */
function checkForms(){
	$("#searchForm").validate({
		rules: {
			searchWord: {
				required: true,
				minLength: 3
			}
		},
		messages: {
			searchWord: "Geef een geldig zoekwoord op"
		},
		errorLabelContainer: $("#searchWordMessage")
	}); 
	//$("#searchWordMessage").style.display = 'block';
	//$("#emailErrorMessage").style.display = 'block';
	swapValues = [];
	$("input.text").each(function(i){
			swapValues[i] = $(this).val();
			$(this).focus(function(){
					if ($(this).val() == swapValues[i]) {
							$(this).val("");
					}
			}).blur(function(){
					if ($.trim($(this).val()) == "") {
							$(this).val(swapValues[i]);
					}
			});
	});
}

/*  Andere naam voor functie, oude website gebruikt zelfde naam vandaar 'do' ervoor */
function doSearch(){
	checkForms();
	searchString = $("#searchWord").val();
	searchBoxString = '<div id="searchBox"><div class="close"><img src="/img/close.gif" alt=""/></div><div class="content"><h1 id="searchWordHolder">Zoekresultaten voor: </h1></div><div id="searchContent" class="content"><div class="loader"><img src="/img/loading.gif" alt="Laden..."/></div></div></div>';
	$("#searchBoxHolder").html(searchBoxString);
	$("#searchWordHolder").append(searchString);
	$.extend($.blockUI.defaults.overlayCSS, { backgroundColor: '#000' });
	$.extend($.blockUI.defaults.pageMessageCSS, { color: '#000', backgroundColor: '#FFF' });
	var searchBox = $('#searchBox');
	$("#searchBox .close").click(function(){
			$.unblockUI();
			$(".blockUI").remove();
	});
	$.blockUI(searchBox); 
	$.getJSON(cmsSearchFacade+'&method=search&websiteID='+websiteID+'&searchString='+searchString+'&jsCallBack=?', function(data){ 
		var row = "";
		if(data["DATA"].length){
			$(data["DATA"]).each(function(i,n){
				var fileName = n[2];
				var map = n[1];
				var title = n[3];
				var content = n[4];
				var pos = n[5] - 1;
				if(pos > 50){
					startPosition = pos - 50;
				}
				else {
					startPosition = 0;
				}
				row += '<tr>';
				row += '<td valign="top">' + (i+1) + '</td>';
				row += '<td valign="top"><a href="http://www.i-concept.nl' + map + '/' + fileName + '">' + title + '</a></td>';
				row += '<td valign="top">&hellip;' + content.substr(startPosition,100) + '&hellip;</td>';
				row += '</tr>';
			});
			$("#searchBox #searchContent").html("<table>" + row + "</table>");
		} 
		else {
			$("#searchBox #searchContent").html("Geen resultaten.");
		}
	});	
}

/* i-Concept 2007 website */
function showButton(obj){
	obj.style.width=84+'px';
	document.getElementById('seachButton').style.display='inline';
}
function searchWord(){
	var word = document.getElementById('word').value;
	document.location.href='http://www.i-concept.nl/search/searchmain.cfm?SearchString='+word;
}
function setTekst(obj, tekst) {
	var naam = obj.value;
	if (naam == tekst) { obj.value = ''; }
	else if (naam == '') { obj.value = tekst; }
}

