// For the pop-up galleries

function OpenGG (c) {
if (screen.width / 2 <= 730) {
	var w = 775;
	} else {
	var w = (screen.width * .65);
	}
var h = (screen.height - 100);
window.open(c,
			   'ggslideshow',
'width='+w+',height='+h+',top=0,left=0,scrollbars=yes,status=yes,resizable=yes');
}

function OpenGGVideo (c) {
if (screen.height <= 600) {
	var h = 500;
	var w = 415;
	} else {
	var w = 405;
	var h = 620;
	}
window.open(c,
			   'ggvideo',
'width='+w+',height='+h+',top=0,left=0,scrollbars=yes,status=yes,resizable=no'); 
}


// Menu Animation

$(document).ready(function(){
	$('#sitemenu a').css({backgroundPosition: "0px -75px"})
		.mouseover(function() {
			$(this).stop().animate({
				backgroundPosition:"(-20px -18px)",scrollTop:400}, 300, "easeInCirc")
		})
		.mouseout(function() {
			$(this).stop().animate({
				backgroundPosition:"(60px -75px)"}, 800, "easeOutCirc", function() {
					$(this).css({backgroundPosition: "0px -75px"})
				})
		})
});

// User Drop-Down Menus

$(document).ready(function() {
	$("li.dropdown").hover(
		function() {
			$(this).addClass("active");
			$(this).find("ul.submenu").fadeIn("fast");
		},
		function() {
			$(this).removeClass("active");
			$(this).find("ul.submenu").fadeOut("fast");	
		}
	)
});

// Comment limiter

