$(function() {
	var path=''; /*  the complete path from the root to the smooth_poll  */
    $('.pollWrapper').each(function(){
    var ref = $(this).attr('id');
    var loader = $('#l-'+ref);
    var pollcontainer = $('#d-'+ref);
    
    $('.ping').live('click',function(){
    	$('#cboxClose').click();
    	var sid=$(this).attr('id').split('s-')[1];
    	submitForm(ref,sid);
    });
    
    	loader.fadeIn();
	    $.post(path+'poll.php',{auth:'y',r:ref},function(d){
	        pollcontainer.each(function(){
	        	$(this).html(d)
	        	animateResults(ref);
	    	}); 
	         
		    $('#viewresult-'+ref).live('click', function() {
		        viewResult(ref);
		        return false;
	   		 });
	   		 
	    	$('#vote-'+ref).live('click',function() {
	            vote(ref);
	            return false;
	        });
	       styleIt(ref);
	        $('#'+ref).live('mouseout',function(){$('#thxMsg-'+ref).hide(800);});
	        var coo=Cookie.get('votedOn');
	        if(coo && coo!="undefined"){
		        var voteData=$.trim(coo.split('<a')[0]);
	        }else{
		        var voteData="Alle doelen";
	        }
		        var elems,label;
		        $('.pollform').each(function(){
		        	elems=$(this).find('label');
		        	elems.each(function(){
		        		label=$.trim($(this).text().split('<a')[0]);
		        		if(label==voteData){
		        			$(this).click();
				        	$(this).prev().prev().click();
		        		}
		        	})
		        })  
	        loader.fadeOut();
	    });
		
	    $('#nimda-'+ref).live('click',function(){
	        return false;
	    });
	    
		$('#nimda-'+ref).live('dblclick',function(){
	        loader.fadeIn();
	        $.post(path+'poll.php', { cmd: 'letMeIn',auth: 'y',r:ref},function(d) {
	            pollcontainer.fadeOut(1000,function() 
	            {
	                $(this).html(d).fadeIn();
	                loader.fadeOut();
	            });
	        });
	        return false;
	    });
	    
	     $('#go-'+ref).live('click',function() {
	        loader.fadeIn();
	        var resu = $('#resu-'+ref).val();
	        var ssap = $('#ssap-'+ref).val();
	        $.post(path+'poll.php', { auth: 'y',u: resu, p: ssap,r:ref },function(d) {
	            pollcontainer.fadeOut(1000,function() {
	                $(this).html(d).fadeIn();
	                styleIt(ref);
	                loader.fadeOut();
	            });
	        })
	    });
	    
	    $('#logout-'+ref).live('click',function() {
	        loader.fadeIn();
	        $.post(path+'poll.php', {cmd: 'getMeOut', auth: 'y',r:ref},function(d) {
	            pollcontainer.fadeOut(1000,function() 
	            {
	                $(this).html(d).fadeIn();
	                styleIt(ref);
	                 loader.fadeOut();
	            });
	        });
	    });
	    
		$('#lang-'+ref).live('click',function(){
			var elem=$(this).offset();
			$(this).next().css({'top':elem.top+22,'left':elem.left});
			$(this).next().toggle(200);
			return false;
		});
		
		$('#dd-'+ref+' .langz').live('click',function(){	
			var language=$(this).text();
			if(!confirm('You are going to change the poll language to'+language+', Are you sure ?'))
			{$('#dd-'+ref).toggle(400);return false;}
			pollcontainer.fadeOut(500);
			loader.fadeIn();
			$.post(path+'poll.php',{cmd:'changeLang',r:ref,l:language,auth:'y'},function(d){
				pollcontainer.html(d).fadeIn(function(){
		                 loader.fadeOut();
		            }
            	);
			})
			return false;
		})
		
	     $('#menu-'+ref).live('click',function() {
	        $('#'+ref+' .adBtn').show(500);
	        $('#'+ref+' .open').each(function() {
	            $(this).toggle(500);
	            $(this).toggleClass('open');
	        })
	        return false;
	    });
	    
	    
	    $('#newPoll-'+ref).live('click',function() {
	        $('#np-'+ref).toggle(500);
	        $('#np-'+ref).toggleClass('open');
	        $('#'+ref+' .adBtn').hide(500);
	    });
	    
	    
	 	$('#addPollOpt-'+ref).live('click',function() {
	        var optNum = ($('#'+ref+' .newPoll').find('.pollOptions').length) + 1;
	        var newOpt = $('<tr><td></td><td><input type="text" class="txtInp pollOptions" name="pollOpt[]" />' + optNum + '</td></tr>');
	        var addOpt = $('#addPollOpt-'+ref);
	        newOpt.insertBefore(addOpt.parent().parent());
	        return false;
	    });
	    
	    
	     $('#rmvPollOpt-'+ref).live('click',function() {
	        var index = $('#'+ref+' .newPoll').find('.pollOptions').length;
	        if (index > 2) {
	            $(this).parent().parent().prev().prev().remove();
	        } else {
	            alert('At least two options should be kept');
	        };
	        return false;
	    });
	    
	    $('#publish-'+ref).live('click',function(){
	        var empty = 0;
	        $('#'+ref+' #pollTable input:not(input[name=pollVote])').each(function() {
	            if ($(this).val() == '') {
	                empty = 1;
	            };
	        });
	        
	        if (empty) {
	            alert('Empty field(s) have been detected please fill them in , and try again !');
	            return false;
	        }
	        
	        var activate = $('#defShow-'+ref).attr('checked');
	        var show='n';
	        if(activate){
	        	show='y';
	        }else{show='n';}
	        var save = $(this).attr('name');
	        var qId = '';
	        if (save == 'save') {
	            qId = $(this).attr('class');
	        }
	        var opts = Array();
	        var votes = Array();
	        var multiple=$('#'+ref+' .newPoll').find('select[name=multiple]').val();
	        var question = $('#'+ref+' .newPoll').find('input[name=pollQues]').val();
	        if (!save) {
	            var tableData = $('#'+ref+' #pollTable').html();
	        }
	        $('#'+ref+' .newPoll').find('.pollOptions').each(function(i) {
	            opts[i] = $(this).val();
	        });
	        $('#'+ref+' .newPoll').find('input[name=pollVote]').each(function(i){
	        	if($.trim($(this).val())=='Original'){
	        		votes[i] = $.trim($(this).val());	
	        	}else{
	        		votes[i] = parseInt($.trim($(this).val()));		
		        	if( isNaN(votes[i])){
		            	empty=1;
		        	}
	        	}
	        });
	        if(empty){
	        	alert('votes value should be a number !');
	        	return false;
	        }
	         loader.fadeIn();
	        $.post(path+'poll.php', {cmd: 'publish', q: question, o: opts,v:votes,m:multiple, s: save,quesId: qId,r:ref,a:show,auth:'y'},function(d) {
	            $('#'+ref+' #pollTable').fadeOut(500,function(){
	                $('#'+ref+' #pollTable').html(d).fadeIn(500,function() {
	                    if (!save) {
	                        setTimeout(function() {$('#pollTable').html(tableData);},3000)
	                    };
	                    loader.fadeOut();
	                });
	            })
	        });
	        return false;
	    });
	    
	    $('#editPoll-'+ref).live('click',function() {
	        $('#ep-'+ref).toggle(500);
	        $('#ep-'+ref).toggleClass('open');
	        $('#'+ref+' .adBtn').hide(500);
	    });
	    
	    
	    
	    $('#'+ref+' .qList').live('click',function() {
	        var id = $(this).attr('id');
	        if (id != null && id != undefined && id != '') {
	            var ques = $(this).text();
	            loader.fadeIn();
	            $.post(path+'poll.php', {cmd: 'editPoll',q: ques,qId: id, r:ref,auth: 'y'},function(d) {
	                $('#'+ref+' #d-'+ref).fadeOut(500,function() {
	                    $('#'+ref+' #d-'+ref).html(d).fadeIn(function() {
	                        $('#'+ref+' .newPoll').toggle(500);
	                        loader.fadeOut();
	                    });
	                })
	            });
	        }
	        return false;
	    });
	    
	    
	    $('#delPoll-'+ref).live('click',function() {
	        $('#dp-'+ref).toggle(500);
	        $('#dp-'+ref).toggleClass('open');
	        $('#'+ref+' .adBtn').hide(500);
	    });
	    
	    
	    $('#'+ref+' .delList').live('click',function() {
        if (!confirm('You are going to delete this poll,Are you sure ?')) {
            return false;
        }
        var id = $(this).attr('id');
        if (id != null && id != undefined && id != '') {
            var ques = $(this).text();
            loader.fadeIn();
            $.post(path+'poll.php', {cmd: 'delPoll',q: ques,qId: id,r:ref,auth: 'y'},function(d) {
                $('#'+ref+' #d-'+ref).fadeOut(500,function() {
                    $('#'+ref+' #d-'+ref).html(d).fadeIn(function() {
                        loader.fadeOut();
                    });
                })
            });
        }
        return false;
    });
	    
        $('#nimda_set-'+ref).live('click',function() {
	        $('#as-'+ref).toggle(500);
	        $('#as-'+ref).toggleClass('open');
	        $('#'+ref+' .adBtn').hide(500);
	    });
	    
	     $('#changeData-'+ref).live('click', function(){
	        var resu = $('#resu-'+ref).val();
	        var ssap = $('#ssap-'+ref).val();
	        var prev = $('input[name=prev_mode]:checked').val();
	        var exp = $('#exp-'+ref).val();
	        if(exp==''){
	        	alert('Set how many minutes should the user wait till (s)he can vote again !');
	        	return false;
	        }
	        if(prev==undefined){
	        	alert('Please choose a preview mode !');
	        	return false;
	        }
	        loader.fadeIn();
	        $.post(path+'poll.php', { cmd: 'changeData', u: resu, p: ssap,pr:prev,x:exp,r:ref,auth: 'y'}, function(d) {
	            $('#'+ref+' #d-'+ref).fadeOut(500,function() {
	                $('#'+ref+' #d-'+ref).html(d).fadeIn(function() {
	                    loader.fadeOut();
	                });
	            })
	        });
	        return false;
	    });
	    
	    $('#design-'+ref).live('click',function() {
	        $('#ds-'+ref).toggle(500);
	        $('#ds-'+ref).toggleClass('open');
	        $('#'+ref+' .adBtn').hide(500);
	    });
	    
	    
	    $('#colorSelector-'+ref).live('click',function() {
	        $(this).ColorPicker({
	            color: '#e6e6e6',
	            onShow: function(colpkr) {
	                $(colpkr).fadeIn(500);
	                return false;
	            },
	            onHide: function(colpkr) {
	                $(colpkr).fadeOut(500);
	                return false;
	            },
	            onChange: function(hsb, hex, rgb) {
	                $('#colorSelector-'+ref+' div').css('backgroundColor', '#' + hex);
	                $('#'+ref).css('backgroundColor', '#' + hex);
	            }
	        });
	    });
	    
	    
	    $('#colorSelector2-'+ref).live('click',function() {
	        $(this).ColorPicker({
	            color: '#e6e6e6',
	            onShow: function(colpkr) {
	                $(colpkr).fadeIn(500);
	                return false;
	            },
	            onHide: function(colpkr) {
	                $(colpkr).fadeOut(500);
	                return false;
	            },
	            onChange: function(hsb, hex, rgb) {
	                $('#colorSelector2-'+ref+' div').css('backgroundColor', '#' + hex);
	                $('#'+ref).css('color', '#' + hex);
	            }
	        });
	    });
	    
	    
	    $('#colorSelector3-'+ref).live('click',function() {
	        $(this).ColorPicker({
	            color: '#e6e6e6',
	            onShow: function(colpkr) {
	                $(colpkr).fadeIn(500);
	                return false;
	            },
	            onHide: function(colpkr) {
	                $(colpkr).fadeOut(500);
	                return false;
	            },
	            onChange: function(hsb, hex, rgb) {
	                $('#colorSelector3-'+ref+' div').css('backgroundColor', '#' + hex);
	            }
	        });
	    });
	    
	    
	    
	     $('#reset-'+ref).live('click',function() {
	        if (!confirm('You are going to style the poll with the default design,are you sure ?')) {
	            return false;
	        }
	        loader.fadeIn();
	        $.post(path+'poll.php', { cmd: 'resetStyle',r:ref,auth: 'y'}, function(d) {
	            $('#'+ref+' #d-'+ref).fadeOut(500,function() {
	                $(this).html(d).fadeIn(function() {
	                    loader.fadeOut();
	                });
	            })
	        });
	        return false;
	    });
    
	    $('#width-'+ref).live('change',function(){
	     	var width = $('#width-'+ref).val();
	     	$('#'+ref).css('width',width);
	 	});
    
	    $('#saveStyle-'+ref).live('click',function(){
	        var val = $('#'+ref+' input[name=buttonStyle]:checked').attr('value');
	        var bg = $('#colorSelector-'+ref+' div').attr('style');
	        var fg = $('#colorSelector2-'+ref+' div').attr('style');
	        var vg = $('#colorSelector3-'+ref+' div').attr('style');
	        var width = $('#width-'+ref).val();
	        if (val == undefined || val == '' || val == null) {
	            alert('Choose a radio button style !');
	        } else {
	            loader.fadeIn();
	            $.post(path+'poll.php', {cmd: 'changeStyle',radStyle: val,b:bg,f:fg,v:vg,w:width,r:ref,auth:'y'},
	            function(d) {alert(d);
	                $('#'+ref+' #d-'+ref).fadeOut(500,function() {
	                    $(this).html(d).fadeIn(function() {
	                        loader.fadeOut();
	                    });
	                })
	            });
	        }
	        return false;
	    });
	    
	    $('#stats-'+ref).live('click',function() {
	        $('#st-'+ref).toggle(500);
	        $('#st-'+ref).toggleClass('open');
	        $('#'+ref+' .adBtn').hide(500);
	    });
    
	    $('#'+ref+' .statList').live('click',function(){
	        var typo = $(this).attr('id');
	        if (typo != null && typo != undefined && typo != ''){
	            loader.fadeIn();
	            $.post(path+'poll.php', {cmd:'stats',type: typo,r:ref,auth:'y' }, function(d){
	                $('#d-'+ref).fadeOut(500, function() 
	                {
	                    $(this).html(d).fadeIn(function() {
	                        loader.fadeOut();
	                    });
	                })
	            });
	        }
	        return false;
	    })
	    
		jQuery.download = function(url, data){
			//url and data options required
			if( url && data ){ 
	        	loader.fadeIn();
				//data can be string of parameters or array/object
				data = typeof data == 'string' ? data : jQuery.param(data);
				//split params into form inputs
				var inputs = '';
				jQuery.each(data.split('&'), function(){ 
					var pair = this.split('=');
					inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />'; 
				});
				//send request
				jQuery('<form action="'+ url +'" method="post">'+inputs+'</form>').appendTo('body').submit().remove();
				loader.fadeOut();
				
			};
		};

    
	    $('#csv-'+ref).live('click',
	    function() {
	        $('#dcsv-'+ref).toggle(500);
	        $('#dcsv-'+ref).toggleClass('open');
	        $('#'+ref+' .adBtn').hide(500);
	    });
    
	    $('.csvList').live('click',function() {
	        var id = $(this).attr('id');
	        if (id != null && id != undefined && id != ''){
	        	$.download(path+'includes/export.php','t=csv&q='+id );
	        }
	        return false;
	    });
    
	    $('#xml-'+ref).live('click',function() {
	        $('#dxml-'+ref).toggle(500);
	        $('#dxml-'+ref).toggleClass('open');
	        $('#'+ref+' .adBtn').hide(500);
	    });
	    
        $('.xmlList').live('click',function() {
	        var id = $(this).attr('id');
	        if (id != null && id != undefined && id != '')
	        {
	        	$.download(path+'includes/export.php','t=xml&q='+id );
	        }
	        return false;
	    });
    
	    $('#pdf-'+ref).live('click',function() {
	        $('#dpdf-'+ref).toggle(500);
	        $('#dpdf-'+ref).toggleClass('open');
	        $('#'+ref+' .adBtn').hide(500);
	    });
	    
	   /* $('.pong').live('click',function(e){
			$('.left').animate({'left' : - 10},{duration:400, queue:false});
			var sid=$(this).attr('data-sid'); // keep these 2 lines if you want..
			submitForm(ref,sid);   // ...the poll to vote when user click on shop	
	    });*/
    });

$('#googleIt').submit(function(e){
	e.preventDefault();
	checkForm(this);
})

function checkForm(form)  {
	var inp=$('#searchField');
	var inpVal=inp.val();
	if ((inpVal)==""){
	   alert("U kunt hier zoekwoorden ingeven waarmee u via Draagbij op Google kunt zoeken. De winkels waar u kunt bijdragen worden apart aan u gepresenteerd! Maak van deze pagina uw startpagina!");
	   inp.focus();
	   return false;
	   }
	   if(!$('#zoekresultaten').length || Cookie.oldInp!=inpVal){
		 $.post("includes/searchdatabase.php",{q:inpVal},function(d){
		 	d=d.split('@');
		 	if(d[0]=='g'){
		 		window.location="http://www.google.com/search?q="+d[1];
		 	}else{
		 		document.getElementById("txtHint").innerHTML=d;
		 		$("#zoekresultaten img[title]").tooltip({ position: "center left", delay:0});
		 	}
		 	Cookie.oldInp=inpVal;
		 	$(".ajax").colorbox({width:"380px",height:"320px",transition: "none",speed: 0,opacity: 0.8});
		 });
	   }else{
	   	Cookie.oldInp=inpVal;
	   	 var link=$('#zoekresultaten>p:not[.zoekkoptekst]').find('a').attr('href');
	   		window.location=link;
	   }
	return false;
}

function submitForm(ref,sid) {
	var loader = $('#l-'+ref);
    var pollcontainer = $('#d-'+ref);
    var pollForm=$('#'+ref+' .pollform');
    var selected_val = pollForm.find('input[name=option]:checked').val();
    $.post(path+'pageViews.php',{pc:'increment','id':sid});
    if (selected_val != undefined){
    	Cookie.set('votedOn',selected_val,Cookie.returnExpiration(365));
        loader.fadeIn();
        $.post(path+'poll.php',{ v: pollForm.serialize(),r:ref,auth: 'y'},function(d) {
            $('#formcontainer-'+ref).fadeOut(100,function() {
                $(this).html(d);
                $(this).fadeIn(500);
                animateResults(ref);
                $('#'+ref).live('mouseout',function(){$('#thxMsg-'+ref).hide(800);});
                loader.fadeOut();
            });
        });
    } else if($('input[name=option]').length!=0){
    		var qid=pollForm.find('input[name=question_id]').val();
    		$.post(path+'poll.php',{ v:'question_id='+qid+'&option=Alle+doelen',r:ref,auth: 'y'},function(d) {
    			$('#formcontainer-'+ref).fadeOut(100,function() {
	                $(this).html(d);
	                $(this).fadeIn(500);
	                animateResults(ref);
	                $('#'+ref).live('mouseout',function(){$('#thxMsg-'+ref).hide(800);});
	                loader.fadeOut();
            	});
    		});
        }
    return false;
};

function viewResult(ref) {
		var loader =$('#l-'+ref);
	    var pollcontainer =$('#d-'+ref);
	    loader.fadeIn();
	    $.post(path+'poll.php', {result:'1',auth: 'y',r:ref},function(d) {
	        pollcontainer.fadeOut(1000,function() {
	            $(this).html(d).fadeIn();
	            animateResults(ref);
	            loader.fadeOut();
	        });
	    });
}
function vote(ref) {
	var loader =$('#l-'+ref);
    var pollcontainer =$('#d-'+ref);
    loader.fadeIn();
    $.post(path+'poll.php', {auth: 'y',r:ref},function(d) {
        pollcontainer.html(d);
        styleIt(ref);
        loader.fadeOut();
    });
}

var Cookie={
		caution:false,
		oldInp:'',
		set:function(name, value, expires, path, domain, secure){
			var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "")
			if (!Cookie.caution || (name + "=" + escape(value)).length <= 4000)
			document.cookie = curCookie
			else
			if (confirm("Cookie exceeds 4KB and will be cut!"))
			document.cookie = curCookie
		},
		get:function(name){
		var prefix = name + "="
		var cookieStartIndex = document.cookie.indexOf(prefix)
		if (cookieStartIndex == -1)
		return null
		var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex +
		prefix.length)
		if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length
		return unescape(document.cookie.substring(cookieStartIndex +
		prefix.length, cookieEndIndex))
		},
		returnExpiration:function(day){
			var now = new Date();
			now.setTime(now.getTime() + day * 24 * 60 * 60 * 1000);
			return now;
		}
	}

});

