$(document).ready(function(){

	$('body').removeClass('no_JS');
	
	LazyLoad=function(){var f=document,g,b={},e={css:[],js:[]},a;function j(l,k){var m=f.createElement(l),d;for(d in k){if(k.hasOwnProperty(d)){m.setAttribute(d,k[d])}}return m}function h(d){var l=b[d];if(!l){return}var m=l.callback,k=l.urls;k.shift();if(!k.length){if(m){m.call(l.scope||window,l.obj)}b[d]=null;if(e[d].length){i(d)}}}function c(){if(a){return}var k=navigator.userAgent,l=parseFloat,d;a={gecko:0,ie:0,opera:0,webkit:0};d=k.match(/AppleWebKit\/(\S*)/);if(d&&d[1]){a.webkit=l(d[1])}else{d=k.match(/MSIE\s([^;]*)/);if(d&&d[1]){a.ie=l(d[1])}else{if((/Gecko\/(\S*)/).test(k)){a.gecko=1;d=k.match(/rv:([^\s\)]*)/);if(d&&d[1]){a.gecko=l(d[1])}}else{if(d=k.match(/Opera\/(\S*)/)){a.opera=l(d[1])}}}}}function i(r,q,s,m,t){var n,o,l,k,d;c();if(q){q=q.constructor===Array?q:[q];if(r==="css"||a.gecko||a.opera){e[r].push({urls:[].concat(q),callback:s,obj:m,scope:t})}else{for(n=0,o=q.length;n<o;++n){e[r].push({urls:[q[n]],callback:n===o-1?s:null,obj:m,scope:t})}}}if(b[r]||!(k=b[r]=e[r].shift())){return}g=g||f.getElementsByTagName("head")[0];q=k.urls;for(n=0,o=q.length;n<o;++n){d=q[n];if(r==="css"){l=j("link",{href:d,rel:"stylesheet",type:"text/css"})}else{l=j("script",{src:d})}if(a.ie){l.onreadystatechange=function(){var p=this.readyState;if(p==="loaded"||p==="complete"){this.onreadystatechange=null;h(r)}}}else{if(r==="css"&&(a.gecko||a.webkit)){setTimeout(function(){h(r)},50*o)}else{l.onload=l.onerror=function(){h(r)}}}g.appendChild(l)}}return{css:function(l,m,k,d){i("css",l,m,k,d)},js:function(l,m,k,d){i("js",l,m,k,d)}}}();
	
	$('input[name=q]').focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	
	$('#search input[type=submit]').click(function(event){
		event.preventDefault();
		search_submit();
	});
	
	$('input[name=q]').keypress(function(event){
		if(event.which == 13){
			event.preventDefault();
			search_submit();
       	}
	});
		
	if($('#cycle').length != 0){
		LazyLoad.js(['/includes/js/jquery.cycle.all.min.js'], function () {
			$.fn.cycle.transitions.scrollVertUp=function($cont,$slides,opts){
				$cont.css("overflow","hidden");
				opts.before.push(function(curr,next,opts,fwd){
					$.fn.cycle.commonReset(curr,next,opts);
					opts.cssBefore.top=fwd?(next.cycleH-1):(1-next.cycleH);
					opts.animOut.top=fwd?-curr.cycleH:curr.cycleH;
				});
				opts.cssFirst={top:0};
				opts.cssBefore={left:0};
				opts.animIn={top:0};
				opts.animOut={left:0};
			};
			$("#cycle").cycle({
				fx: 'scrollVertUp',
				speed: 600,
				timeout: 0,
				next: '#next',
				prev: '#prev'
			});
		});
	}

});

function stripe_tweets(){
	$("div.tweet:odd").addClass("odd");
	$("div.tweet:even").addClass("even");
}

function search_submit(){
	var sstring = $('input[name=q]').val(),
		data = 'search='+ sstring;
	if(sstring) {
		$.ajax({
			type: "POST",
			url: "/fetchsr.php",
			data: data,
			beforeSend: function(html) {
				$("#results").html('');
				$("html").css({'height':'100%'});
				$("body").css({'height':'100%'});
				$("#bgoverlay").show();
				$("#searchresults").show();
				$(".word").html(sstring);
			},
			success: function(html){
				$("#results").show();
				$("#results").append(html);
			}
		});
	}
	return false;
}

var stype = {
	src: '/includes/js/avenir-55roman.swf'
};
sIFR.activate(stype);
sIFR.replace(stype, {
	selector: '#content div.left h2',
	css: [
		'.sIFR-root {color:#ed1b2d; background-color: #ffffff;}'
	],
	wmode: 'transparent'
});