//var host = 'http://localhost/projecten/dinnerjudge.nl/';
var host = 'http://www.dinnerjudge.nl/';

//
function toggle( id ) {
  var sh = $( id );
  if( sh ) {
    if( sh.style.display == 'none' ) {
      sh.style.display = 'block';
    } else {
      sh.style.display = 'none';
    }
  }
}

function timedToggle( id, time ) {
  if( time == '' ) time = 1000;
  setTimeout("toggle( '" + id + "' )", time);
}

function slideDivVertical( divID ) {
  if( $(divID) ) {
    var mySlide = new Fx.Slide( divID, {mode: 'vertical'});
    mySlide.slideOut();
  }
}
function slideOutDivHorizontal( divID ) {
  if( $(divID) ) {
    var mySlide = new Fx.Slide( divID, {mode: 'horizontal'} );
    mySlide.slideOut();
  }
}
function slideInDivHorizontal( divID ) {
  if( $(divID) ) {
    var mySlide = new Fx.Slide( divID, {mode: 'horizontal'} );
    mySlide.slideIn();
  }
}

//JS DOM extention
function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}



function addBrowserFavorite( domein )
{
  var pageUrl = 'http://www.dinnerjudge.nl/';
  var title = 'DinnerJudge.nl';
  
  //window.external.AddFavorite( pageUrl , title );
  
  if (window.sidebar)
	{
		window.sidebar.addPanel(title, pageUrl,"");
	}
	else if(window.external)
	{
		window.external.AddFavorite(pageUrl, title);
	}
	else if(window.opera && window.print)
	{
		var mbm = document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',pageUrl);
		mbm.setAttribute('title',title);
		mbm.click();
	}
}


function checkEnter( event ) {
  if (event && event.keyCode == 13)
    doBlockSearch();
  else
    return true;
}



//POLL
function setPollAnswer( answer ) {
  var selectedanswer = $('selectedanswer');
  
  selectedanswer.value = answer.value;
}

function submitPoll() {
  var pollAnswer = $('selectedanswer').value;
  var pollID = $('pollID').value;
  
  if( pollAnswer != '' && pollID != '' ) {
    
    //Start ajax call
    //Target ID
  	var id = 'polldata';
  	showAjaxLoader( id );
      
    //Send the data
    var postValues = '&a=pollvote';
    postValues += '&pollID=' + pollID;
    postValues += '&answer=' + pollAnswer;
    
    //serialize the postValues
  	postValues = encodeURI( postValues );
  	
  	if( postValues != '' ) {
    	var url = host + 'scripts/ajax/ajax.php?t=action';   
      var functionCall = 'displayHTML( http_request, \'' + id + '\');'; //output weergeven
    	
    	//call Async Ajax
    	doAsyncAjax( url, postValues, functionCall );
  	}  
  }
  
}















/* DJ */
var currentRTab = 'test';
function switchRTab( tabID ) {
  
  //Hide the old tab
  if ( currentRTab != '' ) {
    $(currentRTab).style.display = 'none';
  }
  
  //Show the new tab & set the new tab as the old tab
  $(tabID).style.display = 'block';
  currentRTab = tabID;
}



/* image block restaurant */

var currentImageNr = 0;
function nextImage() {
  var max = $('blockImageMax').value;
  if( currentImageNr + 1 < max ) {
    slideOutDivHorizontal( 'blockImage' + currentImageNr );
    
    currentImageNr = currentImageNr + 1;
  }
  
}
function previousImage() {
  
  //Check if at the beginning
  if( currentImageNr > 0 ) {
    currentImageNr = currentImageNr - 1;

    slideInDivHorizontal( 'blockImage' + currentImageNr );
  }
  
  
}







function log(text, args) {
	if (window.console) console.log(text.substitute(args || {}));
}