$(document).ready(function(){
	/* load bg image */ 
	var width = screen.width; 
	var elem = new fillBg(width);
	if (width > 1920 || width < 1024){
		elem.getBgColor();
	} else {
		elem.getBgImage();
	}

	imagePreview();
	scLoad();	
});
/* class load */
function getContent(hdl,container) {
	this.hdl = hdl;
	this.container = container;
}

getContent.prototype = {
	getItem: function (){
		var values = "xhr=1";
		var container = this.container;
		$.post( this.hdl.href, values, function(data) {
			console.log(data);
			$(container).fadeOut('normal',function(){  
				$(container).html(data).fadeIn('slow');
			});
		});
		return;
	}
}
/* class fillBg */ 
function fillBg(width) {
	this.width = width;
}

fillBg.prototype = {
	getBgImage: function () {
		if (this.width <= 1920 && this.width > 1680){
			var bg_image = "bg_1920.png";
		}	
		if (this.width <= 1860 && this.width > 1280){
			var bg_image = "bg_1680.png";
		}
		else if (this.width <= 1280 && this.width > 1024){
			var bg_image = "bg_1280.png";
		}
		else {
			var bg_image = "bg_1025.png";
		}
		$('body').css('background-image','url(' + setPath() + 'images/layout/bg/' + bg_image +')');
		$('body').css('background-attachment','fixed');
		return;
	},
	getBgColor: function () {
		$('body').css('background-color','#fff');
		return;
	}
}

this.imagePreview = function(){	
	/* CONFIG */
		xOffset = 50;
		yOffset = 20;
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='" + this.href + "' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});	

	$("a.preview").click(function(e){
		e.preventDefault();
	});
	
};
this.scLoad = function (){
	if ($('#soundcloud-followers').length) { 
     	scFollowers();	
		setTimeout(function(){simpleTips()}, 1000);
	} else {
		setTimeout(function(){scLoad()}, 1000);
	}

}

this.scFollowers = function (){

	SC.initialize({
		client_id: "MjdrjDniOLCMpIXOuvUrLQ",
	});

	SC.get("/users/ulanbator/followers?limit=15", function(lastTenUser){
		var values = "xhr=1&followers=" + encodeURIComponent(JSON.stringify(lastTenUser));
		$.post( "/soundcloud/getFollower" , values , function(data) {
			$("#soundcloud-followers").fadeOut('normal',function(){  
				$("#soundcloud-followers").html(data).fadeIn('slow');
			});
		});
	return;
	});
}

this.simpleTips = function(){	
	/* CONFIG */
		xOffset = 30;
		yOffset = 10;
	/* END CONFIG */
	$(".soundclouders a").hover(function(e){
		console.log(this);
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? this.t : "";
		$("body").append("<p class='tooltip'>"+ c +"</p>");								 
		$(".tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("slow");						
    },
	function(){
		this.title = this.t;	
		$(".tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$(".tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});	

	$("a.tooltip").click(function(e){
		e.preventDefault();
	});
	
};


    







