var txtLocals = {
  subscription : "<br />Nieuw op Sexcamera.nl<br /> Ontvang direct een berichtje van <b>%s</b>, als ze online is.<br /> <br />-  Je ontvangt alleen een bericht wanneer <b>%s</b> online is. <br /> - Je kan je op elk gewenst moment weer afmelden <br /> - deze service is en blijft gratis ! <br /><br />"
}

$(function(){
        
        $('#subscribeform').submit(function(){
            var form = $(this);
            $.post(form.attr('action'),form.serialize(), function(data){
                if (typeof data == 'object') {
                    if (data.error == undefined) {
                        form.empty().html('<p>'+data.result+'</p>');
                    } else {
                        form.find('.error').html(data.error);
                    }
                } else {
                    alert('Request failed');
                }
            }, 'json');
            return false;
        });

        $('#loginform').submit(function(){
            var form = $(this);
            var u = form.find('input[name="username"]');
            var p = form.find('input[name="password"]');
            if ($.trim(u.val()) == '') {
              alert("Username is empty");
              return false;
            }
            if ($.trim(p.val()) == '') {
              alert("Password is empty");
              return false;
            }
            $.post('login.php',form.serialize(),function(data){
                 if (data.error == undefined){
                   location.href = data.success;
                 } else {
                   alert(data.error);
                 }
            },'json');
            return false;
        }).find('li').mousedown(function(){
            $(this).find('input').focus();
        }).find('input').focusin(function(){
            $(this).siblings('span').hide();
        }).focusout(function(){
            var input = $(this);
            if ($.trim(input.val()) == '') {
                input.siblings('span').show();
            }
        }).end().find('span').mousedown(function(e){
           e.preventDefault();
        });

        $('.tabs a').click(function(){
            var tab = $(this);
            var id = tab.attr('id') != undefined ? tab.attr('id') : false;
            if (id) {
              tab.addClass('active').siblings('a').each(function(i, obj){
                  var siblTab = $(this);
                  var siblTabId = siblTab.attr('id') != undefined ? siblTab.attr('id') : false;
                  if (siblTabId){
                      siblTab.removeClass('active');
                      $('#'+siblTabId+'-block').hide();
                  }
              });
              $('#'+id+'-block').show();
            }
            return false;
        });

        // play clips
        var tm = null;
        $('.clip').hover(
            function(){
              var img = $(this).find('img');
              tm = setInterval(function(){
                 var n = /_(.{2})\.[^.]+$/g.exec(img.attr('src'));
                 if (typeof n == 'object') {
                    n = parseInt(n[1],10);
                    n = n >= 10 ? 1 : ++n;
                    n = n == 10 ? '10' : ('0' + n);
                    img.attr('src', img.attr('src').replace(/_(.{2})\.([^.]+)$/, '_'+n+'.$2'));
                 }
                },600);
            },
            function(){
                !tm || clearInterval(tm);
            }
        );

        $('.qselect').hover(
            function(){
                $(this).find('.qoptions').show();
            },
            function(){
                $(this).find('.qoptions').hide();
            }
        );
        
        $('.prof-img').colorbox({'rel':'prof-img','fixed':'true'});
        
        new Dialog({'name':'subscribe'}, function(){
            var form = $(this);
            $.post('subscription.php', form.serialize(), function(data){
                if (data.error == undefined) {
                    var parent = form.hide().parent();
                    var close = parent.parent().find('.close').hide();
                    var result = $('<p/>',{'css':{'line-height':'20px','font-size':'14px','color':'#ccc'}}).html(data.result).appendTo(parent);
                    $('<button/>',{'css':{'width':'80px','padding':'8px 0','display':'block','margin':'10px auto'}})
                        .text('Close')
                        .appendTo(result)
                        .click(function(){
                            result.remove();
                            close.click();
                            form.show();
                        });
                    _gaq.push(['_trackPageview', '/subscription.php']);
                } else {
                    alert(data.error);
                }
            }, 'json');
            //form.parents('.dialog').find('.close').click();
            return false;
        }).launcher('.subscribe', function(dlg){
            var link = $(this);
            var formcontent = dlg.find('.formcontent').empty();
                   $('<input/>',{'type':'hidden','name':'camid','value':link.attr('id').split('-')[1]}).appendTo(formcontent);
            $('<p/>',{'css':{'font-size':'18px','text-align':'center'}}).text(link.attr('title')).appendTo(formcontent);
            var snapshot = link.parent().parents('li').find('.snapshot');
            if (snapshot.length){
                $('<p/>',{'css':{'text-align':'center'}}).html('<img width="160" src="'+snapshot.attr('src')+'" />').appendTo(formcontent);
            }
            $('<p/>',{'css':{'padding-left':'4%','font-size':'12px','line-height':'18px'}}).html(txtLocals.subscription.replace(/%s/g, link.attr('href').replace('#',''))).appendTo(formcontent);
            $('<label/>',{'css':{'font-size':'12px','margin-right':'10px','margin-left':'50px'}}).text('Email').appendTo(formcontent);
            $('<input/>',{'type':'text', 'name':'email', 'css':{'width':'184px'}}).appendTo(formcontent);
        });
        
        // live preview for 5 sec
        $('a.cam-item').live('mouseover',
            function(){
                var camItem = $(this);
                if(camItem.data('hover') == undefined || !camItem.data('hover'))
                {
                    camItem.data('hover',1);
                    var camId = camItem.attr('id').substr(7);
                    var videoPreview = camItem.find('.video-preview');
                    var img = camItem.find('img');
                    var blank = camItem.find('.blank');
                    $('<div/>',{'id':'pl-'+camId}).appendTo(videoPreview);
                    blank.css({'width':img.width(),'height':img.height()});
                    startCamPlayer('pl-'+camId, camId, img.width(), img.height());
                }
                return false;
            }
        ).live('mouseleave',function(){
                var camItem = $(this);
                camItem.data('hover',0);
                var camId = camItem.attr('id').substr(7);
                camItem.find('.video-preview').html('');
                return false;
        });
        
        $(window).resize(function(){
            var wnd = $(this);
            $('.dialog').css('left', function(){    
               return ((wnd.width()-$(this).width())/2) + 'px';
            }).css('top', function(){
                return ((wnd.height()-$(this).height())/2) + 'px';
            });
        }).keydown(function(e){
            if (e.which == 27) {
                $('.close').click();
            }
        }).resize();
});


