$(document).ready(function(){
	$.nyroModalSettings({
		
		endFillContent: function(elts, content){
			$(window).unbind('resize.nyroModal');
		},
		showBackground :function(elts, settings, callback) {
			elts.bg.css({opacity:0.75});
			callback();
		},
		hideBackground : function(elts, settings, callback) {
			elts.bg.hide();
			callback();
		},
		showContent: function(elts, settings, callback){
			 elts.contentWrapper
                        .css({
                               width: settings.width+'px',
                            marginLeft: (settings.marginLeft)+'px',
                            height: settings.height+'px',
                           marginTop: (settings.marginTop)+'px'
                  })
               .show()
              callback();
		},
		hideContent : function(elts, settings, callback) {
			elts.contentWrapper.hide();
			callback();
        },
		hideLoading : function(elts, settings, callback) {
			elts.loading.hide();
			callback();
        }
	});

	function rated_over(obj){
		var parent = obj.parent();
		if ( !obj.data('rate') ){
			obj.data('rate', parent.children('.s1').length);
		}

		ratedSet(parent, parent.children().index(obj) + 1);
	}

	function rated_out(obj){
		ratedSet(obj.parent(), obj.data('rate'));
	}

	function ratedSet(obj, rate){
		obj.children().each(function(i){
			if ( i < rate ){
				$(this).addClass('s1');
			}else{
				$(this).removeClass('s1');
			}
		});
	}

	function animatePictoMin(obj) {
		//obj.animate({'opacity': 1 }, 500, 'linear').animate({'opacity': 0.2 }, 'slow').animate({'opacity': 1 }, 'slow', 'linear', function(){ animatePictoMin(obj); } );
	}

	function callKeypress(obj, e){
		if (e.which == 13){
			obj.submit();
		}
	}

	$('a').not('.submit,.page_disclaimer .flag,#jsAccueil,#jsCategories,.jsCat,#jsExit,#jsWebcamLive,#jsTvPorn,#bloc_drapeaux a,.page_categorie .cat_big a').click(function(){
		callPopIn();

		return false;
	});

	$('.cat_min .rated span,.cat_big .rated span,.n,.cat_big .rated span,.list_models .rated span').hover(
		function(){
			rated_over($(this));
		},
		function(){
			rated_out($(this));
		}
	);

	$('.cat_min .rated,.cat_big .rated,.cat_big .fake_controler,.list_models .rated').click(function(){
		callPopIn();

		return false;
	});

	$('.cat_min .picto,.cat_big .picto,.page_pornTv .picto').each(function(){
		animatePictoMin($(this));
	});

	$('.cat_min:gt(0) .img,.cat_big:gt(0) .video,.page_pornTv .blkVideoTv .aVideo,.page_pornTv .blkVignet .img,.page_pornTv .blkListTv .img,.page_pornTv .list_web_tv .img,.page_webcam_live .list_models .link_img').each(function(){
		$(this).hover(
			function(){
				$(this).addClass('opaque');
			},function(){
				$(this).removeClass('opaque');
			}
		);
	});	
});
