$(document).ready(function()
{

$('.slideshowlink').hide();
var lang = getLang();
var link = getPage();

initOfferte();
if(lang == ""){
initNieuws("nl");
}else {
initNieuws(lang);
}

if(lang == "nl") {$("li.lang_switch_nl a").addClass("active");}
else {$("li.lang_switch_en a").addClass("active"); }

$(".callback input.submit").click(function() {
if(lang == "nl"){
call("U wordt zo spoedig mogelijk teruggebeld!");
} else {
call("We will call you back as soon as possible!");
}
});

});


function getLang() 
{
var url = document.URL;
url = url.split("&"); 
if(url[1]){
tempLang = url[1].split("=");
defLang = tempLang[1];
} else {
defLang = "nl";
}
return defLang;
}

function getPage() 
{
var url = document.URL;
url = url.split("&"); 
path = url[0].split("/");
page = path[3];
return page;
}

function call(m)
{
  $.post("../call.php", { phone: $('#callback').val() } );
  if (m) alert(m);
  $('#callback').val('');
}

function initOfferte()
{
 $('#offerte_banner').click(showOfferte);
}

function showOfferte()
{
  $('#offerte_form').show();
  $('#offerte_banner').hide();
}

function hideOfferte()
{
  $('#offerte_form').hide();
  $('#offerte_banner').show();
}

function submitForm(button, message) 
{
  var form = button.form;
  var params = $(form).serialize(); // + '&_eventName=' + button.name;
  $.post(form.action, params, function(data) 
  {
    form.reset();
    hideOfferte();
    if (message) alert(message);        
  });
  return false;
}

function initNieuws(lang)
{
/* Read more and less links */
$('#main ul li p span').parent().next().addClass("smal");
$('.smal ~ p').addClass("smal");
$('.smal').hide();
if(lang == "en") $('#main ul li a.more').text("Read more >"); 

 
 $('#main ul li a.more').click(function() {

	 $(this).parent().addClass("this");
	 $('li.this .smal').toggle();
	 if(lang == "en" && $(this).text()=="Close"){$(this).text("Read more >");}
	 else if(lang == "en" && $(this).text()=="Read more >"){$(this).text("Close");}
	 if(lang == "nl" && $(this).text()=="Sluiten"){$(this).text("Lees verder >");}
	 else if(lang == "nl" && $(this).text()=="Lees verder >"){$(this).text("Sluiten");}
	 
	 //$('li.this a.more').toggle($('this').attr("html","Sluiten"),$('this').attr("html","Lees meer >"));
	 //$('li a.more').removeClass("more").addClass("less");
	 $(this).parent().removeClass("this");
	 });
 
 /* images popup box */
 
 //$('#main ul li a.popup img').lightBox();
 $('#main ul li a img.popup').each(function() {
 var imgSrc = $(this).attr("src");
	imgSrc = imgSrc.split("/"); 
	imgName = imgSrc[imgSrc.length-1].split(".");
	//imgTussen = imgName[0].split("_");
	imgGroot = imgName[0] + "_groot." + imgName[1];
	imgPath = "";
	for(i=0;i<imgSrc.length-1;i++){
	imgPath = imgPath + imgSrc[i] + "/";
	}
	$(this).parent().attr("href", imgPath + imgGroot);

	$(this).parent().addClass("thickbox");
 });
}

