var articleId = imageId = 0;

$(document).ready(function(){

     
        if(articleId != 0) {
                showFrameId(articleId);
        }
	
        if(imageId != 0) {
                showDetail(imageId);
        }

	//$(document).pngFix(); 
	
});


    

        function elmaci(){
            
            //$('#elma').scrollTo('500px', 600);
            $("#elma").scrollTo('1000px', 600 );
            
        }
        
        
function position(ele) { 
			$( "#"+ele ).position({
				of: $( document ),
				my: "center center",
				at: "center center",
				offset: 0
				
			});
		}
		
		
function rate(imageId, rate){
var rateList="";
    $.ajax({
                        type: 'GET',
                        url: 'http://www.noelverin.com/index.php?op=rate',
                        data: 'imageId='+imageId+'&rate='+rate,

                        success: function(data) {

			for(i=1; i< 6; i++){
				if(data >= i) {
					rateList = rateList + "<div class=rated></div>";
				}
				else { 
					rateList = rateList + "<div class=unrated></div>";
	}
				
			}

			$("#rate").html(rateList);

                        }
                     });

}



function showFrameBox(frameUrl){

                         
	$('#frameBoxUrl').attr("src","http://www.noelverin.com/index.php?op="+frameUrl);	

	_mettreFrame();
	



} 

function _mettreFrame(){

	var ww = $(window).width();
	var wh = $(window).height();		
	var lf = Math.floor((ww - 850) / 2 );
	var tp = Math.floor((wh - 520) / 2 );

	$('#frameBox').css({left:lf});
	$('#frameBox').css({top:tp});
	cl = Math.floor(lf-15);
	ct = Math.floor(tp-15);

	$('#frameBoxClose').css({left:cl});
	$('#frameBoxClose').css({top:ct});
	
	nl = Math.floor(lf + 875);
	pl = Math.floor(lf-50);
	pt = Math.floor(wh / 2);

	$('#prev').css({left:pl});
	$('#prev').css({top:pt});

	$('#next').css({left:nl});
	$('#next').css({top:pt});

	$('#frameBoxShadow').width($(window).width());
	$('#frameBoxShadow').height($(window).height());
	
    
    $('#frameBoxShadow').show();
	$('#frameBoxClose').show();	$('#frameBox').show();
	$('#question').hide();
	$('#prev').show();
	$('#next').show();

}


function showFrameId(frameId){

	                 
	$('#frameBoxUrl').attr("src","http://www.noelverin.com/index.php?op=va&id="+frameId);	

	_mettreFrame();
	

} 


function hideFrameBox(){

	$('#frameBoxShadow').hide();
	$('#frameBox').hide();
	$('#frameBoxClose').hide();
	$('#prev').hide();
	$('#next').hide();

}


function essayerThis(imageId){
	
	$(top.location).attr("href","http://www.noelverin.com/essayer/image-"+imageId+"/");	
	

}


function acheterThis(imageId){
	
	$(location).attr("href","http://www.noelverin.com/acheter/image-"+imageId);	

}


function prev(){

	pEl = $('ul.pictures').children(currentChild).prev().attr('id');

	if(pEl){ showDetail(pEl); }
}

function next(){

	nEl = $('ul.pictures').children(currentChild).next().attr('id');

	if(nEl){ showDetail(nEl); } 

}


function acheter(){ 
                      variables = $('#acheter_contact').serialize();

                       $.ajax({
                        type: 'POST',
                        url: 'http://www.noelverin.com/index.php?op=acheterContact',
                        data: variables,

                        success: function(data) {
				//alert(data);
				$('#envoyer').show();
				$('#form').hide();


                        }
                     });


}

