/*String.prototype.reverse = function(){
	splitext = this.split("");
	revertext = splitext.reverse();
	reversed = revertext.join("");
	return reversed;
}
*/
function URLDecode(psEncodeString) 
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " ")); 
}


var current = false;
var logged_in = false;


function refresh(loc) {
	sURL = unescape(window.location.pathname)
	if(loc != 'refresh') {
		sURL = loc
	}
    window.location.href = sURL;
}

function lockLogin() {
	var f = $('LoginForm');
	if (!f) return;
	$A(f.elements).each(function(i,index){
	  i.disabled = true;
	});
	Element.setOpacity(f, 0.5);
	f.old_onsubmit = f.onsubmit;
	f.onsubmit = function() { return false; }
	return false;
}

function unlockLogin() {
	var f = $('LoginForm');
	if (!f) return;
	$A(f.elements).each(function(i){
		i.disabled = false;
	});
	Element.setOpacity(f, 1.0);
	if (typeof f.old_onsubmit == 'function') f.onsubmit = f.old_onsubmit;
	return false;
}


function loadingButton(targ) {
	$(targ).addClass('loading');
}

var write_data = new Array();
var current_write_data = "";
var ii = 0;
var spot = 0;

var page_loaded = false


var loadAllAds_dummy = 0;


function installOpenSearch(){
	if((typeof window.external=="object")&&((typeof window.external.AddSearchProvider=="unknown")||(typeof window.external.AddSearchProvider=="function"))) { 
		window.external.AddSearchProvider("http://www.cutoutandkeep.net/opensearch.xml");
	} else {
		alert("This plugin requires a browser that supports OpenSearch.");
	}
}



var num_r=0;

function addRecipient() {
	if($('#user_to').val()=="") { return }
	num_r++;
	var x = $('#recipients').append(
			'<div id="recipient_'+num_r+'"><div><input type="hidden" name="recipients[]" value="'+$('#user_to :selected').text()+'" />'+
			$('#user_to :selected').text()+
			'</div><a href="#" onclick="removeRecipient('+num_r+','+$('#user_to').val()+'); return false;"><img src="/images/layout/token_close.gif" height="18" width="18"/></a></div>');
	
	setRecipientCount()
	$('#user_to :selected').attr('disabled',true)
	$('#user_to').val("")
}
function removeRecipient(x, n) {
	$("#recipient_"+x).remove();
	$('#user_to :selected').attr('disabled',true)
	
	//$('#user_to').options[n].disabled = false
	num_r--
	setRecipientCount()
}

function setRecipientCount() {
	if (num_r>1) 	{ $('#count_recipients').html(num_r+' recipients') }
	if (num_r==1) 	{ $('#count_recipients').html('1 recipient'); $('#recipient_info').hide(); }
	if (num_r==0) 	{ $('#count_recipients').html('');	$('#recipient_info').show();	}
}

function checkForm() {
	if(i==0) {
		alert('You haven\'t chosen any recipients for this message!')
		return false;
	}
	return true;
}

function videoUpload(id) {
  if ($('file_'+id).value) {
	$('uploading_'+id).show();
	setTimeout( $('form_'+id).hide(), 2000)
	    return true;
  }
  $('error_'+id).show();
  return false;
}







function resizeImage(node) {
	img = $(node).children('a').children().eq(0)
	a = $(node).children('a')
	h = $(img).attr('height') * 1;
	w = (120/h) * ($(img).attr('width') * 1);
	img.css('height', 120)
	img.css('width', w)
	img.css('margin', 0)


	$(node).css('margin', 0)
		
}

function resetImage(node) {
	img = $(node).children('a').children().eq(0);
	img.css('height', 'auto')
	img.css('width', 'auto')
	pt = (360 - img.attr('height'))
	img.css('margin', pt+'px 0 0 0');
}


function setCategory(list, order, instance, value) {
	$('#project_category_id').val(value);
}



function switchChecked(z) {
	if(this.checked==true) {
		$("#"+this.id+"_children").show();
	} else {
		$("#"+this.id+"_children").hide();
	}
}


function superstar(s,i,n) {
	$('.superstar_'+s).hide()
	$('.superstar_'+s+'.project_'+i).show()
	$('#superstar_arrow_'+s).css('left', i*(390/n))
	$('#superstar_arrow_'+s).css('width', (390/n))
}


function toggleSitemap() {
	$("#site-map").slideToggle();
}




