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

/***  twitter.js author: Remy Sharp http://remysharp.com ***/
if(typeof renderTwitters!='function')(function(){var j=(function(){var b=navigator.userAgent.toLowerCase();return{safari:/webkit/.test(b),opera:/opera/.test(b),msie:/msie/.test(b)&&!(/opera/).test(b),mozilla:/mozilla/.test(b)&&!(/(compatible|webkit)/).test(b)}})();var k=0;var n=[];var o=false;window.renderTwitters=function(a,b){function node(e){return document.createElement(e)}function text(t){return document.createTextNode(t)}var c=document.getElementById(b.twitterTarget);var d=null;var f=node('ul'),li,statusSpan,timeSpan,i,max=a.length>b.count?b.count:a.length;for(i=0;i<max&&a[i];i++){d=getTwitterData(a[i]);if(b.ignoreReplies&&a[i].text.substr(0,1)=='@'){max++;continue}li=node('li');if(b.template){li.innerHTML=b.template.replace(/%([a-z_\-\.]*)%/ig,function(m,l){var r=d[l]+""||"";if(l=='text'&&b.enableLinks)r=linkify(r);return r})}else{statusSpan=node('span');statusSpan.className='twitterStatus';timeSpan=node('span');timeSpan.className='twitterTime';statusSpan.innerHTML=a[i].text;if(b.enableLinks==true){statusSpan.innerHTML=linkify(statusSpan.innerHTML)}timeSpan.innerHTML=relative_time(a[i].created_at);if(b.prefix){var s=node('span');s.className='twitterPrefix';s.innerHTML=b.prefix.replace(/%(.*?)%/g,function(m,l){return a[i].user[l]});li.appendChild(s);li.appendChild(text(' '))}li.appendChild(statusSpan);li.appendChild(text(' '));li.appendChild(timeSpan)}f.appendChild(li)}if(b.clearContents){while(c.firstChild){c.removeChild(c.firstChild)}}c.appendChild(f)};window.getTwitters=function(e,f,g,h){k++;if(typeof f=='object'){h=f;f=h.id;g=h.count}if(!g)g=1;if(h){h.count=g}else{h={}}if(!h.timeout&&typeof h.onTimeout=='function'){h.timeout=10}if(typeof h.clearContents=='undefined'){h.clearContents=true}if(h.withFriends)h.withFriends=false;h['twitterTarget']=e;if(typeof h.enableLinks=='undefined')h.enableLinks=true;window['twitterCallback'+k]=function(a){if(h.timeout){clearTimeout(window['twitterTimeout'+k])}renderTwitters(a,h)};ready((function(c,d){return function(){if(!document.getElementById(c.twitterTarget)){return}var a='http://www.twitter.com/statuses/'+(c.withFriends?'friends_timeline':'user_timeline')+'/'+f+'.json?callback=twitterCallback'+d+'&count=20';if(c.timeout){window['twitterTimeout'+d]=setTimeout(function(){if(c.onTimeoutCancel)window['twitterCallback'+d]=function(){};c.onTimeout.call(document.getElementById(c.twitterTarget))},c.timeout)}var b=document.createElement('script');b.setAttribute('src',a);document.getElementsByTagName('head')[0].appendChild(b)}})(h,k))};DOMReady();function getTwitterData(a){var b=a,i;for(i in a.user){b['user_'+i]=a.user[i]}b.time=relative_time(a.created_at);return b}function ready(a){if(!o){n.push(a)}else{a.call()}}function fireReady(){o=true;var a;while(a=n.shift()){a.call()}}function DOMReady(){if(j.mozilla||j.opera){document.addEventListener("DOMContentLoaded",fireReady,false)}else if(j.msie){document.write("<scr"+"ipt id=__ie_init defer=true src=//:><\/script>");var a=document.getElementById("__ie_init");if(a){a.onreadystatechange=function(){if(this.readyState!="complete")return;this.parentNode.removeChild(this);fireReady.call()}}a=null}else if(j.safari){var b=setInterval(function(){if(document.readyState=="loaded"||document.readyState=="complete"){clearInterval(b);b=null;fireReady.call()}},10)}}function relative_time(a){var b=a.split(" ");a=b[1]+" "+b[2]+", "+b[5]+" "+b[3];var c=Date.parse(a);var d=(arguments.length>1)?arguments[1]:new Date();var e=parseInt((d.getTime()-c)/1000);e=e+(d.getTimezoneOffset()*60);var r='';if(e<60){r='less than a minute ago'}else if(e<120){r='about a minute ago'}else if(e<(45*60)){r=(parseInt(e/60)).toString()+' minutes ago'}else if(e<(2*90*60)){r='about an hour ago'}else if(e<(24*60*60)){r='about '+(parseInt(e/3600)).toString()+' hours ago'}else if(e<(48*60*60)){r='1 day ago'}else{r=(parseInt(e/86400)).toString()+' days ago'}return r}function linkify(s){return s.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g,function(m){return m.link(m)}).replace(/@[\S]+/g,function(m){return'<a href="http://twitter.com/'+m.substr(1)+'">'+m+'</a>'})}})();

jQuery.easing.easeOutQuart = function (x, t, b, c, d) {return -c * ((t=t/d-1)*t*t*t - 1) + b;};
jQuery.easing.easeInQuart = function (x, t, b, c, d) {return c*(t/=d)*t*t*t + b;};

