function add_stat(url){
	 jQuery.post(url, { type: "stats"},function(data){});    
}

jQuery(document).ready(function() {
	jQuery('#blog-entry a')
	.attr({
		target: "_blank", 
		title: "Opens in a new window"
	});
	
	window.setTimeout("adjustPhotos()",1000);
});


function adjustPhotos() {
	//alert("Now running adjustment...");
	jQuery('.photo-1 img').css('margin-top', ( (100 - jQuery('.photo-1 img').height() ) / 2 ) );
	jQuery('.photo-2 img').css('margin-top', ( (100 - jQuery('.photo-2 img').height() ) / 2 ) );
	jQuery('.photo-3 img').css('margin-top', ( (100 - jQuery('.photo-3 img').height() ) / 2 ) );
	jQuery('.photo-4 img').css('margin-top', ( (100 - jQuery('.photo-4 img').height() ) / 2 ) );
}

function rightclick(b) { 
	var message="Please be creative and don't copy and paste the samples."; 
	if (navigator.appName == 'Netscape' && (b.which == 3 || b.which == 2)){ 
		alert(message); return false;
	} else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) { 
		alert(message); return false;
	}
	return true;
}

function setProgress(percentage) {
	jQuery('#progress').animate({width: percentage+'%'}, 1500, 'linear');	
}

function setImage(iID, iStatus, iAction) {
	jQuery.post("/json/setimage", {'i':iID, 's':iStatus, 'a':iAction}, function(data) {
		if (data.status == true) {
			redirect();
		}
	}, 'json');	
}

function uploadButton(id, mKey){
	new AjaxUpload("upload_button_id_"+id, {
	  action: '/photo/upload/',
	  name: 'Filedata',
	  data: {
		"soid" : mKey+"_|_"+id
	  },
	  autoSubmit: true,
	  responseType: false,
	  onChange: function(file, extension){},
	  onSubmit: function(file, extension) {
		alert("Please allow up to 2 minutes for your picture to upload.");
	  },
	  onComplete: function(file, response) {
		alert(response);
		setTimeout("redirect()",2000);
	  },
	  onSubmit : function(file , ext){
		if (! (ext && /^(jpg|jpeg|gif)$/.test(ext))){
			// extension is not allowed
			alert('Error: Image must be of type jpg or gif.');
			// cancel upload
			return false;
		}
	  }
	});
}

function redirect(){
	document.location.reload();
}

function doPop(divId) {
	document.getElementById(divId).style.display = "inline";
}
			
function cancelPop(divId) {
	// remove lines about to control popups independently
	document.getElementById(divId).style.display = "none";	
	//document.location="http://<?=$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']?>";
}
		
function preview(img, selection) { 
	var scaleX = 100 / selection.width; 
	var scaleY = 100 / selection.height; 
	
	$('#thumbnail + div > img').css({ 
		width: Math.round(scaleX * 500) + 'px', 
		height: Math.round(scaleY * 375) + 'px',
		marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px', 
		marginTop: '-' + Math.round(scaleY * selection.y1) + 'px' 
	});
	$('#x1').val(selection.x1);
	$('#y1').val(selection.y1);
	$('#x2').val(selection.x2);
	$('#y2').val(selection.y2);
	$('#w').val(selection.width);
	$('#h').val(selection.height);
} 