function animateResults(ref) {
    $('#'+ref+' .bar').each(function() {
        var bar_width = $(this).css('width');
        $(this).css('width', '0').animate({
            width: bar_width
        },
        1000);
    });
}

function styleIt(ref) {
	if ($.browser.msie==1 && parseInt($.browser.version, 10) < 8) {
		return false;
	}else{replace(ref);}

    var oldId='';
    $('#'+ref+' .radRep').each(function() {
        $(this).click(function() {
            var id = $(this).attr('data-repId');
            if(oldId!=id){
            	oldId=id;
	            $('#'+ref+' .radRep:not(this)').removeClass('checked');
	            var check = $('#' + id).attr('checked');
	            if (!check) {
	                $('#' + id).attr('checked', 'checked');
	            } else {
	                $('#' + id).removeAttr('checked');
	            };
	            $(this).toggleClass('checked');
            }
        });
         	
    });

    $('#'+ref+' .pollform p label').each(function() {
        $(this).click(function() {
            $(this).prev().prev().click();
            var t=$(this).text();
            var str=$('#statusbox>span').html(" "+t);
        })
    })
    $('#'+ref+' .pollform p div').each(function() {
        $(this).click(function() {
            var t=$(this).next().next().text();
            var str=$('#statusbox>span').html(" "+t);
        })
    })
    
    $('#'+ref+' .chkRep').each(function() {
    	var label=$(this).next().next();
    	var realInp=$(this).next();
    	var fakeInp=$(this);
        fakeInp.click(function() {
        	var id = $(this).attr('data-repId');
        	var check = $('#' + id).attr('checked');
            if (!check) {
                $('#' + id).attr('checked', 'checked');
                $(this).toggleClass('checked');
            } else {
                $('#' + id).removeAttr('checked');
                $(this).toggleClass('checked');
            };
        });
        realInp.bind('change',function(){
			$(this).prev().toggleClass('checked');
		})
		if($.browser.msie){
			label.click(function(){
				fakeInp.click();
			});
		}
    });
}

