if(top!=self){top.location.href=self.location.href;}
var $j=jQuery.noConflict();Date.prototype.addYear=function(){this.setTime(this.getTime()+(365*24*60*60*1000));return this;};

var JPGMAG_ADS={
	move:function(a){
		/*
			a=array -> [id_old1|id_new1,id_old2|id_new2... ]
			-call ads.move from anywhere (no ties to a parent or child element)
			-call move in "batch mode" (multiple ads and boxes in a single call)
		*/
		var alen=a.length;var o,n,oo,nn;

		for(var i=0; i<alen; i++){
			oo = a[i].split('|')[0];
			nn = a[i].split('|')[1];

			o = ($j('#'+oo).length) ? $j('#'+oo) : null;
			n = ($j('#'+nn).length) ? $j('#'+nn) : null;
			if(o && n){
                var real = $j('#' + nn)[0];$j('#' + oo).contents().each(function(){real.appendChild(this);});
				// $j('#' + oo).children().not('script').appendTo('#' + nn);
			}
		}
	}
};

var JPGMAG={
	cookie:{
		set:function(n,v,e){document.cookie=n+'='+escape(v)+((e)?';expires='+e.toGMTString():'')+';domain=jpgmag.com;path=/';},
		get:function(n){n=n+'=';var c=document.cookie,t=c.indexOf(n);if(t==-1){return '';}var v=c.indexOf(';',t+n.length);if(v==-1){v=c.length;}return unescape(c.substring(t+n.length,v));}
	},
	dropnav:function(){location.href=this.value;},
	lb2br:function(t){t=t.replace(/\r\n/g,'<br/>');t=t.replace(/\n/g,'<br/>');t=t.replace(/\r/g,'<br/>');return t;},
	logIn:function(){
		$j('#meta').append('<div id="loginform" class="login"><form action="/auth/login" method="post"><label for="user">Username </label><input type="text" class="input" id="user" name="user" size="14"/><label for="password">Password </label><input type="password" class="input" id="password" name="password" size="14"/><input type="hidden" name="process" value="TRUE"/><input type="submit" value="Log in" class="submit"/><a href="#" id="cancel">Cancel</a></form></div>');
		$j('#cancel').click(function(){$j('#loginform').fadeOut('normal',function(){$j('#loginform').remove();});return false;});
		$j('#loginform').hide().fadeIn('normal',function(){$j('#user').focus();});
		return false;
	},
	faqToggle:function(){$j(this).parents('li').children().not('h4').toggle();},
    stopEvent:function(e){
        e.stopPropagation();e.preventDefault();
    },
    safeConfirm:function(){
        if($j(this).attr('checked')){var ok=confirm('Select this option if your photo may be considered inappropriate for workplace or family viewing.');if(!ok){$j(this).attr('checked',false);}}
    }
};

$j(function(){
	$j('.dropnav').change(JPGMAG.dropnav);
	$j('.metalog a').click(JPGMAG.logIn);
	$j('.questions li').children().not('h4').hide();
	$j('.questions h4').wrapInner('<span></span>').click(JPGMAG.faqToggle);
	$j('#navsq,#searchInput').focus(function(){$j(this).val('').css('color','#000').unbind('focus');});
	$j('#addphotodets #isSafe').change(JPGMAG.safeConfirm);
    $j('body').css('background-color','#333');
});