var names = new Array();
var currentCompares = new Array();
var searchedCompares = new Array();
var workSpaceWidth = 0;
var workSpaceCanHold = 0;
var lastSaver;
String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}
function inArray(arr, item) {
	var i = 0;
	for (i = 0; i < arr.length; i++) {
		if (arr[i] == item) {
			return true;
		}
	}
	return false;
}
function successfulSave() {
	
}
$(document).ready(function() {
	$(".blacker").css("opacity", 0.7);
	$(".popBlacker").css("opacity", 0.7);
	$("#peSubmit").bind("click", function (){ 
		$.post("setProfile.php",{ fname: $("#pefname").val(), lname: $("#pelname").val(), uname: $("#peuname").val(), email: $("#peemail").val(), pecountry: $("#pecountry").val(), peDay: $("#peDay").val(), peMonth: $("#peMonth").val(), peYear: $("#peYear").val() }, function (res) {
			return false;
		},'json');
		return false;
	});
	$(".sharePop").live("click",function (){
		$(".popBlacker").show();
		$(".comingSoon").slideDown('fast');
		return false;
	});
	$(".popBlacker").bind("click",function (){
		$(".comingSoon").slideUp('fast');
		$(this).hide();
		return false;
	});
	$(".popOk").bind("click",function (){
		$(".comingSoon").slideUp('fast');
		$(".popBlacker").hide();
		return false;
	});
	$(".scrollNum").live("click",function (){
		var nummer = parseInt($(this).html());
		if (nummer > (($(".scrollNum").length / 2) - workSpaceCanHold) + 1) {
			nummer = (($(".scrollNum").length / 2) - workSpaceCanHold + 1);
		}
		var howMuchToScroll = ((nummer - 1) * -350);
		$("#resultShower").animate({
				left: (howMuchToScroll + parseInt($("#dummyItem").css("width").replace("px",""))) + "px"
		  	}, {
		  		duration: 200,
		    specialEasing: {
		    	left: 'easeInOutExpo'
		    },
		    complete: function() {
		    }
		  });
		$(".scrollerIndicator").animate({
			marginLeft: ((nummer - 1) * 39) + "px"
	  	}, {
	  		duration: 100,
	    specialEasing: {
	    	left: 'easeInOutExpo'
	    },
	    complete: function() {
	    }
	  });
		$(".copyIndy").animate({
			marginLeft: ((nummer - 1) * 39) + "px"
	  	}, {
	  		duration: 100,
	    specialEasing: {
	    	left: 'easeInOutExpo'
	    },
	    complete: function() {
	    }
	  });
		return false;
	});
	
	$(".goButton").bind("click", function (){
		var artistsList = $(this).parent().find(".nameKeeper").html();
		var nae = $(this).parent().find(".nameKeeper").html().split(",");
		$(".saveComparesPage").html('<div class="bigLoading"></div>');
		$.post("getData.php", { artists: artistsList }, function (res) {
			
			compareArtists(nae, res,"saveComparesPage");
			return false;
		}, 'json');

		return false;
	});
	$(".showLogin").bind("click", function () {
		$(".notLogged").hide();
		$("#login").show();
		$(".heightControl").animate({ height: '110px' },200);
		return false;
	});
	$("#signUp").bind("click" , function (){
		if ($("#password").val() != $("#password2").val()) {
			alert("Passwords Does Not Match Please Try Again");
		} else {
			$.post("regUser.php",{ email: $("#email").val(), password: $("#password").val(), fname: $("#fname").val(), lname: $("#lname").val() },function (res) {
				if (res.code == 1) {
					$("#signBody").slideUp("fast");
					$("#signText").slideDown('fast');
				} else if (res.code == -4) {
					alert("Email Address Already In Use Please Try Our Password Reset System");
				} else {
					alert("Unknown Error Occurred Please Try Again");
				}
				return false;
			},'json');
		} 
		return false;
	});
	$(".signUp").bind("click", function () {
		window.location = "signup.php";
		return false;
	});
	var isSourceEnabled = 0;
	$(".visualSource").live("click", function (){
		isSourceEnabled = 1;
		$(".lablers").bind("mouseenter", function (e) {
			$(".wikiSourcer").css("left",(140 + $(this).offset().left)+ "px").css("top",($(this).offset().top - 140) + "px").show();
			return false;
		});
		$(".lablers").bind("mouseleave", function (e) {
			$(".wikiSourcer").hide();
			return false;
		});
		$(".events").bind("mouseenter", function (e) {
			$(".lfmSourcer").css("left",(140 + $(this).offset().left)+ "px").css("top",($(this).offset().top - 140) + "px").show();
			return false;
		});
		$(".events").bind("mouseleave", function (e) {
			$(".lfmSourcer").hide();
			return false;
		});
		$(".shortBio").bind("mouseenter", function (e) {
			$(".lfmSourcer").css("left",(140 + $(this).offset().left)+ "px").css("top",($(this).offset().top - 140) + "px").show();
			return false;
		});
		$(".shortBio").bind("mouseleave", function (e) {
			$(".lfmSourcer").hide();
			return false;
		});
		$(".genres").bind("mouseenter", function (e) {
			$(".lfmSourcer").css("left",(140 + $(this).offset().left)+ "px").css("top",($(this).offset().top - 140) + "px").show();
			return false;
		});
		$(".genres").bind("mouseleave", function (e) {
			$(".lfmSourcer").hide();
			return false;
		});
		$(".aacts").bind("mouseenter", function (e) {
			$(".lfmSourcer").css("left",(140 + $(this).offset().left)+ "px").css("top",($(this).offset().top - 140) + "px").show();
			return false;
		});
		$(".aacts").bind("mouseleave", function (e) {
			$(".lfmSourcer").hide();
			return false;
		});
		$(".yearsAct").bind("mouseenter", function (e) {
			$(".mbSourcer").css("left",(140 + $(this).offset().left)+ "px").css("top",($(this).offset().top - 170) + "px").show();
			return false;
		});
		$(".yearsAct").bind("mouseleave", function (e) {
			$(".mbSourcer").hide();
			return false;
		});
		$(".discographies").bind("mouseenter", function (e) {
			$(".mbSourcer").css("left",(140 + $(this).offset().left)+ "px").css("top",($(this).offset().top - 160) + "px").show();
			return false;
		});
		$(".discographies").bind("mouseleave", function (e) {
			$(".mbSourcer").hide();
			return false;
		});
		$(".offWeb").bind("mouseenter", function (e) {
			$(".wikiSourcer").css("left",(140 + $(this).offset().left)+ "px").css("top",($(this).offset().top - 180) + "px").show();
			return false;
		});
		$(".offWeb").bind("mouseleave", function (e) {
			$(".wikiSourcer").hide();
			return false;
		});
		$(".artistToper").bind("mouseenter", function (e) {
			$(".mbSourcer").css("left",(140 + $(this).offset().left)+ "px").css("top",($(this).offset().top - 120) + "px").show();
			return false;
		});
		$(".artistToper").bind("mouseleave", function (e) {
			$(".mbSourcer").hide();
			return false;
		});
		$("html,body").bind("click",function() {
			$(".artistToper").unbind("mouseenter").unbind("mouseleave");
			$(".offWeb").unbind("mouseenter").unbind("mouseleave");
			$(".discographies").unbind("mouseenter").unbind("mouseleave");
			$(".yearsAct").unbind("mouseenter").unbind("mouseleave");
			$(".aacts").unbind("mouseenter").unbind("mouseleave");
			$(".genres").unbind("mouseenter").unbind("mouseleave");
			$(".events").unbind("mouseenter").unbind("mouseleave");
			$(".lablers").unbind("mouseenter").unbind("mouseleave");
			$(".shortBio").unbind("mouseenter").unbind("mouseleave");
			$(".mbSourcer").hide();
			$(".wikiSourcer").hide();
			$(".lfmSourcer").hide();
			$("html,body").unbind("click");
		});
		return false;
	});
	function compareArtists(anames,artistList, pageReplacer) {
		var counter = 0;
		$(".rightBar").show();
		if (anames.length > 0) {
			$(".saver").show();
			lastSaver = anames;
			$("#saveController").show();
			var newSetting = '<div class="categoryNamer options">Search Results</div><div class="categoryNamer">Genre</div><div class="categoryNamer discer">Discography</div><div class="categoryNamer asacts">Associated Acts</div><div class="categoryNamer">Years Active</div><div class="categoryNamer">Official Website</div><div class="categoryNamer" style="height: 205px;">Labels<br /></div><div class="categoryNamer asacts">Upcoming Comcerts</div><div class="categoryNamer" style="height: 205px;">Life & Career</div><div class="categoryNamer" style="height: 250px;">Top Tracks</div><div class="wikiSourcer" style="display: none;"></div><div class="mbSourcer" style="display: none;"></div><div class="lfmSourcer" style="display: none;"></div>';
			$("#dummyItem").html(newSetting).show();
			var dummyOffset = $("#dummyItem").offset();
			$("#resultShower").css("width",(100 + (anames.length * 360))+"px").css("top",dummyOffset + "px").css("left", (parseInt($("#dummyItem").css("width").replace("px","")) + dummyOffset.left) + "px");
			$("#resultShower").show();
			$("."+pageReplacer).html("").css("height", (25 + parseInt($("#dummyItem").css("height").replace("px",""))) + "px");
			$(".scroller").show();
			$(".indiTitle").show();
			for (var k = 0; k < anames.length; k++){
				if (typeof(anames[k]) != typeof(sdfgsdfgsfdg)) {
					var artId = anames[k]; 
					var thisCount = k;
					counter++;
					$(".ajxRes").hide();
					if (typeof(artistList[anames[k]]["life-span"]) != typeof(artistList[anames[k]]["life-spdddan"])) {
						var begin = artistList[anames[k]]["life-span"].begin;
						var end = artistList[anames[k]]["life-span"].end;
						var dateAR = begin.split('-');
						var actSTR = "";
						if (dateAR.length == 1) {
							actSTR += dateAR[0];
						} else if (dateAR.length == 2) {
							actSTR +=  dateAR[0];
						} else if (dateAR.length == 3) {
							actSTR += dateAR[0];
						} else {
							actSTR += begin;
						}
						if (typeof(end) != typeof(fdfdfdfdf)) {
							dateAR = end.split("-");

							if (dateAR.length == 1) {
								actSTR += " - " + dateAR[0];
							} else if (dateAR.length == 2) {
								actSTR += " - " + dateAR[0];
							} else if (dateAR.length == 3) {
								actSTR += " - " + dateAR[0];
							} else {
								actSTR += " - " + end;
							}
						} else {
							actSTR += " - Present";
						}
					} else {
						actSTR = "-";
					}
					if (pageReplacer == "saveComparesPage") {
						$(".dummyMarker").before('<div class="indicator" id="item'+(thisCount + 1)+'"><div class="idSaver" id="i-'+artId+'" style="display: block;"></div><div class="indiLefter"></div><div class="indiCenter">'+artistList[anames[k]].name+'</div><div class="indiRighter"></div><div class="seperator" style="display: none;">&</div></div>').show();				
						var offset1 = $(".rightBar").offset();
						var offset2 = $("#i-"+artId).parent().offset();
						$("#i-"+artId).parent().css("marginTop", "5px").css("marginLeft",(offset1.left - offset2.left - 200)+"px");
						if (thisCount > 0) {
							$(".seperator").show();
							$('#item'+(1 + thisCount)).find(".seperator").hide();
						}
			    		$("#i-"+artId).parent().animate({
							marginLeft: '0px'
						  }, {
						    duration: 400,
						    specialEasing: {
						    	marginLeft: 'linear'
						    },
						    complete: function() {
						    }
						  });
					}
					$(".scroller").append('<div class="scrollNum">'+(1 + k)+'</div>');
					var str = '<div class="artistHolder" id="ho-'+anames[k]+'"><div class="artistToper" id="to-'+anames[k]+'"><div class="hideArtist"></div><div class="name">'+artistList[anames[k]].name+'</div>';
					str += '<div class="image"><img src="images/default.gif" /></div></div>';
					str += '<div class="genres"></div>';
					str += '<div class="discsHolder"><div class="loading"></div></div>';
					str += '<div class="aacts"></div>';
					str += '<div class="yearsAct">'+actSTR.replace("undefined"," Now")+'</div>';
					str += '<div class="offWeb"><div class="loading"></div></div>';
					str += '<div class="lablers"><div class="loading"></div></div>';
					str += '<div class="eventsHolder"><div class="loading"></div></div><div class="shortBio"><div class="loading"></div></div>';
					str += '<div class="listen" style="height : 250px;"></div></div>';
					$('#resultShower').append(str);
					$.post("getLastFM.php", { mbid : artId } , function (res){
						if (res.mbid == res.name) {
							$("#ho-"+res.artID).find(".aacts").html('<div class="aact"><small>Associated Acts Not Found</small></div>');
							$("#ho-"+res.artID).find(".shortBio").html("Bio Not Found");
							$("#ho-"+res.artID).find(".genres").html('<div class="genre">Genres Not Found</div>');
						} else {
							currentCompares[res.mbid] = res;
							$("#ho-"+res.mbid).find(".image").find("img").attr("src",res.images[2]["#text"]);
							var genresSTR = '';
							for (var i = 0; i < res.tags.tag.length; i++) {
								if (i < res.tags.tag.length - 1) {
									genresSTR += '<span class="genre">'+res.tags.tag[i].name.capitalize()+', </span>';
								} else {
									genresSTR += '<span class="genre">'+res.tags.tag[i].name.capitalize()+'</span>';
								}
							}
							$("#ho-"+res.mbid).find(".genres").html(genresSTR);
							var aactSTR = '';
							for (var i = 0; i < res.similar.artist.length; i++) {
								aactSTR += '<div class="aact"><a href="'+res.similar.artist[i].url+'">'+res.similar.artist[i].name+'</a></div>';
							}
							$("#ho-"+res.mbid).find(".aacts").html(aactSTR);
							$("#ho-"+res.mbid).find(".shortBio").html(res.bio.summary);
						}
						$(".shortBio").find("a").each(function (){
							$(this).attr("target","_blank");
						});

						return false;
					},'json');
					if (k % 2 == 0) {
						$("#ho-"+anames[k]).removeClass("artistHolder").addClass("artistHolder2");
					} 
					$.post("wikiTaker.php", { q : artistList[artId].name.replace("'","%27") , mbid: artId } , function (res1){
						var lblStr = "";
						if (res1.labels != null) {
							labels = res1.labels.split(",");
							for (var t = 0; t < labels.length; t++) {
								if (t == 0) {
									lblStr += labels[t].replace('/wiki/','http://www.wikipedia.com/wiki/');
								} else {
									lblStr +=  "<br /> " + labels[t].replace('/wiki/','http://www.wikipedia.com/wiki/');
								}
							}	
						}
							$("#ho-"+res1.mbid).find(".lablers").html(lblStr);
							$("#ho-"+res1.mbid).find(".offWeb").html('<a href="'+res1.website+'">'+res1.website.replace('http://','').replace('www.','').replace("/","")+'</a>');
							$(".artistHolder").find("a").attr("target","_blank");
							$(".artistHolder2").find("a").attr("target","_blank");
							$.post("getLFMTopAlbums.php", { mbid : res1.mbid } , function (resq){
								if (typeof(resq.topalbums) == typeof(blablabla)) {
									$.post("getLFMTopAlbums.php", { mbid : resq.artID } , function (resq){
										if (typeof(resq.topalbums) == typeof(blablabla)) {
											$("#ho-"+resq.artID).find(".discsHolder").html('<div class="discographies"><div class="textTitle">No Albums Found</div>');
										} else {						
											var str1 = '<div class="discographies"><div class="textTitle">'+resq.topalbums.length+' Albums</div>';
											for (var i = 0; i < resq.topalbums.length; i++) {
												str1 += '<div class="discog"><a target="_blank" href="http://www.amazon.com/dp/'+resq.topalbums[i].asin+'/">'+resq.topalbums[i].title+'</a></div>';
											}
											str1 += '</div>';
											$("#ho-"+resq.artID).find(".discsHolder").html(str1);
										}
										return false;
									},'json');	
									} else {						
									var str1 = '<div class="discographies"><div class="textTitle">'+resq.topalbums.length+' Albums</div>';
									for (var i = 0; i < resq.topalbums.length; i++) {
										str1 += '<div class="discog"><a target="_blank" href="http://www.amazon.com/dp/'+resq.topalbums[i].asin+'/">'+resq.topalbums[i].title+'</a></div>';
									}
									str1 += '</div>';
									$("#ho-"+resq.artID).find(".discsHolder").html(str1);
								}
								return false;
							},'json');
							return false;
					},'json');
					
					$.post("getEvents.php", { mbid : artId } , function (res2){
						var count = 0;
						if (typeof(res2.events) == typeof(zdsdfgsdfg)) {
							$("#ho-"+res2.artID).find(".eventsHolder").html('<div class="events"><div class="textTitle">No Events Found</div></div>');

						} else {
							if (res2.events.total == '0') {
								count = 0;
								var texter = "No Upcoming";
							} else {
								count = res2.events.event.length;
								var texter = ""+count;
							}
							var str2 = '<div class="events"><div class="textTitle">'+texter.replace("undefined","No Upcoming")+' Events</div>';
							for (var i = 0; i < count; i++) {
								str2 += '<div class="event"><a href="'+res2.events.event[i].url+'">'+res2.events.event[i].startDate+' @ '+res2.events.event[i].venue.name+'</a></div>';
							}
							str2 += '</div>';
							$("#ho-"+res2.artID).find(".eventsHolder").html(str2);
					}
						return false;
					},'json');
						$.post("getPlayables.php", { q : artistList[artId].name , aid: artId } , function (res4){
							var count = 0;
							var player = '<object width="340" height="250"><param name="movie" value="http://grooveshark.com/widget.swf"><param name="wmode" value="transparent"><param name="allowScriptAccess" value="always"><param name="flashvars" value="hostname=cowbell.grooveshark.com&amp;songIDs='+res4.strIDs+'&amp;bbg=EBF3F6&amp;bth=FFFFFF&amp;pfg=EBF3F6&amp;lfg=EBF3F6&amp;bt=FFFFFF&amp;pbg=6FB3F4&amp;pfgh=6FB3F4&amp;si=6FB3F4&amp;lbg=6FB3F4&amp;lfgh=FFFFFF&amp;sb=6FB3F4&amp;bfg=B1BABF&amp;pbgh=B1BABF&amp;lbgh=B1BABF&amp;sbh=B1BABF&amp;p=0"><embed src="http://grooveshark.com/widget.swf" type="application/x-shockwave-flash" width="340" height="250" flashvars="hostname=cowbell.grooveshark.com&amp;songIDs='+res4.strIDs+'&amp;bbg=B4D5DA&amp;bth=B4D5DA&amp;pfg=B4D5DA&amp;lfg=B4D5DA&amp;bt=813B45&amp;pbg=813B45&amp;pfgh=813B45&amp;si=813B45&amp;lbg=813B45&amp;lfgh=813B45&amp;sb=813B45&amp;bfg=B1BABF&amp;pbgh=B1BABF&amp;lbgh=B1BABF&amp;sbh=B1BABF&amp;p=0" allowscriptaccess="always" wmode="transparent"></object>';
							$("#ho-"+res4.artID).find(".listen").html(player); 
							return false;
						},'json');
				}
				 
			}
		}
		$(".rightBar").css("height",(parseInt($("#dummyItem").css("height").replace("px","")) - 15)+"px");
		var workSpaceWidth = $(".rightBar").offset().left - parseInt($("#dummyItem").css("width"));
		workSpaceCanHold = Math.floor(workSpaceWidth / 350);
		$(".copyScroller").html($(".scroller").html());
		$(".scroller").css("marginLeft",(-1 * Math.round((anames.length * 39) / 2)) + "px");
		$(".copyScroller").css("top", (parseInt($("#dummyItem").css("height").replace("px",""))  + 180) + "px").css("marginLeft",(-1 * Math.round((anames.length * 39) / 2)) + "px").show();
		$(".copyIndy").html($(".scrollerIndicator").html()).show();
		$(".copyIndy").css("top", (parseInt($("#dummyItem").css("height").replace("px",""))  + 178) + "px").css("marginLeft","3px").css("left",$(".scroller").offset().left).show();
		$(".scrollerIndicator").css("left",$(".scroller").offset().left).css("marginLeft","3px").show();
		$(".scrollerIndicatorCenter").css("width",(workSpaceCanHold * 30) + "px");
	}
	$(".startCompare").bind("click",function () {
		$.post("saveCompare.php", { jumper: 0, mbids: names } , function (res){
			if (res == 1) {
				successfulSave();
			} else {
			}
			return false;
		});
		compareArtists(names,searchedCompares,"searchPageMainContainer");
		return false;
	});
	$(".hideArtist").live("click",function () {
		var artistID = $(this).parent().attr("id").replace("to-","");
		$("#ho-"+artistID).hide();
		$(".indicator").each(function (){
			if ($(this).find(".idSaver").attr("id").replace("i-","") == artistID) {
				$(this).find(".indiCenter").css("textDecoration","line-through");
				$(this).bind("click", function (){
					$(this).unbind("click");
					var artistID = $(this).find(".idSaver").attr("id").replace("i-","");
					$(this).find(".indiCenter").css("textDecoration","none");
					$("#ho-"+artistID).show();
					return false;
				});
			}
		});
		return false;
	});
	$(".addArtist").live("click", function () {
		
		return false;
	});
	$(".takeNote").bind("click",function (){
		$(this).parents(".commentArea").hide();
		var compareid = $(this).parents(".commentArea").prev().attr("id");
		var texter = $(this).prev().val();
		$.post("addNote.php", { compareID: compareid, text: texter } , function (res){
			if (res == 1) {
				//append  note but for now
				window.location.reload(true);
			} else {
				//error handle
			}
		});
		return false;
	});
	$(".callNoteAdd").bind("click",function (){
		$(this).parents(".savedCompare").next().show().find(".addNoteShower").show();
		return false;
	});
	$(".faqControllItem").bind("click", function (){
		if (!$(this).parent().hasClass("selected")) {
			$(".menuItem").removeClass("selected");
			$(this).parent().addClass("selected");
			$(".faqA").slideUp('fast');
			
			var saverr = $("#p"+$(this).attr("id")).find(".faqA");
			setTimeout(function (){$(saverr).slideDown('fast');},150);
		}
		return false;
	});
	$(".saveEdition").live("click", function () {
		var textG = $(this).parent().parent().find(".noteEditor").val();
		var nnID = $(this).attr("id");
		if (textG.length > 0) {
			$.post('editNote.php',{nID : nnID, texter: textG },function (res) {
				window.location.reload(true);
				return false;
			},'json');
		}
		return false;
	});
	$(".editNote").live("click", function () {
		var texter = $(this).parent().parent().find(".noteController").html();
		var nnID = $(this).parent().parent().find(".noteController").attr("id");
		$(this).parent().parent().find(".noteController").html('<input type="TEXT" class="noteEditor" value="'+texter+'" />')
		$(this).parent().html('<button class="button saveEdition" id="'+nnID+'" style="float: right; margin-top: 0px;margin-right: 0px;">Save</button>');
		return false;
	});
	$(".faqQ").bind("click",function (){
		
		if ($(this).parent().find(".faqA").css("display") == "none") {
			$(".menuItem").removeClass("selected");
			$("#"+$(this).parent().attr("id").substr(1)).parent().addClass("selected");
			$(".faqA").slideUp('fast');
			var saverr = $(this).parent().find(".faqA");
			setTimeout(function (){$(saverr).slideDown('fast');},150);
		}
		return false;
	});
	$(".getLastFM").live("click", function (){
		var returnTo = $(this).parent().find('.lfm_results');
		$.post("getLastFM.php", { artistName : $(this).attr("id") } , function (res){
			$(returnTo).show();
					$(returnTo).html("").html(res.bio.summary).show();
			return false;
		});
		return false;
	});
	$(".saver").bind("click",function () {
		$(".saver").hide();
		if (lastSaver.length) {
			$.post("saveCompare.php", { mbids: lastSaver } , function (res){
				if (res == 1) {
					successfulSave();
				} else {
					//failHandle
				}
				return false;
			});
		} else {
		}
		return false;
	});
	$(".clearIt").bind("click",function () {
		if (currentCompares.length > 0) {
			window.location.reload(true);
		}
		return false;
	});
	function eachSorted(selector, func) {

	}
    $("html,body").droppable({
      drop: function() { 
    	  var artBuffer = "";
    	  var i = 0;
    	  setTimeout(function () {
    		  $(".indicator").each(function (){
        		  if (typeof($(this).find(".idSaver").attr("id")) != typeof(asdfasdfasdf)) {
        			  if ($(this).find(".indiCenter").css("textDecoration") == "none") {
            			  artBuffer +=  '<div class="artistHolder" id="'+$(this).find(".idSaver").attr("id").replace("i-","ho-")+'">' + $("#"+$(this).find(".idSaver").attr("id").replace("i-","ho-")).html() + "</div>";
        			  } else {
            			  artBuffer +=  '<div class="artistHolder" style="display: none;" id="'+$(this).find(".idSaver").attr("id").replace("i-","ho-")+'">' + $("#"+$(this).find(".idSaver").attr("id").replace("i-","ho-")).html() + "</div>";
        			  }
        		  }
        	  });
    		  $("#resultShower").html("").html(artBuffer);
    		  return false;
    	  },200);
      }
    });
    $("html,body").sortable({ axis: 'x',  items: '.indicator', tolerance: 'pointer', change: function(event, ui) {
    	var ii = 0;
    	var idSave = 0;
    	$(".seperator").each(function () {
    		var offs = $(this).parent().offset();
    		if (offs.left > ii) {
    			ii = offs.left;
    			idSave = $(this).parent().attr("id");
    		} else {    		}
    		$(this).show();
    	});
    	$("#"+idSave).find(".seperator").hide();
    }});
	var counter = 0;
	$(".searchRes").live("click",function (){
		var artId = $(this).attr("id"); 
		var thisCount = counter;
		var itemName = $(this).html();
		$("#saveController").show();
		$(".saver").hide();
		$(".ajxRes").hide();
		$(".indiTitle").show();
		if (!inArray(names,artId)) {
			counter++;
			$(".dummyMarker").before('<div class="indicator" id="item'+(thisCount + 1)+'"><div class="idSaver" id="i-'+artId+'" style="display: block;"></div><div class="indiLefter"></div><div class="indiCenter">'+itemName+'</div><div class="indiRighter"></div><div class="seperator" style="display: none;">&</div></div>').show();
			names[thisCount] = artId;
			var offset1 = $(".rightSider").offset();
			var offset2 = $("#i-"+artId).parent().offset();
			$("#i-"+artId).parent().css("marginTop", "100px").css("marginLeft",(offset1.left - offset2.left - 200)+"px");
			if (thisCount > 0) {
				$(".seperator").show();
				$('#item'+(1 + thisCount)).find(".seperator").hide();
			}
			$("#searchTitle").html("And...");
			$("#searchQ").val("");
			setTimeout(function (){
				$("#i-"+artId).parent().animate({
					marginTop : '5px'
				  }, {
				    duration: 400,
				    specialEasing: {
				    	marginTop: 'linear'
				    },
				    complete: function() {
				    	setTimeout(function (){ 
				    		$("#i-"+artId).parent().animate({
								marginLeft: '0px'
							  }, {
							    duration: 400,
							    specialEasing: {
							    	marginLeft: 'linear'
							    },
							    complete: function() {
							    }
							  });
				    	},150);
				    }
				  });
			},150);
		}
		return false;
	});
	$(".searchRes").live("mouseenter",function (){
		$(this).css("backgroundColor","#e3eef4")
		return false;
	});
	$(".searchRes").live("mouseleave",function (){
		$(this).css("backgroundColor","#FFF")
		return false;
	});
	var halterFlag = 0;
	var timeOutSaver = '';
	$("#searchQ").bind("keyup", function () {
			if ($("#searchQ").val().length > 3) {
				$(".ajxRes").html('<div class="loading"></div>');
				$(".ajxRes").show();
				$(".loading").show();
				if (halterFlag == 0) {
					halterFlag = 1;
					timeOutSaver = setTimeout(function () {
						$.post("searchMB.php", { artistName : $("#searchQ").val() } , function (res){
							for (var i = 0; i < res.length; i++) {
								if (res[i].id.length > 2) {
									searchedCompares[res[i].id] = res[i];
									$(".ajxRes").append('<div class="searchRes" id="'+res[i].id+'">'+res[i].name+'</div>');
								}
							}
							$(".ajxRes").show();
							$(".loading").hide();
							halterFlag = 0;
							return false;
						},'json');
						},200);
				} else {
					clearTimeout(timeOutSaver);
					timeOutSaver = setTimeout(function () {
						$.post("searchMB.php", { artistName : $("#searchQ").val() } , function (res){
							for (var i = 0; i < res.length; i++) {
								if (res[i].id.length > 2) {
									searchedCompares[res[i].id] = res[i];
									$(".ajxRes").append('<div class="searchRes" id="'+res[i].id+'">'+res[i].name+'</div>');
								}
							}
							$(".ajxRes").show();
							$(".loading").hide();
							halterFlag = 0;
							return false;
						},'json');
						},200);
				}
			}
	});
});
window.onresize = function () {
	if ($(".rightBar").length > 0) {
		workSpaceWidth = $(".rightBar").offset().left - parseInt($("#dummyItem").css("width"));
		workSpaceCanHold = Math.floor(workSpaceWidth / 350);
		$(".copyIndy").css("marginLeft","3px").css("left",$(".scroller").offset().left);
		$(".scrollerIndicator").css("left",$(".scroller").offset().left).css("marginLeft","3px");
		$(".scrollerIndicatorCenter").css("width",(workSpaceCanHold * 30) + "px");
	}
}
