var swf_upload_control;	
var opacity = 50;
var img_src;
var orig_h;
var orig_w;
$(document).ready(function() {
	$(".color_picker").click(function(){
		mypickcolor("#input_" + $(this).attr("id"), "#" + $(this).attr("id"), this);
	});
	$("#cmCloseButton").click(function(){
		$("#ColourMod").hide();
		$("#contenedor_skin").css("background-color","#"+ $("#input_background-color").val());
		return false;
	});
	
	$("#btnSubmit").click(function() {
		var f_re=/^.+\.(gif|jpg|png|jpeg)$/i;
		var res=f_re.test($("#resume_file").val());
		if(!res) {
			alert('Bad file. Just GIF, JPG or PNG.');
			return false;
		}
		$("#loader").attr({"src":"plugins/reproductor-skin/images/loading.gif", "height":"20"});					   
		$.ajaxUpload({
			uploadform:document.f,
			url:'plugins/reproductor-skin/upload.php',
			secureuri:false,
			dataType:'json',
			success:function(msg) {
				$("#loader").attr({"src":"plugins/reproductor-skin/images/blank.gif", "height":"2"});	
				if(msg.success == 0)
					return false;
					
				$("#manejador_de_imagen").slideDown();
				$("#image").attr("src", "plugins/reproductor-skin/img/"+msg.img);
				$(".slider_handle").css("left", "90px");
				img_src = msg.img;
				orig_w = msg.w;
				orig_h = msg.h;
			},
			error:function(data, status, e) {
				alert(e);
			}
		});
	});
	
	$('#opacity_slider').Slider({
		accept: '.slider_handle',
		onChange: function(px,py,x,y) {
			opacity = Math.round((px/100)*100-11) - 237;
			if ($("#imgfinal").attr("src") != "plugins/reproductor-skin/images/blank.gif") {
				$("#imgfinal").css({"filter":"alpha(opacity="+opacity+")","-moz-opacity":(opacity/100),"opacity":(opacity/100)});
				show_code();
			}
		},
		values:[[100,0]]
	});
	
	$('#image').Resizable({
		maxWidth: 800,
		maxHeight: 600,
		handlers: {
			se: '#resizeSE',
			e: '#resizeE',
			ne: '#resizeNE',
			n: '#resizeN',
			nw: '#resizeNW',
			w: '#resizeW',
			sw: '#resizeSW',
			s: '#resizeS'
		}
	});
	$('#image').Draggable({
		opacity: 0.7,
		zIndex: 10
	});
});

function drag_ratio(option) {
	$('#image').ResizableDestroy();
	
	var ratio_op = 0;
	if ($("#image").width() > $("#image").height())
		ratio_op = $("#image").height() / $("#image").width();
	else
		ratio_op = $("#image").width() / $("#image").height();
	
	if (option == 1) {	
		$('#image').Resizable({
			maxWidth: 800,
			maxHeight: 600,
			ratio:  ratio_op,
			handlers: {
				se: '#resizeSE',
				e: '#resizeE',
				ne: '#resizeNE',
				n: '#resizeN',
				nw: '#resizeNW',
				w: '#resizeW',
				sw: '#resizeSW',
				s: '#resizeS'
			}
		});	
	}
	else {
		$('#image').Resizable({
			maxWidth: 800,
			maxHeight: 600,
			handlers: {
				se: '#resizeSE',
				e: '#resizeE',
				ne: '#resizeNE',
				n: '#resizeN',
				nw: '#resizeNW',
				w: '#resizeW',
				sw: '#resizeSW',
				s: '#resizeS'
			}
		});	
	}
}

function pageDimensions() {
	var x,y;
	if (self.innerHeight) {
		x = self.innerWidth;
		y = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	} else if (document.body) {
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	return [x,y];
}
function scrollOffset() {
	var x,y;
	if (self.pageYOffset) {
		x = self.pageXOffset;
		y = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	} else if (document.body) {
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	return [x, y];
}