(function ($) {

$.fn.hint = function (blurClass) {
    if (!blurClass) blurClass = 'blur';
    
    return this.each(function () {
        var $input = $(this),
            title = $input.attr('title'),
            $form = $(this.form),
            $win = $(window);

        function remove() {
            if (this.value === title && $input.hasClass(blurClass)) {
                $input.val('').removeClass(blurClass);
            }
        }

        // only apply logic if the element has the attribute
        if (title) { 
            // on blur, set value to title attr if text is blank
            $input.blur(function () {
                if (this.value === '') {
                    $input.val(title).addClass(blurClass);
                }
            }).focus(remove).blur(); // now change all inputs to title
            
            // clear the pre-defined text when form is submitted
            $form.submit(remove);
            $win.unload(remove); // handles Firefox's autocomplete
        }
    });
};

})(jQuery);



function setImages() {
	images = $('#projectimages li a.bump');
}

function nextImage() {	
	setImages()
	
	// current left slide to center and hide
	bumpHide(images.last(), function() { $("#projectimages li a").last().hide(); })
	// current main slide to left, callback bump to end
	bumpLeft(images.eq(0), function() { $("#projectimages li").first().remove().appendTo($("#projectimages")) }, null)
	
	// current right slide to main
	bumpCenter(images.eq(1))
	
	// slide out hidden right
	resetBump(images.eq(2))
	bumpRight(images.eq(2), null, null)
	return false;
}



function prevImage() {
	setImages()
	
	// current right slide to center and hide
	bumpHide(images.eq(1), function() { $("#projectimages li a.bump").eq(2).hide(); })
	
	// current main slide to right
	bumpRight(images.first(), function() { $("#projectimages li").last().remove().prependTo($("#projectimages")) }, null)
	
	// current left slide to main, callback bump to start
	bumpCenter(images.last())

	// slide out hidden left
	resetBump(images.eq(images.size()-2))
	bumpLeft(images.eq(images.size()-2), null, null)
	return false
}

function initBump() {
		setImages()
		$.each($('#projectimages li a.bump img'), function(i,node) {
			img_sizes[$(node).attr('id')] = {'width':$(node).width(), 'height':$(node).height() }
		})
}
function setupBump() {
	setImages()
	
	images.hide();
	
	bumpCenter(images.eq(0))
	bumpLeft(images.last())
	bumpRight(images.eq(1))
}

function bumpRight(i, callback, zindex) {
	try {
	
	i.show();
	img = i.children('img').eq(0)
	d = imageSize($(img).attr('id'))
	h = d['height']
	w =  (120/h) * d['width']
	i.stop().animate({'left':'100%', 'bottom':'40%'}, 500, 'swing', function() {
		$(this).parent().css('z-index',50)
	}).children('img').stop().animate({'margin-left':'-100%',  'height':140, 'width':w }, 500, 'swing', callback)
	} catch(err) {
		console.log("Right broke")
		
		console.log(err)
	}
}

function imageSize(id) {
	return img_sizes[id]
}

function resetBump(i) {
	try {
	
	setImages()
	
	i.show();
	img = i.children('img').eq(0)
	d = imageSize($(img).attr('id'))
	h = d['height']
	w =  (120/h) * d['width']
	i.css('left','50%')
	i.parent().css('z-index',2)
	img.css('margin-left','-50%')
	img.height(140)
	img.width(w)
	} catch(err) {
		console.log("Reset broke")
		
		console.log(err)
		
	}
}

function bumpHide(i, callback) {
	try {
	
	img = i.children('img').eq(0)
	d = img_sizes[$(img).attr('id')] //$.data(img[0], "size")
	h = d['height']
	w =  (120/h) * d['width']
	i.parent().css('z-index',10)
	i.stop().animate({'left':'50%'}, 500, null, callback)
	} catch(err) {
		console.log("Hide broke")
		
	}
}


function bumpCenter(i) {
	try {
	i.show();
	img = i.children('img').eq(0)
	d = imageSize($(img).attr('id'))
	i.parent().css('z-index',150)
	i.stop().animate({'left':'50%', 'bottom':'0px'}, 500, 'swing').children('img').stop().animate({'margin-left':'-50%', 'height':d['height'], 'width':d['width'] }, 500, 'swing')
	} catch(err) {
		console.log("center broke")
		
		console.log(err)
		
	}
}