function resetSearchPanel()
{
    var form = $('.searchform');
    form.find('input[type="checkbox"]').removeAttr('checked').end()
        .find('input[type="text"]').val('').end()
        .find('input[name="age1"]').val('18').end()
        .find('input[name="age2"]').val('99').end()
        .find('select').find('option').removeAttr('selected').eq(0).attr('selected','selected');
    
}

function resetCategoryPanel()
{
    $('.qselect .qoptions li a').removeClass('active');
}

function categoryChanged(cat, el) {
    el = el ? $(el) : $(this);
    var parent = el.parent().parent();
    setCookie('page',1);
   // xajax_filter('category', cat);
    parent.hide().find('li a').removeClass('active');
    el.addClass('active'); 
    resetSearchPanel();
    return true;
}


function getOnlineCams(options, excludeIds)
{
    $('ul.models').load('data.php',{'req':'onlineCams', 'options':options, 'excludeIds':excludeIds});
}

<!--
function refreshCams() {
    xajax_refreshcams();
    setTimeout('refreshcams()', 60000);
}

/**
*   Cam preview
**/
function startCamPlayer( selector, camid, width, height )
{
    // Config
    var player  = "http://cams.dnxlive.com/swf/live_preview_public.swf";
    var gateway = "http://cams.dnxlive.com/stream/gateway.php";
    var defaultWidth  = 160;
    var defaultHeight = 120;

    // Init
    width  = typeof(width)=='undefined' ? defaultWidth : width;
    height = typeof(height)=='undefined' ? defaultHeight : height;

    swfobject.embedSWF(
        player,
        selector,
        width,
        height,
        '9.0.0',
        'expressInstall.swf',
        {
            // Flashvars
            account: camid,
           // gateway: gateway,
            teaser_enter : "Enter Now"
        },
        {
            //Params
            wmode: "transparent",
            allowScriptAccess: "sameDomain"
        },
        {}
    );
}

function maxWindow(url, name, width, height) {
  features = 'scrollbars=1,resizable=1,menubar=0,toolbar=0,location=0,status=0,top=0,left=0,screenX=0,screenY=0,';

  if (window.screen) {
    aw = screen.availWidth;
    ah = screen.availHeight;
    features = features+'width='+(aw-20)+',height='+(ah-38);
  }
  else {
    features = features+'width='+width+',height='+height;
  }
  window.open(url, name, features);
}
  