$(document).ready(function() {  
	//process mouseovers
	$("div.process").mouseover(function() {$(this).children(".processHide").css('display','block');}).mouseout(function(){$(this).children(".processHide").css('display','none');});
	//nav scrolling anchors
	$('a.nav').click(function(){
		var index = $(this).attr("rel");
		if ($(this).hasClass('showHide')) //showHide behavior
			{
				if( parseInt($('#wrapperRight').css('left')) == 0) {closeCenter(); return false;}
				else {openCenter();	$('ul#menu li:eq(3)').children().removeClass('on'); $('ul#menu li:eq(0)').children().addClass('on'); return false;}
			}
		else //everything else
			{	//open if it's closed
				if (parseInt($('#wrapperRight').css('left')) == -390){openCenter();}
				$.scrollTo(index, 400); //fix this to scroll to DOM	
			}
		$('a.nav').removeClass('on');
		if ($(this).hasClass('logo')){$('ul#menu li:eq(0)').children().addClass('on');} else {$(this).addClass('on');}
		return false;
	});	// $('a.nav').click //

	$('.gallery .banner').click(function(){$(this).prev().click();});
	$('#right h2').click(function(){
		if (parseInt($('#wrapperRight').css('left')) == 0) {closeCenter();}
		galleryAccordion($(this).parent().parent());
		return false;
	});
	
	$('a.videoDot').click(function(){
		$('#pagerVideo li').removeClass('activeSlide');
		$(this).parent().addClass('activeSlide');
		$('#ifrm').attr('src',$(this).parent().attr('rel'));
		//window.frames['ifrm'].location = $(this).parent().attr('rel');
	});
		
});// end $(document).ready //

function galleryAccordion(target) //target is li
	{ //if clicked-on target rotator is open, reset them all to neutral
	if (parseInt($(target).css('height'),10) == 390)
		{
		if ($(target).attr('id') == 'liVideo') {$('#ifrm').attr('src',"").css('display','none');} 	//if target is Video, turn off the iframe before it starts to shut
		$(target).children().animate({height: 180},{complete: function(){$(target).children().children('.rotator').css('display','none');}}); // shut, callback turns off the rotator after it's shut
		$(target).children().children('.banner').animate({height: 125});//put back the banner
		$(target).siblings().children().animate({height: 180});//put others back to neutral
		}
	else //if target rotator is neutral or shut
		{
		$(target).children().children('.rotator').css('display','block');//turn on rotator
		//if target rotator is Video, turn on the iframe after it opens
		if ($(target).attr('id') == 'liVideo') {$(target).children().animate({height: 390}
																			,{complete: function(){$('#ifrm').css('display','block');
																									$('#pagerVideo li').each(
																										function() {
																										if ($(this).hasClass('activeSlide'))
																											{$('#ifrm').attr('src',$(this).attr('rel'));}
																										});
																									}
																			}
																			);}
			else {$(target).children().animate({height: 390});} // otherwise just open target all the way
		

		$(target).children().children('.banner').animate({height: 0});//retract the banner
		$(target).siblings().children().animate({height: 75});// shut the others
		$(target).siblings().each(function() 		//look for retracted banners and set to neutral any that are shut
			{
			if(parseInt($(this).children().children('.banner').css('height'),10) == 0)
				{$(this).children().children('.banner').animate({height:125},//put back the banner
				{complete: function(){$(this).next().css('display','none');}});//turn off the rotator after it slides down
				// ???????WHY NEXT
				}
			});
		}
	}
	
function openCenter() {
	$('#center').css('display','inline');
	$('#wrapperRight').animate({left: 0}, 300, 'easeInQuart');
	$('#right').animate({left: 650}, 300, 'easeInQuart');
	$('#slidingArrow').animate({marginLeft: -50});
	$('#right li').each(function(){if(parseInt($(this).css('height'),10) == 390){galleryAccordion($(this));}});
}
function closeCenter() {
	$('#wrapperRight').animate({left: -390}, 300, 'easeInQuart', function(){$('#center').css('display','none');});
	$('#right').animate({left: 250}, 300, 'easeInQuart');
	$('#slidingArrow').animate({marginLeft: 665});
	$('a.nav').removeClass('on'); 
	$('ul#menu li:eq(3)').children().addClass('on');	
}

// rotator //
$(function() {$('#right code').each(function() {eval($(this).text());});
    $('.cycleWrapper').hover(
        function() { $(this).children('.textBox').slideDown(); },
        function() { $(this).children('.textBox').slideUp(); }
    );
});
function onAfter() {$(this).parent().next().html('<p>' + this.alt + '</p>');}

//function r                                                                                                                                                                                         

function onBeforeVideo() {$('#ifrm').css('display','none');}
//function onAfterVideo() {if (parseInt($('#videoBanner').css('height'),10) == 0) {$('#videoPlayer').css('display','block');}}




// twitter //
window.onload = getTwitters('twitters', {id: 'OwegoHouse', clearContents: true, count: 1, withFriends: true, ignoreReplies: false,
				template: '<span class="status">"%text%"</span> <span class="time"><br/><hr/><a href="http://twitter.com/%user_screen_name%/statuses/%id_str%">%time%</a></span>'});
  
function externalLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) { var anchor = anchors[i]; if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; } } window.onload = externalLinks;
