/*
**	Bookmark stuff
*/
var bmurl = 'http://www.naaktcam.com/';
var bmttl = 'Naaktcam.com - Live webcam seks';
function addFav() {
	if (addFav2()==false) {
		alert('Close this message and press CTRL-D\r\nto add this site to your favorites.');
	}
}
function addFav2() {
  if((typeof window.sidebar == 'object')&&(typeof window.sidebar.addPanel == 'function')){
		window.sidebar.addPanel(bmttl, bmurl,'');
	} else if (typeof window.external == 'object'){
		window.external.AddFavorite(bmurl, bmttl);
  } else if (window.opera && document.createElement){
    var a=document.createElement('A');
    if(!a){return false;}
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',bmurl);
    a.setAttribute('title',bmttl);
    a.click();
  } else {return false;}
  return true;
}


$(document).ready(function(){
/*
**	Search box focus/blur (TODO)
*/
  var default_search_value = $("#search").attr('value');
  $("#search").focus(function(event){
    if ($(this).attr('value')==default_search_value) {
      $(this).attr('value','');
    } else {
      // select everything
    }    
  });
  $("#search").blur(function(event){
    if ($(this).attr('value')=='') {
      $(this).attr('value',default_search_value);
    } else {
      // select everything
    }    
  });

/*
**	Payment window
*/
  $("a.payment").click(function(event){
    event.preventDefault();
    window.open(this.href,'naaktcam_payment','status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1, scrollbars=1');
    return false;
  });

/*
**	Flag checkbox
*/
  $("label[for*=lang]").click(function(event){
    event.preventDefault();
    var oChk = $("#"+$(this).attr('for'));
    var oImg = $(this).children();
    var sIso = $(this).attr('for').substr(4,2).toLowerCase();  
    if (oChk.attr('checked')==true) {
      oChk.attr('checked', false);
      oImg.attr('src', '/gfx/flags/'+sIso+'o.gif');
    } else {
      oChk.attr('checked', true);
      oImg.attr('src', '/gfx/flags/'+sIso+'.gif');
    }
    return false;
  });

/*
**	Add favourite webcam
*/
  $("a.fav_add").click(function(event){
    event.preventDefault();
    var sId = $(this).attr('id').substr(8);
    $.get('/ajax_favourites.php?action=add&webcam='+sId, function(data){
			if (data=='') {
				$("#favourite_"+sId).fadeOut('slow');
				$("#favourite_"+sId).fadeIn('slow');
			} else {
				$('#favourites').prepend(data);
				$('#nofavourites').hide('fast');
				$("#favourite_"+sId).show('slow');
				$("#favourite_"+sId+" fav_del").click(function(event){
					event.preventDefault();
					var sId = $(this).attr('id').substr(10);
					$('#favourite_'+sId).hide('slow');
					$.get('/ajax_favourites.php?action=del&webcam='+sId);
				});
			}
    });
  });

/*
**	Remove favourite webcam
*/
  $("a.fav_del").click(function(event){
    event.preventDefault();
    var sId = $(this).attr('id').substr(8);
		$('#favourite_'+sId).hide('slow');
    $.get('/ajax_favourites.php?action=del&webcam='+sId);
  });



});