jQuery.is_numeric = function(p_mVar){
	if(p_mVar === ''){
		return false;
	}
	return !isNaN(p_mVar * 1);
}

jQuery.preloadImages = function(){
	for(var i = 0; i<arguments.length; i++){
		jQuery("<img>").attr("src", arguments[i]);
	}
}

jQuery.news = function(lang, nr){
	$.post('/'+lang+'/news', {item_nr : nr}, function(ServerResponseData){
		var responseData = eval('('+ServerResponseData+')');
		$('#content_master_sub').animate({"opacity" : 0.0}, 600, "swing", function(){
			$('#content_top h1').html(responseData.title);
			$('#menu_lev_3').html(responseData.menu);
			$('#content_container').html(responseData.data);
			$('#content_master_sub').animate({opacity: 1.0}, 600, "swing");
			$('#content_bottom').jScrollPane();
		});
	});
}

jQuery.newPage = function(idx, menuno, url, lang, parent_idx, and_idx){
	switch(menuno){
		case 1:
			nimg = 'img_bg_home.jpg';
			break;
		case 2:
			nimg = 'img_bg_over_celectric.jpg';
			break;
		case 3:
			nimg = 'img_bg_producten.jpg';
			break;
		case 4:
			nimg = 'img_bg_service.jpg';
			break;
		case 5:
			nimg = 'img_bg_contact.jpg';
			break;
		case 100:
			nimg = "";
			break;
		default:
			nimg = 'img_bg_home.jpg';
	}

	//if(nimg != '' && $('#content_master').css("background-image").indexOf(nimg) === -1){
		$('#content_master').animate({"opacity" : 0.0}, 600, "swing", 
			function(){
				$('#content_master_sub').load("/"+lang+"/ajax/"+url, {pidx : parent_idx, aidx : and_idx}, function(){
					if(nimg != '' && $('#content_master').css("background-image").indexOf(nimg) === -1){
						$('#content_master').css("background-image","url(/images/"+nimg+")").animate({"opacity" : 1.0}, 600, "swing");
					}else{
						$('#content_master').animate({"opacity" : 1.0}, 600, "swing");
					}
					$('.selected').removeClass("selected");
					if($.is_numeric(parent_idx)){
						$('.menuitem'+parent_idx).addClass("selected");
					}
				
					if($.is_numeric(and_idx)){
						$('.menuitem'+and_idx).addClass("selected");
					}
				
					$('.menuitem'+idx).addClass("selected");
					selected_item = idx;
					//document.title = $('#page_title').html();
					$('#content_bottom').jScrollPane();

					$("#gallery a").lightBox({fixedNavigation:true});
					//-- anti spam
					if($(".nawform").size()>0){
						$(".nawform").append($('<input type="hidden" name="js-antispam-validate" value="true"/>'))
					}
					
				});
			}
		);
// 	}else{
// 		$('#content_master_sub').animate({"opacity" : 0}, 600, "swing", function(){
// 			$('#content_master_sub').load("/"+lang+"/ajax/"+url, {pidx : parent_idx, aidx : and_idx}, function(){
// 				$('#content_master_sub').animate({"opacity" : 1}, 600, "swing", function(){
// 					$('#content_bottom').jScrollPane({reinitialiseOnImageLoad:true});
// 				});
// 				$('.selected').removeClass("selected");
// 				if($.is_numeric(parent_idx)){
// 					$('.menuitem'+parent_idx).addClass("selected");
// 				}
// 			
// 				if($.is_numeric(and_idx)){
// 					$('.menuitem'+and_idx).addClass("selected");
// 				}
// 			
// 				$('.menuitem'+idx).addClass("selected");
// 				selected_item = idx;
// 				//document.title = $('#page_title').html();
// 			});
// 		});
// 	}
}

$(function(){
	//-- anti spam
	if($(".nawform").size()>0){
		$(".nawform").append($('<input type="hidden" name="js-antispam-validate" value="true"/>'))
	}
	$.preloadImages('/images/img_bg_home.jpg', '/images/img_bg_over_celectric.jpg', '/images/img_bg_producten.jpg', '/images/img_bg_service.jpg', '/images/img_bg_contact.jpg');
	$('#main_menu').hover(function(){
		if(!window.menubusy){
			$('.nav_lev_2').fadeIn("slow");
		}
	}, function(){
		window.menubusy = true;
		$('.nav_lev_2').fadeOut("slow", function(){
			window.menubusy = false;
		});
		
	});
	$('#search_input').bind("focus" ,function(){
		window.tempsearch = $('#search_input').val();
		$('#search_input').val('');
	});
	$('#search_input').bind("blur" ,function(){
		if($('#search_input').val() == ''){
			$('#search_input').val(window.tempsearch);
		}
	});

	$('#language_selector').hover(function(){
		$('#all_languages').fadeIn("fast");
		$('#lang_arrow').attr("src", "/images/img_arrow_black_down.jpg");
	}, function(){
		$('#all_languages').fadeOut("fast");
		$('#lang_arrow').attr("src", "/images/img_arrow_black.jpg");
	});
	$('#content_bottom').jScrollPane();

	$('#catalog').popupWindow({ 
		windowURL:'/scripts/catalog.html',
		windowName:'swip',
		height:700,
		width:900,
		scrollbars:1,
		centerScreen:1
	}); 
});