function limitChars(textid,limit,infodiv)	{
	var text = $('#'+textid).val();
	var textLength = text.length;
	
	if(textLength > limit)	{
		$('#'+infodiv).html('You cannot write more than <b>'+limit+'</b> characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}	else	{
		$('#'+infodiv).html('You have <b>'+ (limit - textLength) +'</b> characters left.');
		return true;
	}
}

$(document).ready(function(){
	
	// Setup Login Box
	
	$("#login").mouseover(function()	{
		$("#loginform").fadeIn("fast");
		$("#login").addClass('active');
		loginShowing = true;
		$("#loginform :text").focus();
	});
	
	$("a").not("#login").mouseover(function()	{
		$("#loginform").fadeOut("fast");
		$("#login").removeClass('active');
		$("#loginform :text").blur();
		loginShowing = false;
	});


	// Setup generic tab-switching function

	var allTabs = $("ul.tabs li");
	var tabSelectors = jQuery.makeArray($(allTabs).parent([0]));

	$(tabSelectors).each(function(n)	{
		var theTabContent = ($(this).parent("div").find(".tabwrap"));
		var theTabs = ($(this).find("a"));
		$(theTabs).attr("id", function(u)	{
			return "tab" + u;
		});

		var curTab;
		
		$(theTabs).click(function() {
			$(theTabs).removeClass('active');
			$(this).addClass('active');
			curTab = $(theTabs).index(this);
			$(theTabContent).css("z-index",99);			
			$(theTabContent[curTab]).css("z-index",100);			
			return false;
		});
	
	});
	
	
	// Setup generic scrolling pane function
	
	var paneScrolling = false;	
	var allPages = $(".pagewrap");
	var pageSelectors = jQuery.makeArray($(allPages).parent([0]));
	
	$(pageSelectors).each(function(i)	{
		var thePages = jQuery.makeArray($(this).children(".pagewrap"));
		var curPage = 0;
		var nextPage;
		var prevPage;
		var easeMethod = "easeInOutBack";
		
		$(thePages).hide();
		$(thePages[curPage]).show();
		
		$(thePages).parent("div").find("a.arrow.next").click(function()	{
			if(paneScrolling)	{
				return false;
			}	else	{
				paneScrolling = true;
				nextPage = $(thePages[curPage+1]);
				$(thePages).parent("div").find("a.arrow.prev").show();
				nextPage.css("marginLeft",$(thePages[curPage]).width());
				nextPage.show();
		
				$(thePages[curPage]).animate({
				marginLeft: "-="+$(thePages[curPage]).width()+"+1"
				}, 600, easeMethod);
		
				nextPage.animate({
				marginLeft: "-="+$(thePages[curPage]).width()
				}, 600, easeMethod, function()	{
					if((curPage+1) >= $(thePages).length)	{
						$(thePages).parent("div").find("a.arrow.next").hide();
						}
					if(curPage > 0)	{
						$(thePages).parent("div").find("a.arrow.prev").show();
						}
					paneScrolling = false;
					}
				);
				curPage++;
				return false;
			}
		});

		$(thePages).parent("div").find("a.arrow.prev").click(function()	{
			if(paneScrolling)	{
				return false;
			}	else	{
			paneScrolling = true;
			prevPage = $(thePages[curPage-1]);
			$(thePages).parent("div").find("a.arrow.next").show();
	
			$(thePages[curPage]).animate({
			marginLeft: "+="+$(thePages[curPage]).width()
			}, 600, easeMethod);
	
			prevPage.animate({
			marginLeft: "+="+$(thePages[curPage]).width()
			}, 600, easeMethod, function()	{
				if(curPage <= 0)	{
					$(thePages).parent("div").find("a.arrow.prev").hide();
					}

				if(curPage < $(thePages).length)	{
					$(thePages).parent("div").find("a.arrow.next").show();
					}
					paneScrolling = false;
				}
			);
			curPage--;
			return false;
			}
		});
		
	});
		
});

/*
CSS Browser Selector v0.2.9
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
var css_browser_selector = function() {var ua=navigator.userAgent.toLowerCase(),is=function(t){return ua.indexOf(t) != -1;},h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera\s(\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('chrome')?'chrome webkit safari':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js'; h.className += h.className?' '+c:c;}();


/*

jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing

*/

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('h.i[\'1a\']=h.i[\'z\'];h.O(h.i,{y:\'D\',z:9(x,t,b,c,d){6 h.i[h.i.y](x,t,b,c,d)},17:9(x,t,b,c,d){6 c*(t/=d)*t+b},D:9(x,t,b,c,d){6-c*(t/=d)*(t-2)+b},13:9(x,t,b,c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g)*8.r(c/a);6-(a*8.j(2,10*(t-=1))*8.n((t*d-s)*(2*8.g)/p))+b},H:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d)==1)6 b+c;e(!p)p=d*.3;e(a<8.w(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.r(c/a);6 a*8.j(2,-10*t)*8.n((t*d-s)*(2*8.g)/p)+c+b},T:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d/2)==2)6 b+c;e(!p)p=d*(.3*1.5);e(a<8.w(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.r(c/a);e(t<1)6-.5*(a*8.j(2,10*(t-=1))*8.n((t*d-s)*(2*8.g)/p))+b;6 a*8.j(2,-10*(t-=1))*8.n((t*d-s)*(2*8.g)/p)*.5+c+b},F:9(x,t,b,c,d,s){e(s==u)s=1.l;6 c*(t/=d)*t*((s+1)*t-s)+b},E:9(x,t,b,c,d,s){e(s==u)s=1.l;6 c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},16:9(x,t,b,c,d,s){e(s==u)s=1.l;e((t/=d/2)<1)6 c/2*(t*t*(((s*=(1.B))+1)*t-s))+b;6 c/2*((t-=2)*t*(((s*=(1.B))+1)*t+s)+2)+b},A:9(x,t,b,c,d){6 c-h.i.v(x,d-t,0,c,d)+b},v:9(x,t,b,c,d){e((t/=d)<(1/2.k)){6 c*(7.q*t*t)+b}m e(t<(2/2.k)){6 c*(7.q*(t-=(1.5/2.k))*t+.k)+b}m e(t<(2.5/2.k)){6 c*(7.q*(t-=(2.14/2.k))*t+.11)+b}m{6 c*(7.q*(t-=(2.18/2.k))*t+.19)+b}},1b:9(x,t,b,c,d){e(t<d/2)6 h.i.A(x,t*2,0,c,d)*.5+b;6 h.i.v(x,t*2-d,0,c,d)*.5+c*.5+b}});',62,74,'||||||return||Math|function|||||if|var|PI|jQuery|easing|pow|75|70158|else|sin|sqrt||5625|asin|||undefined|easeOutBounce|abs||def|swing|easeInBounce|525|cos|easeOutQuad|easeOutBack|easeInBack|easeInSine|easeOutElastic|easeInOutQuint|easeOutQuint|easeInQuint|easeInOutQuart|easeOutQuart|easeInQuart|extend|easeInElastic|easeInOutCirc|easeInOutCubic|easeOutCirc|easeInOutElastic|easeOutCubic|easeInCirc|easeInOutExpo|easeInCubic|easeOutExpo|easeInExpo||9375|easeInOutSine|easeInOutQuad|25|easeOutSine|easeInOutBack|easeInQuad|625|984375|jswing|easeInOutBounce'.split('|'),0,{}))

