

var o = {
    score:0,
    givenScore:0,
    ready:function()
    {
        o.score = $('.stars .over').length;
        //console.log(o.score);
        $('.stars div').mouseover(o.starOver);
        $('.stars div').mouseout(o.starOut);
        $('.stars div').click(o.starClicked);
        $('.opmerkingen').click(o.showOpmerkingen);
    },
    
    frameReady:function()
    {
        //console.log('test');
    },
    
    starOver:function()
    {
        var all = $('.stars').children('div');
        all.removeAttr('class');
        var index = all.index(this);
        for(var c = 0; c<=index; c++){
            all.eq(c).addClass('over');
        }
    },
    
    starOut:function()
    {
        
        var all = $('.stars').children('div');
        for(var c = 0; c<5; c++){
            all.eq(c).attr('class', c>=o.score?'':'over');
        }
    },
    
    starClicked:function()
    {
        givenScore = $('.stars').children('div').index(this)+1;
        
        var url = 'rate.php?score='+givenScore;
        if($('.stars').hasClass('shop'))
            url+='&shop=1';
        TINY.box.show({url:url, boxid:'frameless', animate:true, openjs:o.opened})
    },
    
    opened:function()
    {
        $('#submitReactieForm').click(o.sendForm);
    },
    
    sendForm:function()
    {
        var send = {};
        send.email = $('.reactieForm input[name=email]').val();
        send.score = $('.reactieForm input[name=score]').val();
        send.reactie = $('.reactieForm textarea[name=uitleg]').val();
        send.ref_id = $('.stars').attr('id');
        if($('.stars').hasClass('shop'))
            send.shop = 1;
        if(!send.email.match(/^.+\@.+\..+$/)){
            alert('Ongeldig email adres');
            return false;
        }
        if(!send.reactie){
            alert('Geen reactie ingevuld');
            return false;
        }
        $.post('rate.php', send);
        TINY.box.fill('<div class="reactieForm"><h1>Bedankt</h1><br/>Uw reactie is succesvol geplaatst.</div>');
    },
    
    showOpmerkingen:function()
    {
        var url = 'rate.php?comments='+$('.stars').attr('id');
        if($('.stars').hasClass('shop'))
            url+='&shop=1';
        TINY.box.show({url:url, boxid:'frameless', animate:true, openjs:o.opened});
        
        return false;
    }
    
};

$(document).ready(o.ready);

function print(){
    printContent('directions');
}

function printContent(id){
    str = document.getElementById(id).innerHTML;
    newwin=window.open('','printwin'+Math.random(),'left=100,top=100,width=400,height=400');
    newwin.document.write(str);
    newwin.document.getElementById('print').style.display = "none";
    newwin.window.print();
}