function popupWindow(url, w, h) {
  var middleLeft = 400 - w;
  var middleTop = 10;
            
  if (window.screen) {
    middleLeft = (screen.availWidth / 2) - (w / 2);
  }
                      
  window.open(url, '', 'scrollbars=0,resizable=0,menubar=0,toolbar=0,location=0,status=0,top='+middleTop+',left='+middleLeft+',width='+w+',height='+h);
}
  
function openNewWindow(URLtoOpen, windowName, windowFeatures) { 
  newWindow=window.open(URLtoOpen, windowName, windowFeatures);
}

function addBookmark(title,url) {
    if (window.sidebar) { 
        window.sidebar.addPanel(title, url,""); 
    } else if( document.all ) {
        window.external.AddFavorite( url, title);
    } else if( window.opera && window.print ) {
    return true;
    }
}

var _cookies;
function _initCookies() {
  _cookies = {};
  var ca = document.cookie.split(';');
  var re = /^[\s]*([^\s]+?)$/i;
  for(var i = 0; i < ca.length; i++) {
    var c = ca[i].split("=");
    if(c.length == 2) {
     _cookies[c[0].match(re)[1]] = unescape(c[1].match(re) ? c[1].match(re)[1] : '');
    }
  }
}

function getCookie(name) {
  if(!_cookies) _initCookies();
  return _cookies[name];
}

function setCookie(name, value, days) {
  if(!_cookies) _initCookies();
  _cookies[name] = value;
  var expires = "";
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    expires = "; expires="+date.toGMTString();
  }
  path = path ? path : '/';
  var domain = location.host.match(/[^.]+\.[^.]+$/);
  document.cookie = name+"="+escape(value)+expires+"; path=" + path + (domain ? '; domain=.'+domain : ';');
}




// CLASSES

var Dialog = function(options, callback){
    this.settings = {
        name        : '',
        submit      : ' Submit ',
        formHtml    : '',
        css         : {
                 'width':'400px',
                 'left': '30%',
                 'top': '25%',
                 'background':'#111',
                 'z-index':100,
                 'border':'1px solid #ccc',
                 'color':'#ccc'
        },
        cssClose   : {
                 'width':'20px',
                 'height':'20px',
                 'line-height':'20px',
                 'top':'-8px',
                 'right':'-8px',
                 'background':'#222',
                 'color':'#ccc',
                 'border':'1px solid #ccc'
        },
        cssWrap   : {
                 'background':'#222'
        },
        cssSubmit : {
                  'width':'80px',
                  'padding': '6px 0',
                  'display':'block',
                  'margin' : '10px auto'
        }
    }
    this.dlg =  null;

    this.settings = $.extend(true, this.settings, options);
    this.construct(callback);
}

Dialog.prototype = {
    construct : function(callback){
         this.dlg  = $('<div/>',{
                'id':this.settings.name+'-dlg',
                'class':'dialog',
                'css':$.extend(true, this.settings.css, {'display':'none','position':'fixed','padding':0})
         }).appendTo($('body'));

         var box  = $('<div/>',{
                'class':this.settings.name+'box',
                'css':$.extend(true, this.settings.cssWrap, {'margin':'15px','padding':'10px'})
         }).appendTo(this.dlg);

         $('<div/>',{
             'class':'close',
             'css':$.extend(true, this.settings.cssClose, {'position':'absolute','text-align':'center','cursor':'pointer','title':'close'})
         }).text('X').appendTo(this.dlg).click(function(){
             $(this).parent().hide();
         });

         var form = $('<form/>').appendTo(box).submit(function(){
            if (typeof callback == 'function') {
                return callback.call(this);
            } else {
                alert('Callback is not defined');
                return false;
            }
         }).html('<div class="formcontent">'+this.settings.formHtml+'</div>');

         $('<input/>',{'type':'submit','name':'submit','value':' '+this.settings.submit+' ', 'css':this.settings.cssSubmit}).appendTo(form);
    },
    form : function(html) {
      this.dlg.find('.formcontent').empty().html(html);
      return this;
    },
    launcher  : function(selector, callback){
        var self = this;
        $(selector).live('click',function(){
            if (typeof callback == 'function') {
                callback.call(this, self.dlg);
            }
            self.show();
            return false;
        });
        return this;
    },
    show : function(){
        $(window).resize();
        this.dlg.show().find('.close').show().end().find('form').show().siblings().remove();
        return this;
    },
    hide : function(){
        this.dlg.hide();
        return this;
    },
    destroy : function(){
        this.dlg.remove();
        delete this.settings;
        delete this.dlg;
    }
}


//-->