function bumpLeft(i, callback, zindex) {
	try {
	
	i.show();
	img = i.children('img').eq(0)
	d = imageSize($(img).attr('id'))
	h = d['height']
	w =  (120/h) * d['width']
	i.css('-webkit-transform', 'rotateY(45deg)')
	i.animate({'left':'0%', 'bottom':'40%'}, 500, 'swing', function() {
		$(this).parent().css('z-index',50)
	}).children('img').stop().animate({'margin-left':'0%', 'height':140, 'width':w}, 500, 'swing', callback)
	} catch(err) {
		console.log("Left broke")
		console.log(err)
		
	}
}




function loginToFacebook() {
    window.location = '/facebook/auth?return_to=' + window.location.href;
};


/* jQuery Carousel 0.9.2
Copyright 2008-2009 Thomas Lanciaux and Pierre Bertet.
This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/
;(function($){$.fn.carousel=function(params){var params=$.extend({direction:"horizontal",loop:false,dispItems:1,pagination:false,paginationPosition:"inside",nextBtn:'<a role="button">Next</a>',prevBtn:'<a role="button">Previous</a>',btnsPosition:"inside",nextBtnInsert:"appendTo",prevBtnInsert:"prependTo",nextBtnInsertFn:false,prevBtnInsertFn:false,autoSlide:false,autoSlideInterval:3000,delayAutoSlide:false,combinedClasses:false,effect:"slide",slideEasing:"swing",animSpeed:"normal",equalWidths:"true",verticalMargin:0,callback:function(){},useAddress:false,adressIdentifier:"carousel",tabLabel:function(tabNum){return tabNum;}},params);if(params.btnsPosition=="outside"){params.prevBtnInsert="insertBefore";params.nextBtnInsert="insertAfter";}
params.delayAutoSlide=params.delayAutoSlide||params.autoSlideInterval;return this.each(function(){var env={$elts:{},params:params,launchOnLoad:[]};env.$elts.carousel=$(this).addClass("js");env.$elts.content=$(this).children().css({position:"absolute","top":0});env.$elts.wrap=env.$elts.content.wrap('<div class="carousel-wrap"></div>').parent().css({overflow:"hidden",position:"relative"});env.steps={first:0,count:env.$elts.content.children().length};env.steps.last=env.steps.count-1;if($.isFunction(env.params.prevBtnInsertFn)){env.$elts.prevBtn=env.params.prevBtnInsertFn(env.$elts);}else{env.$elts.prevBtn=$(params.prevBtn)[params.prevBtnInsert](env.$elts.carousel);}
if($.isFunction(env.params.nextBtnInsertFn)){env.$elts.nextBtn=env.params.nextBtnInsertFn(env.$elts);}else{env.$elts.nextBtn=$(params.nextBtn)[params.nextBtnInsert](env.$elts.carousel);}
env.$elts.nextBtn.addClass("carousel-control next carousel-next");env.$elts.prevBtn.addClass("carousel-control previous carousel-previous");initButtonsEvents(env);if(env.params.pagination){initPagination(env);}
initAddress(env);$(function(){var $items=env.$elts.content.children();var $maxHeight=0;$items.each(function(){$item=$(this);$itemHeight=$item.outerHeight();if($itemHeight>$maxHeight){$maxHeight=$itemHeight;}});if(env.params.verticalMargin>0){$maxHeight=$maxHeight+env.params.verticalMargin;}
$items.height($maxHeight);var $firstItem=env.$elts.content.children(":first");env.itemWidth=$firstItem.outerWidth();if(params.direction=="vertical"){env.contentWidth=env.itemWidth;}else{if(params.equalWidths){env.contentWidth=env.itemWidth*env.steps.count;}else{env.contentWidth=(function(){var totalWidth=0;env.$elts.content.children().each(function(){totalWidth+=$(this).outerWidth();});return totalWidth;})();}}
env.$elts.content.width(env.contentWidth);env.itemHeight=$maxHeight;if(params.direction=="vertical"){env.$elts.content.css({height:env.itemHeight*env.steps.count+"px"});env.$elts.content.parent().css({height:env.itemHeight*env.params.dispItems+"px"});}else{env.$elts.content.parent().css({height:env.itemHeight+"px"});}
updateButtonsState(env);$.each(env.launchOnLoad,function(i,fn){fn();});if(env.params.autoSlide){window.setTimeout(function(){env.autoSlideInterval=window.setInterval(function(){goToStep(env,getRelativeStep(env,"next"));},env.params.autoSlideInterval);},env.params.delayAutoSlide);}});});};function initButtonsEvents(env){env.$elts.nextBtn.add(env.$elts.prevBtn).bind("enable",function(){var $this=$(this).unbind("click").bind("click",function(){goToStep(env,getRelativeStep(env,($this.is(".next")?"next":"prev")));stopAutoSlide(env);}).removeClass("disabled");if(env.params.combinedClasses){$this.removeClass("next-disabled previous-disabled");}}).bind("disable",function(){var $this=$(this).unbind("click").addClass("disabled");if(env.params.combinedClasses){if($this.is(".next")){$this.addClass("next-disabled");}else if($this.is(".previous")){$this.addClass("previous-disabled");}}}).hover(function(){$(this).toggleClass("hover");});};function initPagination(env){env.$elts.pagination=$('<div class="center-wrap"><div class="carousel-pagination"><p></p></div></div>')[((env.params.paginationPosition=="outside")?"insertAfter":"appendTo")](env.$elts.carousel).find("p");env.$elts.paginationBtns=$([]);env.$elts.content.find("li").each(function(i){if(i%env.params.dispItems==0){env.$elts.paginationBtns=env.$elts.paginationBtns.add($('<a role="button"><span>'+env.params.tabLabel(env.$elts.paginationBtns.length+1)+'</span></a>').data("firstStep",i));}});env.$elts.paginationBtns.each(function(){$(this).appendTo(env.$elts.pagination);});env.$elts.paginationBtns.slice(0,1).addClass("active");env.launchOnLoad.push(function(){env.$elts.paginationBtns.click(function(e){goToStep(env,$(this).data("firstStep"));stopAutoSlide(env);});});};function initAddress(env){if(env.params.useAddress&&$.isFunction($.fn.address)){$.address.init(function(e){var pathNames=$.address.pathNames();if(pathNames[0]===env.params.adressIdentifier&&!!pathNames[1]){goToStep(env,pathNames[1]-1);}else{$.address.value('/'+env.params.adressIdentifier+'/1');}}).change(function(e){var pathNames=$.address.pathNames();if(pathNames[0]===env.params.adressIdentifier&&!!pathNames[1]){goToStep(env,pathNames[1]-1);}});}else{env.params.useAddress=false;}};function goToStep(env,step){env.params.callback(step);transition(env,step);env.steps.first=step;updateButtonsState(env);if(env.params.useAddress){$.address.value('/'+env.params.adressIdentifier+'/'+(step+1));}};function getRelativeStep(env,position){if(position=="prev"){if((env.steps.first-env.params.dispItems)>=0){return env.steps.first-env.params.dispItems;}else{return((env.params.loop)?(env.steps.count-env.params.dispItems):false);}}else if(position=="next"){if((env.steps.first+env.params.dispItems)<env.steps.count){return env.steps.first+env.params.dispItems;}else{return((env.params.loop)?0:false);}}};function transition(env,step){switch(env.params.effect){case"no":if(env.params.direction=="vertical"){env.$elts.content.css("top",-(env.itemHeight*step)+"px");}else{env.$elts.content.css("left",-(env.itemWidth*step)+"px");}
break;case"fade":if(env.params.direction=="vertical"){env.$elts.content.hide().css("top",-(env.itemHeight*step)+"px").fadeIn(env.params.animSpeed);}else{env.$elts.content.hide().css("left",-(env.itemWidth*step)+"px").fadeIn(env.params.animSpeed);}
break;default:if(env.params.direction=="vertical"){env.$elts.content.stop().animate({top:-(env.itemHeight*step)+"px"},env.params.animSpeed,env.params.slideEasing);}else{env.$elts.content.stop().animate({left:-(env.itemWidth*step)+"px"},env.params.animSpeed,env.params.slideEasing);}
break;}};function updateButtonsState(env){if(getRelativeStep(env,"prev")!==false){env.$elts.prevBtn.trigger("enable");}else{env.$elts.prevBtn.trigger("disable");}
if(getRelativeStep(env,"next")!==false){env.$elts.nextBtn.trigger("enable");}else{env.$elts.nextBtn.trigger("disable");}
if(env.params.pagination){env.$elts.paginationBtns.removeClass("active").filter(function(){return($(this).data("firstStep")==env.steps.first)}).addClass("active");}};function stopAutoSlide(env){if(!!env.autoSlideInterval){window.clearInterval(env.autoSlideInterval);}};})(jQuery);