/**
 * BGPos, Copyright author Alexander Farkas
 * v. 1.02
 */

$.extend($.fx.step,{
	backgroundPosition: function(fx) {
		if (fx.state === 0 && typeof fx.end == 'string') {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			start = toArray(start);
			fx.start = [start[0],start[2]];
			var end = toArray(fx.end);
			fx.end = [end[0],end[2]];
			fx.unit = [end[1],end[3]];
		}
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	   function toArray(strg){
		   strg = strg.replace(/left|top/g,'0px');
		   strg = strg.replace(/right|bottom/g,'100%');
		   strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		   var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		   return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	   }
	}
});

/*
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 9/11/2008
 * @author Ariel Flesler
 * @version 1.4
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
*/
;(function(h){var m=h.scrollTo=function(b,c,g){h(window).scrollTo(b,c,g)};m.defaults={axis:'y',duration:1};m.window=function(b){return h(window).scrollable()};h.fn.scrollable=function(){return this.map(function(){var b=this.parentWindow||this.defaultView,c=this.nodeName=='#document'?b.frameElement||b:this,g=c.contentDocument||(c.contentWindow||c).document,i=c.setInterval;return c.nodeName=='IFRAME'||i&&h.browser.safari?g.body:i?g.documentElement:this})};h.fn.scrollTo=function(r,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};a=h.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=h(k),d=r,l,e={},p=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(d)){d=n(d);break}d=h(d,this);case'object':if(d.is||d.style)l=(d=h(d)).offset()}h.each(a.axis.split(''),function(b,c){var g=c=='x'?'Left':'Top',i=g.toLowerCase(),f='scroll'+g,s=k[f],t=c=='x'?'Width':'Height',v=t.toLowerCase();if(l){e[f]=l[i]+(p?0:s-o.offset()[i]);if(a.margin){e[f]-=parseInt(d.css('margin'+g))||0;e[f]-=parseInt(d.css('border'+g+'Width'))||0}e[f]+=a.offset[i]||0;if(a.over[i])e[f]+=d[v]()*a.over[i]}else e[f]=d[i];if(/^\d+$/.test(e[f]))e[f]=e[f]<=0?0:Math.min(e[f],u(t));if(!b&&a.queue){if(s!=e[f])q(a.onAfterFirst);delete e[f]}});q(a.onAfter);function q(b){o.animate(e,j,a.easing,b&&function(){b.call(this,r,a)})};function u(b){var c='scroll'+b,g=k.ownerDocument;return p?Math.max(g.documentElement[c],g.body[c]):k[c]}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);


// Uber-Secret Code.
var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
$(document).keydown(function(e) {
	kkeys.push( e.keyCode );
	if ( kkeys.toString().indexOf( konami ) >= 0 )
		window.location = "/secret";
}, false);