function Scrolly(func){
	this.func=func;this.v1=false;this.v2=false;
	this.D1=function(){
		this.v1=(document.body.scrollHeight>window.innerHeight)?true:false;
	}
	this.D1();
	this.D2=function(){
		this.v2=(document.body.scrollHeight>window.innerHeight)?true:false;
		if(this.v1!=this.v2){
			this.func();
		}
	}
	return this;
}
function StripPx(val){return Number(val.replace("px",""));}
function GetCols(width,sizearray){
	var cnt=sizearray.length-1;
	for(var i=0;i<cnt;i++){
		if(width<=sizearray[i][0]){
			return sizearray[i][1];
		}
	}
	return sizearray[cnt];
}
function NormalSizes(){
	return [[320,1],[640,2],[1280,3],[3]];
}
function ResizeWhenLoaded(obj,resizefunc,width,height){
	if(obj.complete){
		resizefunc(obj,width,height);
	}else{
		$(obj).css('opacity',0);
		obj.onload=function(){
			resizefunc(obj,width,height);
			$(obj).css('opacity',1);
		}
	}
}
function GetPadding(){return 8;}
function AdjustBecauseOfScroll(scrollvar,func){if(!scrollvar){func();}}
function T65Load(runner){runner();window.onresize=runner;}

function AssignMiniIconsSizer(menuid){
	var o=$(".MiniStartHolder").html();
	var original=$("#NormalNaviLinks #menu-item-"+menuid).html();
	$("#NormalNaviLinks #menu-item-"+menuid).html(original+o);
	$(".MiniStartHolder").html("");
}
function ShowMiniIcons(){
	$("#NormalNaviLinks .MiniShowIcons").css("display","");
	$("#NormalNaviLinks .MiniShowIcons").animate({"opacity":1},200);
}
function HideMiniIcons(){
	$("#NormalNaviLinks .MiniShowIcons").animate({"opacity":0},200);
	setTimeout(function(){
						$(".MiniShowIcons").css("display","none");},201);
}
function SizeSocialPanel(){
	var nw=StripPx($(".UIMain").css("width"))*0.6;
	if(window.innerWidth<=420){
		nw=300;
	}
	$(".SocialPanel").css("width",nw);
	$(".SocialPanel").css("left",-nw);
	$('.SocialPanelHolder').css('width',1);
	$(".SocialPanel").css('top',$('#SocialButtonHeader').outerHeight());
}
function HideSocialPanel(){$(".SocialPanel").animate({"opacity":0},200);DisplayNone($(".SocialPanel")[0],201);}
function DisplayNone(obj,time){setTimeout(function(){$(obj).css("display","none");},time);}
function ShowSocialPanel(){
	if($('.SearchBox').css('display')!='none'){
		HideSearchBox();
	}
	if($('.SocialPanel').css('display')=='none'){
		$(".SocialPanel").css("display","").css('opacity',0).animate({'opacity':1},200);
	}else{
		HideSocialPanel();
	}
}
	
function ResizeImg4(obj,maxw,maxh,padding){
	//maxw,maxh - width and height OF the image
	//maintain - whether to keep the height or the width as best as possible
	var width=StripPx($(obj).find("img").css("width"));var height=StripPx($(obj).find("img").css("height"));
	var ratio=height/width;
	var cratio=maxh/maxw;
	$(obj).find(".ImgHolder").css("overflow","hidden");//always hide extra!
	
	if(cratio>=ratio){
		//height of container longer than height of image proportionally
		$(obj).find("img").css("height",maxh).css("width",maxh/ratio);
		var imgwidth=maxh/ratio;
		var newleft=(imgwidth-maxw)/-2;
		$(obj).find("img").css("left",newleft);
	}else{
		$(obj).find("img").css("width",maxw).css("height",maxw*ratio);
		var imgheight=maxw*ratio;
		var newtop=(imgheight-maxh)/-2;
		$(obj).find("img").css("top",newtop);
	}
	$(obj).find(".ImgHolder").css("width",maxw).css("height",maxh);
}
function ResizeImg5(obj,containerwidth,containerheight){
	$(obj).css("width","").css("height","");
	var cratio=containerheight/containerwidth;
	var width=StripPx($(obj).css('width'));
	var height=StripPx($(obj).css('height'));
	var ratio=height/width;
	
	if(cratio>=ratio){
		$(obj).css('height',containerheight).css("width",containerheight/ratio);
		$(obj).css('position','relative').css('left',(containerheight/ratio-containerwidth)*-0.5);
	}else{
		$(obj).css("width",containerwidth).css("height",containerwidth*ratio);
		$(obj).css('position','relative').css('top',(containerwidth*ratio-containerheight)*-0.5);
	}
}
function GetStyleCols(name,defaultnum){if($(name)[0]!=null){var x=Number(StripPx($(name).css("width")));if(x<=10){return x;}else{return 10;}}else{return defaultnum;}}

function ShowSearchBox(){
	var width=StripPx($('.SearchBox').css('width'));
	var buttonwidth=StripPx($('.SearchButton').css('width'));
	
	$('.SearchBox .Liner').css('width',width-buttonwidth+1);
	$('.SearchButton img').css('border','solid thin #ccc').css('border-bottom','none').css('border-radius','0.5em 0.5em 0 0');
	if($('.SocialPanel').css('display')!='none'){
		HideSocialPanel();
	}
	if($('.SearchBox').css('display')=='none'){
		$(".SearchBox").css('display','').css('opacity',0).animate({'opacity':1},200);
	}else{
		HideSearchBox();
	}
}
function HideSearchBox(){
	$('.SearchButton img').css('border','solid thin #ccc').css('border-radius','0.5em');
	$('.SearchButton img').mouseenter(null);
	$('.SearchButton img').mouseenter(function(){
		$('.SearchButton img').css('border','solid thin #ccc');
	}).mouseleave(function(){
		$('.SearchButton img').css('border','solid thin #fff');
	});
	$(".SearchBox").animate({"opacity":0},200);
	DisplayNone($(".SearchBox")[0],201);
}
function SizeScreenSmallMenu(){
	var width=StripPx($('#Sizer3').css('width'));
	$('.UINaviLinksSmallScreen').css('width',width);
}
function LClick(event){
	if(event.button==0){return true;}return false;}
function SetupSmallScreenButton(){
	$('#SmallScreenMenuButton').mousedown(function(event){
		if(LClick(event)){
			if($('#UISmallScreenMenu').css('display')=='none'){
				$('#SmallScreenMenuButton')[0].className="Button1 Button1Active";
				$('#UISmallScreenMenu').css('opacity',0).css('display','').animate({'opacity':1},200);
			}else{
				$('#SmallScreenMenuButton')[0].className="Button1";
				$('#UISmallScreenMenu').animate({'opacity':0},200);
				DisplayNone($('#UISmallScreenMenu')[0],201);
			}
		}
												   });
}
