// JavaScript Document

$(document).ready(function() {

	// Showroom projecten
	
	$('#mycarousel').jcarousel({
			vertical: true,
			wrap: 'last',
			scroll: 4,
			buttonNextHTML: null,
			buttonPrevHTML: null,
			initCallback: mycarousel_initCallback
	});
	
	
	// Showroom album
	
	$('#showroom-img UL LI:first').show().addClass('active');
	
	$('#showroom-nav-left A').click(function() {
		var $curObj = $("#showroom-img UL LI.active");
		
		$prev = $curObj.prev();		
		$curObj.removeClass('active').hide();
			
		if ($prev.length > 0) {
			$prev.show().addClass('active');
		}
		else {
			$prev = $('#showroom-img UL LI:last').show().addClass('active');
		}
		
		$("#showroom-img UL LI").each(function(key) {
			if ($(this).is('.active')) {
				$("#showroom-current").text(key+1);
			}
		});		
		
		
		return false;
		
	});
	
	
	$('#showroom-nav-right A').click(function() {
		$curObj = $("#showroom-img UL LI.active");
		
		$next = $curObj.next();		
		$curObj.removeClass('active').hide();	
			
		if ($next.length > 0) {
			$next.show().addClass('active');
		}
		else {
			$next = $('#showroom-img UL LI:first').show().addClass('active');
		}
		
		$("#showroom-img UL LI").each(function(key) {
			if ($(this).is('.active')) {
				$("#showroom-current").text(key+1);
			}
		});		
		
		
		return false;
	});
	
});


function mycarousel_initCallback(carousel) {
	$("#showroom-list-up").bind('click', function() {
		carousel.prev();
		return false;
	});
	
	$("#showroom-list-down").bind('click', function() {
		carousel.next();
		return false;
	});
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function set_tab(id,total) {
	close_tabs(total);
	document.getElementById('tab_'+id).className = 'tab_active';
	
	var browser=navigator.appName;
	
	if (browser=="Microsoft Internet Explorer") {
		document.getElementById('content_'+id).style.display = 'block';
	}
	else {
		document.getElementById('content_'+id).style.display = 'table-row-group';		
	}
}

function close_tabs(total) {
	for (var i=1;i<=total;i++) {
		document.getElementById('tab_'+i).className = 'tab_normal';
		document.getElementById('content_'+i).style.display = 'none';
	}
}

var curr = 1;

function openWin(url, wi, he) {

  var win = window.open(url,'popup_win','width='+wi+',height='+he+',resizable=yes,status=no,toolbar=no,menubar=no, scrollbars=yes');
 
  var b = screen.width;
  var h = screen.height;
 
  b = (b - wi) / 2;
  h = (h - he) / 2;
 
  win.moveTo(b,h);

}

function set_class(obj, naam) {

  obj.className = naam;

}



var hovers = [[ [], [] ],[ [], [] ]] , images = [];

function loadHovers (tag) {

  tag_text = (tag == 0)?'img':'input';

  images[tag] = document.getElementsByTagName ( tag_text );
  
  for ( var i = 0; i < images[tag].length; i ++ ) {

    if ( images[tag].item(i).getAttribute ( 'src' ) && images[tag].item(i).getAttribute ( 'hover' ) ) {
         
      // preload it
    
      ( hovers[tag][0][i] = new Image () ).src=images[tag].item(i).getAttribute('src');
      ( hovers[tag][1][i] = new Image () ).src=images[tag].item(i).getAttribute('hover');
         
      if ( images[tag].item(i).attachEvent ) {
 
        images[tag].item(i).attachEvent ( 'onmouseover', new Function ( "hover(" + i + ", true, '"+tag+"');" ) );
        images[tag].item(i).attachEvent ( 'onmouseout', new Function ( "hover(" + i + ", false, '"+tag+"');" ) );

       } 

       else if ( images.item(i).addEventListener ) {
       
         images[tag].item(i).addEventListener ( 'mouseover', new Function ( "hover(" + i + ", true);" ), true );
         images[tag].item(i).addEventListener ( 'mouseout', new Function ( "hover(" + i + ", false);" ), true );
    
       }
     }
   }

   if (tag != 1) {

     loadHovers(1);

   }

}

function hover ( index, mouseover, tag ) {

   images[tag].item( index ).setAttribute ( 'src', hovers[tag][mouseover?1:0][index].src );

}


function markRow(rowobj, nClass) {
	
  var theCells = null;

  if (rowobj.cells != 'undefined') {

    theCells = rowobj.cells;
	
  }

  else if (rowobj.getElementsByTageName('td')) {

    theCells = rowobj.getElementsByTageName('td');

  }

  cntCells = theCells.length;
  
  if (cntCells > 0) {

    for (i=0;i<cntCells;i++) {
		
      theCells[i].className = nClass;
  
    }

  }

}



function checkForm(form) {

  var aantal = form.elements.length;

  var string = 'U heeft de volgende verplichte veld(en) niet ingevuld: \n';

  string += '_______________________________________________________\n';

  var returnbool = true;

  for (var i=0;i<aantal;i++) {

    if (form.elements[i].type == 'checkbox') {

      if (form.elements[i].title.length > 0 && !form.elements[i].checked) {

	string += form.elements[i].title+'\n';

        returnbool = false;

      }

    }

    else if (form.elements[i].value.length == 0 && form.elements[i].title.length > 0 && !form.elements[i].disabled && form.elements[i].style.display != 'none') {

      string += form.elements[i].title+'\n';

      returnbool = false;

    }

  }

  if (returnbool) {

    return true;

  }

  else {

    string += '______________________________________________________\n';

    string += 'Vul deze velden in om de actie te voltooien';

    alert(string);

    return false;

  }

}