function replace(ref) {
    $('#'+ref+' input[name=option]').each(function() {
        $(this).css('display', 'none');
        var classo='';
        var type=$(this).attr('type');
        switch(type){
        	case'radio':
        		classo='radRep';
        	break;
        	case'checkbox':
        		classo='chkRep';
        	break;
        }
        var id = $(this).attr('id');
        $('<div data-repId=' + id + ' class="'+classo+'"></div>').insertBefore(this);
    })
}

$(function(){
	var leftDiv=$('.left .the-content');
	var lefticonDiv=$('.left .the-icon,.left .exit,#statusbox,.kiesgoeddoel');	
	var leftWidth = leftDiv.width();
		
	lefticonDiv.bind('click', function() {
		var stat= Cookie.get('divStat');
		var rs;
		if(stat){
				rs=stat.split(',')[1];
			}else{
				rs='o';
			}
		if(parseInt(leftDiv.parent().css('left')) < -270){
			Cookie.set('divStat','o,'+rs,Cookie.returnExpiration(365*5));
			leftDiv.parent().animate({'left' : -20},{duration:400, queue:false});	
		} else {
			Cookie.set('divStat','c,'+rs,Cookie.returnExpiration(365*5));		
			leftDiv.parent().animate({'left' : -275},{duration:400, queue:false});	
		}	
	})	
		
	var rightDiv=$('.right .the-content');
	var righticonDiv=$('.right .the-icon,.right .exit,.kieseenwinkel');	
	var rightWidth = rightDiv.width();
		
	righticonDiv.bind('click', function() {
		var stat= Cookie.get('divStat');
		var ls;
		if(stat){
				ls=stat.split(',')[0];
			}else{
				ls='o';
			}
		if(parseInt(rightDiv.parent().css('right')) < -5){
			Cookie.set('divStat',ls+',o',Cookie.returnExpiration(365*5));
			rightDiv.parent().animate({'right' : -5},{duration:400, queue:false});	
		} else {
			Cookie.set('divStat',ls+',c',Cookie.returnExpiration(365*5));		
			rightDiv.parent().animate({'right' : -205},{duration:400, queue:false});
		}
	})	
	
	
/*	var leftDiv2=$('.left2 .the-content');
	var leftWidth2 = leftDiv2.width();
	setTimeout(function(){leftDiv2.parent().animate({'left' : -leftWidth2- 40},{duration:700, queue:false});},1000)
	leftDiv2.bind('mouseenter', function() {
		if(parseInt(leftDiv2.parent().css('left')) < -250){
			leftDiv2.parent().animate({'left' : -40},{duration:400, queue:false});	
		}
	})	
	leftDiv2.bind('mouseleave', function() {
			leftDiv2.parent().animate({'left' : -leftWidth2 - 40},{duration:400, queue:false});
	})
*/		
	var topDiv=$('.top .the-content');
	var topiconDiv=$('.top .the-icon,.top .the-icon2,.top .exit');
	var topHeight = topDiv.height();
	
	topiconDiv.bind('click', function() {
		if(parseInt(topDiv.parent().css('top')) < -20){
			topDiv.parent().animate({'top' : -20},{duration:400, queue:false});	
		} else {
			topDiv.parent().animate({'top' : -220},{duration:400, queue:false});	
		}	
	})	
	
	var topDiv2=$('.top2 .the-content');
	var topiconDiv2=$('.top2 .the-icon,.top2 .exit');
	var topHeight2 = topDiv2.height();
	
	topiconDiv2.bind('click', function() {
		if(parseInt(topDiv2.parent().css('top')) < -20){
			topDiv2.parent().animate({'top' : -20},{duration:400, queue:false});	
		} else {			
			topDiv2.parent().animate({'top' : -250},{duration:400, queue:false});	
		}	
	})	
	
	var bottomDiv=$('.bottom .the-content');
	var bottomDiv2=$('.bottom .the-icon');
	var bottomHeight = bottomDiv.height();
	setTimeout(function(){bottomDiv.parent().animate({'bottom' : -bottomHeight- 30},{duration:700, queue:false});},1000)
	
	bottomDiv.bind('mouseleave', function() {
			bottomDiv.parent().animate({'bottom' : -bottomHeight - 30},{duration:400, queue:false});
	})
	bottomDiv2.bind('click', function() {
		if(parseInt(bottomDiv.parent().css('bottom')) < -30){
			bottomDiv.parent().animate({'bottom' : -30},{duration:400, queue:false});	
		}
	})	
	
	var Cookie={
		caution:false,
		set:function(name, value, expires, path, domain, secure){
			var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "")
			if (!Cookie.caution || (name + "=" + escape(value)).length <= 4000)
			document.cookie = curCookie
			else
			if (confirm("Cookie exceeds 4KB and will be cut!"))
			document.cookie = curCookie
		},
		get:function(name){
		var prefix = name + "="
		var cookieStartIndex = document.cookie.indexOf(prefix)
		if (cookieStartIndex == -1)
		return null
		var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex +
		prefix.length)
		if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length
		return unescape(document.cookie.substring(cookieStartIndex +
		prefix.length, cookieEndIndex))
		},
		returnExpiration:function(day){
			var now = new Date();
			now.setTime(now.getTime() + day * 24 * 60 * 60 * 1000);
			return now;
		}
	}
	var stat= Cookie.get('divStat');
	if(stat){
		var ds=stat.split(',');
		if(ds[0]=='o'){			
			leftDiv.parent().animate({'left' : -20},{duration:0, queue:false});	
		}
		if(ds[1]=='o'){
			
			rightDiv.parent().animate({'right' : -5},{duration:0, queue:false});	
		}
	} else {
		// Geen Cookie: dus uitklappen!	
		leftDiv.parent().animate({'left' : -20},{duration:0, queue:false});	
		rightDiv.parent().animate({'right' : -5},{duration:0, queue:false});	
	}	
})
