jQuery(document).ready(function(){
	if(videoid && ! isNaN(videoid) && videoid > 0){
		setWallpaper(videoid);
	}
});

function setWallpaper(video_id){
	var date = new Date();
	date.setHours(23, 59, 59);

	jQuery.get('/getwallpaper/' + video_id , function(data){
		if(data){
			var data = jQuery.evalJSON(data);

			if(data.image_url){
				function tapetamuti(){
					jQuery('.video').addClass('with-wallpaper');

					jQuery('.with-wallpaper').css('position', 'relative');
					jQuery('.with-wallpaper').css('width', '980px');
					jQuery('.with-wallpaper').css('height', '614px');
					jQuery('.with-wallpaper').css('background-image', 'url(' + data.image_url + ')');
					jQuery('.with-wallpaper').css('background-repeat', 'no-repeat');
					jQuery('.with-wallpaper').css('background-position', '10px 0');
					jQuery('.with-wallpaper').css('padding-top', '156px');
					jQuery('.with-wallpaper').click(function(){
						if(data.CT){
							window.open(data.CT);
						}
					});
					jQuery('.playerarea').click( function(){return false;} );
//					if(data.AV){
						jQuery.get("/site/execute/test_xman.php?var=hellokitty");
//					}
				}

				if(jQuery.cookie('wallpaper')){
					var kukitartalom = jQuery.evalJSON(jQuery.cookie('wallpaper'));

					if(kukitartalom[data.id] !== false && !isNaN(kukitartalom[data.id])){
						if(kukitartalom[data.id] > 0){
							tapetamuti();

							kukitartalom[data.id] -= 1;
						}
					}else{
						tapetamuti();

						kukitartalom[data.id] = data.cookie_limit - 1;
					}
				}else{
					tapetamuti();

					var kukitartalom = {};
					kukitartalom[data.id] = data.cookie_limit - 1;
				}

				jQuery.cookie('wallpaper', jQuery.toJSON(kukitartalom), {expires: date});
			}
		}
	});
}
