var popupStatus = 0;
var womenBar = 6;
var secondaryBar = 6;
var loadingBar = 0;
var erasedLogin = 0;
var antiBounce = 0;
function stripos ( f_haystack, f_needle, f_offset ){
    var haystack = (f_haystack+'').toLowerCase();    var needle = (f_needle+'').toLowerCase();
    var index = 0; 
    if ((index = haystack.indexOf(needle, f_offset)) !== -1) {
        return index;    }
    return false;
}     
function preCheck(rel){
  $('.checkBox[rel='+rel+']').addClass("checkedBox");
  $('.checkBox[rel='+rel+']').removeClass("checkBox");    
  $('#'+rel).attr("value",1);
}
$(document).ready(function(){
   $('.searchRow[rel=znaam] input').change(function(){
      var myVal = $(this).attr("value");
      if(myVal !== ''){
        $('.searchRow[rel!=znaam] input').attr("disabled","disabled");
      }else{
        $('.searchRow[rel!=znaam] input').removeAttr("disabled");
      }
   });
   $('#logRef').click(function(){ if(erasedLogin === 0){ $(this).attr("value",""); erasedLogin = 1; } });
   $('.moreProfiles').click(function(){
     if(loadingBar == 0){
        loadingBar = 1;
        var whichBar = $(this).attr("rel");
        if(whichBar == "women"){
          if(womenBar < 41){
            var slideIn = womenBar + 5;
            $('.onlineWomen .liveProf').hide(); 
              setTimeout(function(){
                for(womenBar;womenBar<=slideIn;womenBar++){
                   $('.onlineWomen .liveProf[rel='+womenBar+']').fadeIn(600);  
                }
              },50);
          }
          loadingBar = 0;
        }else{
           if(secondaryBar < 41){
             var slideIn = secondaryBar + 5;
              $('.onlineMen .liveProf').hide();
                setTimeout(function(){
                  for(secondaryBar;secondaryBar<=slideIn;secondaryBar++){
                     $('.onlineMen .liveProf[rel='+secondaryBar+']').fadeIn(600);  
                  }
                },50);
            }
            loadingBar = 0;
          }
      }
   });
   $('.logo,#logo').click(function(){ window.location='http://www.nieuwsexcontact.nl/'; });
   $('.hoverAction,.popupHistory').hover(function(){
      var srcNew = $(this).attr('src').replace('.png','_hover.png');
      $(this).attr('src',srcNew);
   },function(){
      var srcNew = $(this).attr('src').replace('_hover','');
      $(this).attr('src',srcNew);
   }); 
   $('.introNav div').hover(function(){
     var currentClass = $(this).attr("class");  
     if(stripos(currentClass,'_content') === false){   
       if(stripos(currentClass,'_sel') === false){         //if NOT selected 
          $(this).removeClass(currentClass);
          $(this).addClass(currentClass+"_sel");
       }
     }                               
   },function(){
     var currentClass = $(this).attr("class");  
     var currentId = $(this).attr("id");
     if(currentId === ""){
       if(stripos(currentClass,'_content') === false){   
         if(stripos(currentClass,'_sel') !== false){         //only if selected  
            var newClass = $(this).attr('class').replace('_sel','');            
            $(this).removeClass(currentClass);
            $(this).addClass(newClass);
         }
       }
     }
   });
   $(".popupContactClose").click(function(){  
    disablePopup();  
   });  
   $(document).keypress(function(e){  
   if(e.keyCode==27 && popupStatus==1){  
    disablePopup();  
   }  
  });  
   $('.checkBox[rel!=addpic][rel!=punten][rel!=notify],.checkedBox[rel!=addpic][rel!=punten][rel!=notify]').click(function(){   
      var currentClass = $(this).attr("class");
      var rel = $(this).attr("rel");
      if(stripos(currentClass,'checkBox') !== false){
        $(this).removeClass("checkBox");      
        $(this).addClass("checkedBox");
        $('#'+rel).attr("value",1);
      }else{
        $(this).removeClass("checkedBox");
        $(this).addClass("checkBox");
        $('#'+rel).attr("value",0);
      }
   }); 
   $('.lpImage img').hoverIntent(function(){
        $(this).css("z-index",11);  
        var hook = $(this);        
        setTimeout(function(){
          $(hook).animate({ width: "121px",height: "121px"},475);
        },25);
   },function(){
     var hook = $(this);
      $(this).animate({ width: "50px",height: "50px"},300); 
      setTimeout(function(){
        $(hook).css("z-index",10);  
      },200);
   });
});
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
 function disablePopup(){  
 //disables popup only if it is enabled  
 if(popupStatus==1){  
 $(".backgroundPopup").fadeOut("slow");  
 $(".popupContact").fadeOut("slow");  
 popupStatus = 0;  
 }  
 }  
 function loadPopup(width){  
 //loads popup only if it is disabled  
 if(popupStatus==0){  
 $(".backgroundPopup").css({  
  "opacity": "0.7"
 });  
 $(".backgroundPopup").fadeIn("slow");  
 $(".popupContact").fadeIn("slow");  
  $(".popupContent").hide();
  $(".popupContent").css("width",width+"px");
  $(".popupContact").animate({ width: width },550,function(){
  $(".popupContent").fadeIn("slow");  
 });
 
 popupStatus = 1;  
 }  
 } 
  function centerPopup(width){  
 //This pageheight code is thanks to lightbox!
 	   var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		}else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}else{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
 var popupHeight = $(".popupContact").innerHeight();
 var popupWidth = width;
 var topOffset = windowHeight/6.5;
 var comparePop = topOffset + popupHeight;
 var currentFoot = $('.footWrap').innerHeight();
 var newFoot = currentFoot + comparePop;
 $('.footWrap').css("height",newFoot+"px");
 //centering  
 $(".popupContact").css({  
 "position": "absolute",  
 "top": topOffset+"px",  
 "left": windowWidth/2-popupWidth/2  
 });    
 //only need force for IE6  
 $(".backgroundPopup").css({  
  "height": pageHeight+"px"
 });  
 }
  if(document.images){
  preload_image = new Image();
  var img_url = new Array();
  img_url[0] = "http://www.nieuwsexcontact.nl/images/btn_aanmelden_hover.png";
  img_url[1] = "http://www.nieuwsexcontact.nl/images/btn_add_favorite_hover.png";
  img_url[2] = "http://www.nieuwsexcontact.nl/images/btn_afmelden_hover.png";
  img_url[3] = "http://www.nieuwsexcontact.nl/images/btn_contactpunten_hover.png";
  img_url[4] = "http://www.nieuwsexcontact.nl/images/btn_gesprek_hover.png";
  img_url[5] = "http://www.nieuwsexcontact.nl/images/btn_goto_profiel_hover.png";
  img_url[6] = "http://www.nieuwsexcontact.nl/images/btn_gratis_aanmelden_hover.png";
  img_url[7] = "http://www.nieuwsexcontact.nl/images/btn_inbox_contact_hover.png";
  img_url[8] = "http://www.nieuwsexcontact.nl/images/btn_inbox_hover.png";
  img_url[9] = "http://www.nieuwsexcontact.nl/images/btn_inloggen_hover.png";
  img_url[10] = "http://www.nieuwsexcontact.nl/images/btn_instellingen_hover.png";
  img_url[11] = "http://www.nieuwsexcontact.nl/images/btn_nav_aanmelden_hover.png";
  img_url[12] = "http://www.nieuwsexcontact.nl/images/btn_bookmark_hover.png";
  img_url[13] = "http://www.nieuwsexcontact.nl/images/btn_bookmark_logged_hover.png";
  img_url[14] = "http://www.nieuwsexcontact.nl/images/btn_nav_contact_hover.png";
  img_url[15] = "http://www.nieuwsexcontact.nl/images/btn_nav_fakerspolicy_hover.png";
  img_url[16] = "http://www.nieuwsexcontact.nl/images/btn_nav_home_hover.png";
  img_url[17] = "http://www.nieuwsexcontact.nl/images/btn_nav_overons_hover.png";
  img_url[18] = "http://www.nieuwsexcontact.nl/images/btn_nav_regels_hover.png";
  img_url[19] = "http://www.nieuwsexcontact.nl/images/btn_nav_vip_hover.png";
  img_url[20] = "http://www.nieuwsexcontact.nl/images/btn_profiel_hover.png";
  img_url[21] = "http://www.nieuwsexcontact.nl/images/btn_search_hover.png";
  img_url[22] = "http://www.nieuwsexcontact.nl/images/btn_send_credits_hover.png";
  img_url[23] = "http://www.nieuwsexcontact.nl/images/btn_send_msg_hover.png";
  img_url[24] = "http://www.nieuwsexcontact.nl/images/btn_send_notify_hover.png";
  img_url[25] = "http://www.nieuwsexcontact.nl/images/btn_show_album_hover.png";
  img_url[26] = "http://www.nieuwsexcontact.nl/images/btn_signup_now_hover.png";
  img_url[27] = "http://www.nieuwsexcontact.nl/images/btn_sms_verify_hover.png";
  img_url[28] = "http://www.nieuwsexcontact.nl/images/btn_uitloggen_hover.png";
  img_url[29] = "http://www.nieuwsexcontact.nl/images/btn_uitschrijven_hover.png";
  img_url[30] = "http://www.nieuwsexcontact.nl/images/btn_upload_hover.png";
  img_url[31] = "http://www.nieuwsexcontact.nl/images/btn_verzenden_hover.png";
  img_url[32] = "http://www.nieuwsexcontact.nl/images/btn_wachtwoord_hover.png";
  img_url[33] = "http://www.nieuwsexcontact.nl/images/btn_wijzig_profiel_hover.png";
  img_url[34] = "http://www.nieuwsexcontact.nl/images/btn_zoeken_hover.png";
  img_url[35] = "http://www.nieuwsexcontact.nl/images/un_contactpunten_hover.png";
  img_url[36] = "http://www.nieuwsexcontact.nl/images/un_favorieten_hover.png";
  img_url[37] = "http://www.nieuwsexcontact.nl/images/un_inbox_hover.png";
  img_url[38] = "http://www.nieuwsexcontact.nl/images/un_instellingen_hover.png";
  img_url[39] = "http://www.nieuwsexcontact.nl/images/un_profiel_hover.png";
  img_url[40] = "http://www.nieuwsexcontact.nl/images/un_vip_hover.png";
  img_url[41] = "http://www.nieuwsexcontact.nl/images/un_voorkeuren_hover.png";
  for(var i in img_url){
    preload_image.src = img_url[i];
  }
 }
