var $weapons = {
	featureHTML: false,
	flagit: function(){
		var u="/weapondesigner/flag?id="+flagthis;
		if (flagthis) {
			$j.ajax({
				url:u
				});
			}
			tb_remove();
		$j(".flag-"+flagthis).fadeOut("slow");
		},



	sendToFriend:function (region) {
		var email = $j('#send-email-input').val();
		if (email) {
			var u = "/"+region+"/weapondesigner/ajaxSendToFriend?shareUrl="+ escape(document.location) +"&graphicId="+hash.id+"&toEmail=" + email;
			$j.ajax({
				url:u,
				success: function(data){
						tb_remove();
						}
				});
			}
		}
		,
	weapons : {features:[], gallery:[], state:{}} ,
	init: function() {
	
		tb_init('a.thickbox:not(.weaponsdesigner #n1 a.thickbox)');
		var starX = 12;
		var theMonths = {0:"JAN",1: "FEB",2: "MAR", 3:"APR", 4:"MAY" , 5:"JUN", 6:"JUL", 7:"AUG", 8:"SEP" , 9:"OCT", 10:"NOV", 11:"DEC"};
		//var weapons = {features:[], gallery:[], state:{}} ;
		viewerItem.index = viewerItem.home = false;
		
		hash = {	
				tab : 'features',  
				sortOrder : 'created_date', 
				periodType :  'alltime',
				page : '1',
				searchTextType : 'personaName',
				searchField : '',
				id: false
				};			
			
		if(document.location.hash != ""){
			var q = document.location.hash;
			q = q.replace('#','');
			for(var i=0; i < q.split("&").length; i++) {
				if(	hash[q.split("&")[i].split("=")[0]] || 
					q.split("&")[i].split("=")[0]=="id" || 
					hash[q.split("&")[i].split("=")[0]]==""
					)hash[q.split("&")[i].split("=")[0]] = q.split("&")[i].split("=")[1];
				}
			}	
	
		$j("#wd-search-tools .chooser.sortby h4").text((hash.sortOrder != "searchResults")?$j("#"+hash["sortOrder"]).text():$j("#created_date").text()) ;
		$j("#wd-search-tools .chooser.alltime h4").text($j("#"+hash["periodType"]).text());
		$j("#wd-search-tools .chooser.searchby h4").text($j("#"+hash["searchTextType"]).text());
		$j("input#searchstring").val(hash["searchField"]);
		




/*=============== 3. SET HASH ===========*/	




		function setHash(val, attr){
			hash[attr] = val;
			document.location.hash = jQuery.param(hash);	
			}
			
		var features = new Array;
		
		if(hash.id) {
			$j.ajax({ 
				url: "/weapondesigner/ajaxWeaponDetail?graphicId="+hash.id+"&incViewCount=true", 
				dataType : "json" , 
				success: function(json){
					
					if(json.id !== ""){
						viewerItem = json;
						viewerItem.home ="state";
						viewerItem.index =0;
						 $weapons.weapons["state"] = {0 : json} ;
						 loadViewer("state",0);
						getGallery();
						if(hash.tab == "features" ) getTab(hash.tab);
						}
					else{
						hash.id =false;
						getGallery();
						getTab("features");
						}
					
					}
				});
			}
		else{
			getGallery();
			getTab("features");
			}
		

	





/*=============== 2. GET GALLERY    ===========*/	
		
		
		
		
		var gallery =  new Array;
		
function getGallery(){

			$j("#wd-result-items").html("");
			$weapons.weapons.gallery =[];
			$j.getJSON("/weapondesigner/ajaxGalleryPage?"+ jQuery.param(hash), function(json){
				$j.each(json.items, function(i,item){
					var currimg =(item.id == hash.id) ? "class=\"current\" " : "";
					$j("#wd-result-items").append("<li id=\"gall-"+item.id+"\" class=\"wd-result-item\"></li>");
					$j("li#gall-"+item.id).append("<span class=\"itemindex\">"+item.id+"</span>"+
						"<ul>"+
						"	<li  class=\"viewclick\" ><img src=\""+ item.version[2].url +"\" "+currimg+" width=\"192\" height=\"120\" /></li>"+
						"	<li  class=\"viewclick\" ><h5>"+ item.title +"</h5></li>"+
						"	<li>"+txtUploadedBy+" "+ item.personaName +"</li>"+
						"	<li>"+txtAvgScore+" <span class=\""+item.id+"\">"+Math.round(item.rating/2*10)/10 +"</span></li>"+
						"	<li>"+txtBasedOn+" <span class=\"rcount"+item.id+"\">"+ item.ratingCount +"</span> Votes</li>"+
						"	<li>"+txtTotalViews+" <span class=\"views"+item.id+" \">"+item.viewCount+"</span></li>"+
						"	<li class=\"wd-stars\"><span class=\""+item.id+"\">"+ item.rating/2 +"</span></li>"+
						"</ul>"
						);

				/*===============MAKE ITEM ELEMENTS CLICKABLE===========*/	
				
					$j("#gall-"+item.id+" li.viewclick").click(function(){
						$j("img.current").removeClass("current");
						$j("#gall-"+item.id+" img , #feat-"+item.id+" img").addClass("current");
						setHash("details", "tab");
				
						loadViewer("gallery", item.id);
						});
						$j("#gall-"+item.id+" .viewclick" ).mouseover(function(){
							$j(this).parent().addClass("boxfocus");
							})
						.mouseout(function(){
							$j(this).parent().removeClass("boxfocus");
							});					
					$weapons.weapons.gallery[item.id] = item;
					});	
					
				/*=====================ADD PAGGING=================*/	
				

				$j("#wd-result-items").css("height",(gallery.length<4)? 242:482);
				$j("#wd-pagination").html("");
				if(json.pageInfo.numPages>1){
					var n = 8; 
					if(json.pageInfo.pageNum > 1) $j("#wd-pagination").html("<li class=\"wd-page-go wd-arr wd-ten-back\" >&lt;&lt;</li><li class=\"wd-page-go wd-arr wd-page-back\">&lt;</li>");
					else $j("#wd-pagination").html("<li class=\"wd-dead wd-arr\">&lt;&lt;</li><li class=\"wd-dead wd-arr\">&lt;</li>");
								
					
					if(json.pageInfo.numPages<=8){
						for(i=1; i<=json.pageInfo.numPages; i++){
							if(i!=json.pageInfo.pageNum)	$j("#wd-pagination").append("<li class=\"wd-page wd-page-go\">"+i+"</li>");
							else $j("#wd-pagination").append("<li class=\"wd-page wd-dead\">"+i+"</li>");
							}
						}
					else {
						
						var spage = ((json.pageInfo.pageNum -(n/2)) < 1 )? 1 : (json.pageInfo.pageNum - (n/2));
						var epage =  ((json.pageInfo.pageNum + (n/2))> json.pageInfo.numPages)? json.pageInfo.numPages : json.pageInfo.pageNum + (n/2);
						epage +=(json.pageInfo.pageNum < n/2 )? (n/2) - json.pageInfo.pageNum + 1:0;
						spage -=(json.pageInfo.numPages - json.pageInfo.pageNum < n/2 )?  n/2+json.pageInfo.pageNum - json.pageInfo.numPages:0;
						if(json.pageInfo.numPages>n+1 && json.pageInfo.pageNum> n/2+1 ) $j("#wd-pagination").append("<li class=\"wd-page wd-page-go\">1</li><li>...</li>");
						
						for(i=spage; i<=epage; i++){
							if(i!=json.pageInfo.pageNum)	$j("#wd-pagination").append("<li class=\"wd-page wd-page-go\">"+i+"</li>");
							else $j("#wd-pagination").append("<li class=\"wd-page wd-dead\">"+i+"</li>");
							}
						
						if(json.pageInfo.pageNum < json.pageInfo.numPages - (n/2) && json.pageInfo.numPages != n+1) $j("#wd-pagination").append("<li>...</li><li class=\"wd-page wd-page-go\">"+json.pageInfo.numPages+"</li>");

						}
					

					
					
					if(json.pageInfo.numPages> json.pageInfo.pageNum) $j("#wd-pagination").append("<li class=\"wd-page-go wd-arr wd-page-forw\" >&gt;</li><li  class=\"wd-page-go wd-arr wd-ten-forw\" >&gt;&gt;</li>");
					else $j("#wd-pagination").append("<li  class=\" wd-arr wd-dead\">&gt;</li><li class=\"wd-dead wd-arr\">&gt;&gt;</li>");

				
					/*	if(json.pageInfo.numPages>1 && json.pageInfo.pageNum > 1)  $j("#wd-pagination").append("");
					else $j("#wd-pagination").append("");*/
					
					}
			
			
			
			$j("#wd-pagination .wd-page-go").click(function(){
					var newpage;
					var currpage= Math.abs(hash.page);
					if($j(this).hasClass("wd-page")) newpage = Math.abs($j(this).text());
					else if($j(this).hasClass("wd-ten-back")) newpage = 1;
					else if($j(this).hasClass("wd-page-back")) newpage = currpage - 1;
					else if($j(this).hasClass("wd-ten-forw")) newpage = json.pageInfo.numPages;
					else if($j(this).hasClass("wd-page-forw")) newpage = currpage + 1;
					$weapons.weapons.gallery =  [];
					setHash(newpage, 'page');
					getGallery();
					});
				
		


				initStars("#wd-result-items");
				});


			}



/*=================== VIEWER  ===================*/					
					

	
	
function loadViewer(obj,i){
			var item;

			/*=============NO POUNDING THE VIEW COUNT============*/
			$j("#viewerimage").html("");
			$j("#viewerimage").hide();
			item = $weapons.weapons[obj][i];
			$j("#viewerimage").html("<img src="+item.version[1].url+" width=\"512\" height=\"320\" />");
			viewerItem =item;	
			viewerItem.home = obj;
			viewerItem.index = i;
			$j("#discussion h4 span").text("(.)");
			if($weapons.weapons[obj][i].comments === undefined) {
				$j.getJSON("/weapondesigner/getAssetComments?assetUrl=http://ea.com/"+viewerItem.id, function(json){
					$weapons.weapons[obj][i].comments =item.comments  = viewerItem.comments = json.comments;
					$j("#discussion h4 span").text("(" + $weapons.weapons[obj][i].comments.length + ")").fadeIn("slow");
					})
				}
			else $j("#discussion h4 span").text("(" + $weapons.weapons[obj][i].comments.length + ")");
		
			setHash(item.id, "id");

			if( hash.tab == "details" || hash.tab == "discussion") getTab(hash.tab);
		
			setTimeout('$j("#viewerimage").fadeIn("slow")',750); 

			$j(".urlbox").val(document.location);
			$j("#startdownload").attr("href","/weapondesigner/downloadItem?imageUrl="+item.version[0].url);
			if(item.title == null || item.title == '')
				setOmniValues('','','','contenttitle=','', '', 1, '', '', '');
			else
				setOmniValues('','','','contenttitle='+item.title,'', '', 1, '', '', '');
			if((obj == "features" || obj == "gallery") )$j.ajax({
				url: "/weapondesigner/ajaxWeaponDetail?graphicId="+hash.id+"&incViewCount=true", 
				dataType : "json" , 
				success: function(json){
					var newVcount = json.viewCount;
					//$j(".views"+item.id).text(weapons[obj][i]);
					if($weapons.weapons["features"][item.id]) $weapons.weapons["features"][item.id].ratingCount = newVcount;
					if($weapons.weapons["gallery"][item.idid]) $weapons.weapons["gallery"][item.id].ratingCount = newVcount;
					if($weapons.weapons["state"][item.id]) $weapons.weapons["state"][item.id].ratingCount = newVcount;
					$j(".views"+item.id).text(newVcount);
					}
				});
			
			}
		
		
		
function featItem(i,item){
			$j("#scroll-pane ul").append("<li id=\"feat-"+item.id+"\" class=\"wd-feat-item\"></li>");
			$j("#scroll-pane ul li#feat-"+item.id).html("<span class=\"itemindex\">"+i+"</span>"+
				"<img src=\""+ item.version[2].url +"\" class=\"viewclick\" width=\"96\" height=\"60\" />"+
				"<h5 class=\"viewclick\">"+ item.title +"</h5>"+
				"<p>"+ item.personaName +"<br />"+
				txtAvgScore+" <span class=\""+item.id+"\">"+Math.round(item.rating/2*10)/10 +"</span><br />"+
				txtBasedOn + " <span class=\"rcount"+item.id+"\">"+ item.ratingCount +"</span> Votes <br />"+
				txtTotalViews + " <span class=\"views"+item.id+" \">"+item.viewCount+"</span>"+
				"<div class=\"wd-stars features\"><span  class=\""+item.id+"\">"+ item.rating/2 +"</span></div>");
				
			/*===================MAKE CLICKABLE=====================*/
			initFeatures(i,item);
			
			
			}
		
function initFeatures(i,item){
		$j("#scroll-pane ul #feat-"+item.id+" .viewclick").click(
					function(){
						$j("img.current").removeClass("current");
						$j(".views"+item.id).text(item.viewCount+1);
						$j("#gall-"+item.id+" img , #feat-"+item.id+" img").addClass("current");
						setHash("details", "tab");
						loadViewer("features",  item.id);
						});
				
		$j("#scroll-pane ul #feat-"+item.id+" .viewclick" ).mouseover(function(){
						$j(this).parent().addClass("boxfocus");
						})
					.mouseout(function(){
						$j(this).parent().removeClass("boxfocus");
						});		
		if(item.id == hash.id || hash.id=="" && i==0 ) $j("#scroll-pane ul #feat-"+item.id+" img").addClass("current") ;
		}
		
var featuresIndex = false;
		
function getTab(type,index){
			var data;
			$j("#wd-tabs li").removeClass("on");	
			$j("#"+type).addClass("on");
			$j("#wd-txtarea-wrap").html("").hide();
			$j('#wd-gallerylist .scroll-pane').jScrollPane({showArrows:true,scrollbarWidth:18, scrollbarMargin:10});		
			switch(type)
			 	{
			 
			 
/*===================MAKE FEATURES=====================*/

			 
			 	case "features":
					$j("#wd-gallerylist .jScrollPaneContainer").css({"height":315});
					$j("#scroll-pane").fadeOut("slow");
					$j("#scroll-pane").html("<ul></ul>");
					
					if(!featuresIndex){ /*=========IF FEATURES OBJ IS EMPTY - LOAD SOME ==========*/
						featuresIndex=[];
						$j.getJSON("/weapondesigner/ajaxFeatured", function(json){
							$j("#loading").hide();	
							var first = false;
							$j.each(json.items, function(i,item){
								if(!first) first = item.id;
								$weapons.weapons.features[item.id] = item;
								featItem(item.id,item);
								featuresIndex[i] = item.id;
								});	
							$j("#scroll-pane").fadeIn("medium");	
							initStars("#scroll-pane .wd-feat-item");
							/*===============IF NO #STATE ID PRESENT LOAD THE FIRST FEATURE ============*/
							if(!hash.id){	
							$j("#feat-"+first+" img").addClass("current");

								loadViewer("features", first);
								}
							$j('#wd-gallerylist .scroll-pane').jScrollPane({showArrows:true,scrollbarWidth:18, scrollbarMargin:10})	;
							$j("#wd-gallerylist #scroll-pane")[0].scrollTo(0);	
							
							});
						}
					else{
						$j("#scroll-pane").fadeIn("medium");		
						$j("#loading").hide();
						$j.each(featuresIndex, function(i,featId){
							featItem(i,$weapons.weapons.features[featId]);//initFeatures(i,item)
							$j("#feat-"+featId).show();
							});	
						$j('#wd-gallerylist .scroll-pane').jScrollPane({showArrows:true,scrollbarWidth:18, scrollbarMargin:10})	;
						$j("#wd-gallerylist #scroll-pane")[0].scrollTo(0);	
						initStars("#scroll-pane");
						}
					break;
					
	/*===================MAKE DETAILS=====================*/				
					
				case "details":
					$j("#wd-gallerylist .jScrollPaneContainer").css({"height":315});
					$j("#scroll-pane").hide();

					var item = $weapons.weapons[viewerItem.home][viewerItem.index];
					$j("#scroll-pane").html("<div id=\"wd-item-details\" ></div>");
					$j("#scroll-pane #wd-item-details").append("<h5>"+ item.title +"</h5>"+
						"<p><strong>"+txtUploadedBy +"</strong> "+ item.personaName +"<br />"+
						txtAvgScore+" <span class=\""+item.id+"\">"+Math.round(item.rating/2*10)/10  +"</span><br />"+
						txtBasedOn +" <span class=\"rcount"+item.id+"\"> "+ item.ratingCount +"</span> " + txtVotes+"<br />"+
						txtTotalViews + " <span class=\"views"+item.id+" \">"+item.viewCount+"</span></p>" +
						"<div class=\"detailsRate\"><strong>"+ txtRateThis+"</strong>"+"<div class=\"wd-stars details\"><span class=\""+item.id+"\">"+ item.rating/2 +"</span></div></div>"+
						"<h6>"+txtDescription+"</h6>"+
						"<p class=\"para\">"+ item.description +"</p>");
					$j("#scroll-pane").fadeIn("fast");
					initStars("#scroll-pane #wd-item-details");
					$j('#wd-gallerylist .scroll-pane').jScrollPane({showArrows:true,scrollbarWidth:18, scrollbarMargin:10});	
					$j("#wd-gallerylist #scroll-pane")[0].scrollTo(0);
					$j("#loading").hide();	
					$j("#scroll-pane").fadeIn("fast");
					break;
					
/*=================== MAKE DISCUSSION  A  ===================*/					
					
				case "discussion":
					if(loggedIn) $j("#wd-gallerylist .jScrollPaneContainer").css({"height":230});
					else  $j("#wd-gallerylist .jScrollPaneContainer").css({"height":300});
					var firstMsg = (loggedIn)? txtBeTheFirstToDiscuss:  ""+txtLoginIn +" "+ txtBeTheFirstToDiscuss ;
					$j("#scroll-pane").html("<ul id=\"wd-commenting\"></ul>");
					if($weapons.weapons[viewerItem.home][viewerItem.index].comments === undefined){ //onload call ajax and set features obj
						$j.getJSON("/weapondesigner/getAssetComments?assetUrl=http://ea.com/"+viewerItem.id, function(json){
							if(json.comments.length == 0){
								$j("ul#wd-commenting").append("<li  class=\"wd-comment-item\" id=\"firstcomment\"><h5>"+ firstMsg+"</h5></li>");
								$weapons.weapons[viewerItem.home][viewerItem.index].comments ={};
								}
							$j.each(json.comments, function(i,item){
								$weapons.weapons[viewerItem.home][viewerItem.index].comments[i] = item;
								fillComment(item);
								});
							completeComments();
							});
						}
					else{
						if(!$weapons.weapons[viewerItem.home][viewerItem.index].comments.length || $weapons.weapons[viewerItem.home][viewerItem.index].comments.length == 0 ) {
							$j("ul#wd-commenting").append("<li  class=\"wd-comment-item\" id=\"firstcomment\"><h5>"+ firstMsg+ "</h5></li>");
							}
						else $j.each($weapons.weapons[viewerItem.home][viewerItem.index].comments , function(i,item){
								fillComment(item);
								});	
						completeComments()
						}
					break;	
				}	
		}



/*=================== MAKE DISCUSSION B  ===================*/	




function fillComment(item){		
			
			$j("ul#wd-commenting").append("<li id=\"comment-"+item.id+"\" class=\"wd-comment-item\"></li>"); 
			var y = item.timestamp.year;
				if(y>99) y-= 100;
				if(y<10) y = "0"+y;
			var Hours   = item.timestamp.hours;
			var Mins	= item.timestamp.minutes ;
				if (Mins < 10) {Mins = "0" + Mins;}
			var Secs	= item.timestamp.seconds;
				if (Secs < 10) {Secs = "0" + Secs;}
		/*	Stamp = new Date(parseFloat(item.timestamp.time));
					var Hours; var Mins; var Time; var Day; var Month; var Year;
					Hours = Stamp.getHours();
					Mins = Stamp.getMinutes();
					Secs = Stamp.getSeconds();
				 	Year = Stamp.getYear();
					Month = Stamp.getMonth();
					Day = Stamp.getDate();
					
				if(Year>99) Year-= 100;
				if(Year<10) Year = "0"+Year;
				if (Mins < 10) {Mins = "0" + Mins;}		
				if (Secs < 10) {Secs = "0" + Secs;}
	*/
			
			$j("ul#wd-commenting li#comment-"+item.id).append(
					"<h5 class=\"viewclick\">"+ item.creatorPersonaName +"</h5>"+
					"<span class=\"date\">"+ item.timestamp.date +"-"+ theMonths[item.timestamp.month] +"-"+y+
					" "+ Hours +":"+ Mins +":"+Secs+"</span>"+
					"<p> "+ item.text +" </p>"+
					"<div class=\"wd-flag flag-"+item.id+"\">"+txtFlag +"</div>"
				).hide().fadeIn("slow");	
			$j("#firstcomment").fadeOut("slow");
			$j("#wd-commenttext").val("")
			$j("ul#wd-commenting li#comment-"+ item.id  + " .wd-flag").click(function(){
				tb_show(null,"#TB_inline?height=213&amp;width=470&amp;inlineId=wd-comment-flagbox", null);
				flagthis = item.id;
				}
			).hover(
				function(){$j(this).css({color:"yellow"})},
				function(){$j(this).css({color:"white"})}
			)
			$j("#discussion h4 span").text("("+viewerItem.comments.length+")");
			return item.id;
			}
		
		
		
/*=================== MAKE DISCUSSION  C  ===================*/	


function completeComments(){
			/*=========== INPUT AREA FOR LOGGED IN =========*/	
			if(loggedIn){
				$j("#wd-txtarea-wrap").append("<textarea id=\"wd-commenttext\">"+txtWriteYourCommentHere+"</textarea>"+
					"<div id=\"wd-submitcomment\"></div><span id=\"charcount\">(0/256)</span> "+"<div id=\"cTOS\">"+txtTOSmsg+
					"<a href=\"http://www.ea.com/global/legal/tos.jsp\" onclick=\"openPositionedWindow(this.href, 'tos', 580, 600, 0, 0, true, true);return false;\">"+txtTOS+"</a></div>").show();
				$j("#wd-commenttext").click(function(){
   		 			if($j("#wd-commenttext").val() == txtWriteYourCommentHere){ $j("#wd-commenttext").val("").css("text-transform", "none");
   		 			}
   				}).keyup(function(e){
   					$j("#charcount").text("("+$j(this).val().length+"/256)");
   					if($j(this).val().length>256 && e.which != 8) {
   					  	if (!e) event.returnValue = false;
 						else e.preventDefault();
 						alert(txtToManyChars);
   						}
   					})
   				$j("#wd-submitcomment").click(function(e){	
					if($j("#wd-commenttext").val().length>256) {
						$j("#charcount").text("("+$j(this).val().length+"/256)");
						if (!e) event.returnValue = false;
						else e.preventDefault();
						alert(txtToManyChars);
						return;
						}
			/*		Stamp = new Date();
					var Hours; var Mins; var Time;
					Hours = Stamp.getHours();
					if (Hours >= 12) {Time = " pm.";}
					else {Time = " am";}
					if (Hours > 12) {Hours -= 12;}
					if (Hours == 0) {Hours = 12;}
					Mins = Stamp.getMinutes();
					Secs = Stamp.getSeconds();
					var y = Stamp.getYear();
					var cData = {subtext : t, h : Hours, m : Mins, s : Secs, mnth : Stamp.getMonth(), yr : y , dy : Stamp.getDate() }
					
			*/

					var t = encodeURIComponent($j("#wd-commenttext").val());

					$j.ajax({
						url: "/weapondesigner/postAssetComment?assetUrl=http://ea.com/"+viewerItem.id+"&commentText="+t, 
						dataType : "json" , 
						success: function(json){
						/*	var ncomment ={
								creatorPersonaName:wduser, 
								id:json.commentId, 
								text :cData.subtext, 
								timestamp:{
									hours: cData.h,
									minutes: cData.m,
									seconds: cData.s,
									day : cData.dy,
									month :cData.mnth,
									year : cData.yr
									}
								};*/
							$weapons.weapons[viewerItem.home][viewerItem.index].comments = viewerItem.comments = json.comments;
							var cid = fillComment($weapons.weapons[viewerItem.home][viewerItem.index]["comments"][0]);
	  						$j("#wd-gallerylist #scroll-pane")[0].scrollTo(0);
							$j("li#comment-"+cid).remove().prependTo("ul#wd-commenting");
							$j('#wd-gallerylist .scroll-pane').jScrollPane({showArrows:true,scrollbarWidth:18, scrollbarMargin:10});		

							}
						});
					})
				}
			else{
			
				$j("#wd-txtarea-wrap").append("<div><a href='#' class=\"bigchev\">"+txtLoginToComm+"<span>>></span></a></div> ").show();
				$j("#wd-txtarea-wrap .bigchev").click(function(e){
							if (!e)
								  event.returnValue = false;
							 // Firefox, Safari, Opera
							 else
								 e.preventDefault();
							window.location.href = wdlogginlink + "&surl=" +  window.location.href;
							})
				}
				
						
	  		$j('#wd-gallerylist .scroll-pane').jScrollPane({showArrows:true,scrollbarWidth:18, scrollbarMargin:10});		
	  		$j("#wd-gallerylist #scroll-pane")[0].scrollTo(0);
	  		$j("#loading").hide();	
	  		$j("#scroll-pane").fadeIn("fast");
			}
			
function doStarsMove(obj,e){	
			if(loggedIn){
					var position = obj.position();
					var offset = obj.offset();
					var x = e.pageX - (offset.left);
					$j("span",obj).width(Math.round((x+6)/starX)*starX);                  //$j('#score-display').show().css({'left': e.pageX+16, 'top': e.pageY+16}).html(Math.round(x/starX)*starX);
				}
			else if($j("#wd-pleaselogin a", obj).text()=="") {
					$j(obj).addClass("nostars");
					$j("span",obj).append("<div id='wd-pleaselogin'><a href='#'  class=\"login\">"+txtPleaseLoginRate+"</a></div>");
					$j("#wd-pleaselogin a",obj).click(function(e){
						if (!e)
							  event.returnValue = false;
						 // Firefox, Safari, Opera
						 else
							 e.preventDefault();
						window.location.href = wdlogginlink + "&surl=" +  window.location.href;
						})
					$j("span #wd-pleaselogin", obj).show();
				}
			}
			
			
function doStarsClick(obj,e){			
					if($j("span",obj).hasClass("ranked")) return;
					if(loggedIn){
						var position = obj.position();
						var offset = obj.offset();
						var x = e.pageX - (offset.left);
						var iid = $j("span",obj).attr('class');
						var score = ( (Math.round( (x+6)/starX)  > 5 )? 5 : Math.round((x+6)/starX));
						$j("."+$j("span",obj).attr('class')).attr("title",txtYouGaveThis+" "+ score +" "+txtStars);
						$j.ajax({
							url: "/weapondesigner/rateImage?assetId="+ iid +"&rating="+ score, 
							dataType : "json" , 
							success: function(json){
								starSuccess(iid, json);
								}
							});		
						}
					else return;
				}
			
		function starSuccess(iid,json) {
				var result = json;
				$j("."+result.id).text(+Math.round((result.rating/2)*10)/10);
				$j("."+result.id).width(result.rating*starX/2);   
				//$j('#score-display').show().css({'left': e.pageX+16, 'top': e.pageY+16}).html(Math.round(x/starX)*starX);
				var newRcount = result.ratingCount;
				var newRating = result.rating;
				if($weapons.weapons["features"][iid]){ 
					$weapons.weapons["features"][iid].ratingCount = newRcount; 
					$weapons.weapons["features"][iid].rating = newRating; 
					}
				if($weapons.weapons["gallery"][iid]){
					$weapons.weapons["gallery"][iid].ratingCount = newRcount;
					$weapons.weapons["gallery"][iid].rating = newRating;
					}
				if($weapons.weapons["state"][iid]) {
					$weapons.weapons["state"][iid].ratingCount = newRcount;
					$weapons.weapons["state"][iid].rating = newRating;
					}
				$j(".rcount"+iid ).text(newRcount);
				
				$j("."+iid).addClass("ranked").text( Math.round(newRating/2*10)/10) ;
				}
				
			
			
			
	function initStars(obj){	
			$j('.wd-stars',obj).each(function(){
				$j("span",this).width(starX * Math.abs($j("span",this).text()));
				$j(this).attr('title',"Current score "+(Math.round(Math.abs($j("span",this).text())*10)/10)+" stars");
				});		
			$j('.wd-stars',obj).mousemove(function(e){
					doStarsMove($j(this), e)
				}).click(function(e){
					doStarsClick($j(this), e);
				})
				.mouseleave(function(){
					$j("#wd-pleaselogin",this).remove();
					$j(this).removeClass("nostars");
					$j("span",this).width(starX * Math.abs($j("span",this).text()));
				});
			}
			
			
			
			
		
		$j('#wd-search-tools .chooser h4').click(function(){
			$j(this).next("ul").toggle();
			 $j(".chooser").bind("mouseleave", function(){
				$j("ul", this).hide();
				$j(".chooseritems").css('background-color','transparent').addClass('color','#fff');
				})
			});  
			
			
		$j(".chooseritems").mouseover(function(){
			$j(".chooseritems").removeClass("highlight");
			$j(this).addClass("highlight");
			});

			
		$j(".chooseritems").click(function(){
			$j(this).parent().prev().html($j(this).html())
			$j(this).parent().fadeOut("slow");
		
			setHash($j(this).attr('id'), $j(this).parent().attr('id'));
			setHash(1, "page");
			if( $j(this).parent().attr('id') == "sortOrder" || $j(this).parent().attr('id') == "periodType") getGallery();
			//setSearchCriteria($j(this).attr('id'), "form_"+$j(this).parent().attr('id'));
			})

		
		$j(".wd-close").hover(
				function(){
      				$j(this).css({"color": "#fff","border-color": "#ffffff"})
      				},
      			function(){
      				$j(this).css({"color": "#797979","border-color": "#797979"});
      				}
   		 	).click(tb_remove);
   		
   		 $j(".wd-popbox .noflag").click(tb_remove);	
   		$j("input#searchstring").keypress(function(e){
			 if (e.which == 13) {
			 	setHash("searchResults", "sortOrder");
				setHash($j("input#searchstring").val(), "searchField");
				getGallery();
				}
			}
		) 
   		$j("#wd-content-nav a.wd-gosubmiss").click(function(){
				$j("#main-content").fadeOut("fast").addClass("wd-mydesigns");
				$j.ajax({
					url: "/weapondesigner/mySubmissions", 
					dataType : "json" , 
					success: function(json){
						$j.each(json.items, function(i,item){
							var mystatus = (item.approved)? txtApproved : txtPending;
							$j("#wd-my-items").append("<li id=\"mysub-"+item.id+"\"></li>");
							
							$j("#wd-my-items li#mysub-"+item.id).append("<img src="+item.version[1].url+" width=\"512\" height=\"320\" />"+
							"<div class=\"mysub-wrap\">"+
							"	<h5>"+ item.title +"</h5>"+
							"	<p><strong>"+txtUploadedBy+"</strong> "+ item.personaName +"</p>"+
							"	<div class=\"off-score\"><strong>"+txtOffScore+" "+item.rating/2 +"</strong><div class=\"wd-stars\"><span  class=\""+item.id+"\">"+ item.rating/2 +"</span></div></div>"+
							"	<p>"+txtBasedOn+" "+ item.ratingCount +" Votes</p>"+
							"	<h6>"+txtDescription+"</h6><p class=\"wd-desc\">"+ item.description +"</p>"+
							"	<p class=\"wd-status\"><span class=\"red\">"+txtStatus+" </span> "+ mystatus +"</p>"+
							"</div>"
							);
							
							
							});
						initStars("#wd-my-items");
						}
					
					});
					
				$j("#main-content").fadeIn("fast");
				});
		
		
		
		$j("#wd-submissions-nav a.wd-gosubmiss").click(
			function(){
   				$j("#main-content").fadeOut("fast")
				.removeClass("wd-mydesigns").fadeIn("fast");
   				}
   			);
		
		$j("#searchbutt").click(function(){
			setHash("searchResults", "sortOrder");
			setHash($j("input#searchstring").val(), "searchField");
			getGallery();
			})	
			
			
		$j("#wd-tabs li h4").click(function(){
			if(!$j(this).parent().hasClass("on")){
				$j("#wd-tabs li ").removeClass("on");
				$j(this).parent().addClass("on");
				$j("#scroll-pane").hide();
				$j("#loading").show();
				getTab($j(this).parent().attr('id'));
				setHash($j(this).parent().attr('id'), 'tab');
				}
			})

	$j(".login").click(function(e){
			if (!e)
  				  event.returnValue = false;
 			 // Firefox, Safari, Opera
 			 else
   				 e.preventDefault();
   			window.location.href = wdlogginlink + "&surl=" +  window.location.href;
			})
	
	$j("#wd-result-items .wd-result-item").bind("mouseenter", function(){
		
				$j("img", this).css('border-color','yellow').addClass('color','#fff');
				}).bind("mouseleave", function(){
		
				$j("img", this).css('border-color','#383838').addClass('color','#fff');
				})
	
		
	$j("#wd-download-image").click(
			function(){
				$j(".sharebox-item").hide();
				$j("#download-terms-box").fadeIn("fast");
				}
			);	
	$j(" #close-terms").click(function(){
			$j("#download-terms-box").hide();
			$j(".sharebox-item").fadeIn("fast");			
			});	
			
	
	$j(".close.trans").bind("click",
			function(e){
			tb_remove();
			$j("body").removeClass("transbox");
  			if (!e)
  				  event.returnValue = false;
 			 // Firefox, Safari, Opera
 			 else
   				 e.preventDefault();					
			});	
	/* not needed
	$j("#n1 a").bind("click", function(e){
			$j("body").addClass("transbox");
			tb_show(null,"#TB_inline?&height=653&width=920&amp;inlineId=commbox", null);
			if (!e)
  				  event.returnValue = false;
 			 else
   				 e.preventDefault();
			});	
	*/
	$j("#shareboxlink").bind("click",
		function(e){
			
				$j("body").addClass("transbox");
			tb_show(null,$j(this).attr("href"), null);
 			
			})	

    $j('#footer-links')
            .hover(function() {
                $j('#footer #links').slideDown('slow');
            }, function() {
                $j('#footer #links').slideUp('slow');
            });
    //gus function to expand menus
	$j(".uploadlink").click(function(e){
	 tb_show(null,((!e)?"#TB_inline?height=513&width=462&inlineId=uploadbox":"/weapondesigner/submitDesignDialog?TB_iframe=true&height=503&amp;TB_iframe=true&amp;width=462"), null);
		})}
}
$j("body").addClass("transbox");
function transbox(){
	$j("body").addClass("transbox");
	}

$j(document).ready($weapons.init);
