var shareLink = "";

function shareThis(thisObj) {
	//top.location.href=shareLink;	
	thisLocation = top.location.href;
	if(thisLocation == 'http://www.seymoursimon.com/index.php') {
		thisLocation = 'http://www.seymoursimon.com/index.php/home/';	
	}
	trimmedLocation = thisLocation.substring(38);
	if(trimmedLocation == "blog/") {
		trimmedLocation = "blog_redirect/";
	}

	//top.location.href="http://www.seymoursimon.com/index.php/site/tell-a-friend/"+thisLocation.substring(38);
	thisObj.href="http://www.seymoursimon.com/index.php/site/tell-a-friend/"+trimmedLocation;
	$(thisObj).modal({width:419, height:337}).open();
	//$.modal("<div><h1>SimpleModal</h1></div>", {width:419, height:337}).open();
	//$.modal("<div><h1>SimpleModal</h1></div>");


}

jQuery.fn.vvAccordion = function(_options){

	var _options = jQuery.extend({

		el: '> li',

		head: 'a.opener',

		content: 'div.ac-content',

		active: 'selected',

		event: 'click',

		onBeforeAply: null,

		onChangeStart: null,

		onChange: null,

		duration: 400

	},_options);

	return this.each(function(){

		var _this = this;

		var _t = null;

		_this.duration = _options.duration;

		_this.list = $(_options.el, _this);

		_this.list.each(function(i){

			this.opener = $(_options.head, this);

			this.slider = $(_options.content, this);

			this.width = $(this).width();

			this.height = $(this).height();

			if($(this).hasClass(_options.active)){

				_this.active = this;

			};

			this.index = i;

		});

		if(!_this.active) _this.active = _this.list[0];

		if(jQuery.isFunction(_options.onBeforeAply)){

			_options.onBeforeAply.apply(_this);

		};

		_this.list.not(_this.active).each(function(){

			$(this).css({width: '0px'});

		});

		_this.list.each(function(){

			var next = this;

			this.opener.bind(_options.event, function(){

				if(jQuery.isFunction(_options.onChangeStart)){

					_options.onChangeStart.apply(_this.active);

				};

				if(_t) clearTimeout(_t);

				_t = setTimeout(function(){

					_this.curent = next;

					$(next).animate({width: next.width},{duration: _options.duration,

					step:function(i, curObj){

						var _p = curObj.now/curObj.end;

						if(_this.active !== next){

							var _thisValue = 0;

							if (curObj.prop == 'height') {

								_thisValue = _this.active.height - (_this.active.height * _p);

							}else{

								_thisValue = curObj.end - curObj.now;

							}

							eval('$(_this.active).css({'+curObj.prop+':'+_thisValue+'})');

						}

					},

					complete: function(){

						$(_this.active).removeClass(_options.active);

						$(_this.active).css({width: 0});

						_this.active = next;

						$(_this.active).addClass(_options.active);

						$(_this.active).css({width: _this.active.width});

						if(jQuery.isFunction(_options.onChange)){

							_options.onChange.apply(_this.active);

						};

						_this.curent = false;

					}});

				},150);

				return false;

			});

		});

	});

}





$(window).bind('load',function(){

	$('ul.accordion').vvAccordion({

		el: '> li',

		head: 'a.opener',

		content: 'div.ac-content',

		activeClass: 'selected',

		onBeforeAply: function(_this){

			$('.carusel').each(function(i){

				$(this).galleryScroll({

					btPrev: 'a.btn-prev',

					btNext: 'a.btn-next',

					holderList: 'div.g-hold',

					scrollElParent: 'ul',

					scrollEl: 'li',

					onNumCreate: function(){

						this.hide();

					},

					slideNum: 'div.galnav'+(i+1),

					duration : 1000

				});

			});

			$('div.galnav1').show();

		},

		onChangeStart: function(){

			$('div.galnav'+(this.index+1)).fadeOut();

		},

		onChange: function(){

			$('div.galnav'+(this.index+1)).fadeIn();

		},

		duration: 400

	});

});

var jokeCount = 0;

function toggleJoke() {
	$('#joke_q').slideToggle();
	$('#joke_a').slideToggle();
	if(jokeCount==0) {
		$('#btn_text').html('See Again');	
		jokeCount=1;
	} else {
		$('#btn_text').html('What’s the answer?');	
		jokeCount=0;
	}
}
var jokeCountB = new Array;
jokeCountB[1] = 0;
jokeCountB[2] = 0;
jokeCountB[3] = 0;
jokeCountB[4] = 0;
jokeCountB[5] = 0;
jokeCountB[6] = 0;
jokeCountB[7] = 0;
jokeCountB[8] = 0;
jokeCountB[9] = 0;
jokeCountB[0] = 0;
jokeCountB[11] = 0;
jokeCountB[12] = 0;
jokeCountB[13] = 0;
jokeCountB[14] = 0;
jokeCountB[15] = 0;

function toggleJokeB(question,answer,count) {
	$('#'+question).slideToggle();
	$('#'+answer).slideToggle();
	if(jokeCountB[parseFloat(count)]==0) {
		$('#btn_text_'+count).html('See Again');	
		jokeCountB[parseFloat(count)]=1;
	} else {
		$('#btn_text_'+count).html('What’s the answer?');	
		jokeCountB[parseFloat(count)]=0;
	}
}

function showTerm(not) {
		$("#show-another").html('<img style="margin:0 auto;" src="/images/spinner2.gif" alt="">');
		$('#science-box').load('/index.php/site/_science-box/'+not);
}

function setEducator(which) {
	//alert(which);
	if(which=="Yes") {
		$('#educator-fields').css("display","block");
		$('#school-email').val('');
		$('#group-id').val('7');
	} else {
		$('#educator-fields').css("display","none");
		$('#school-email').val('n/a');
		$('#group-id').val('5');
	}
	//alert($('#group-id').val());
}

var eduLocation = "tg";
function showEdu(which, detail) {
	if(which=="sc") {
		$('#scImg').attr("src", 'images/btn-sample-chaps-on.gif');	
		$('#piImg').attr("src", 'images/btn-project-ideas-off.gif');
		$('#tgImg').attr("src", 'images/btn-teacher-guides-off.gif');
		$('#common-content').load('/index.php/site/_sample-chapters/'+detail);
	} else if(which=="tg") {
		$('#scImg').attr("src", 'images/btn-sample-chaps-off.gif');	
		$('#piImg').attr("src", 'images/btn-project-ideas-off.gif');
		$('#tgImg').attr("src", 'images/btn-teacher-guides-on.gif');
		$('#common-content').load('/index.php/site/_teacher-guides/'+detail);
	} else {
		$('#scImg').attr("src", 'images/btn-sample-chaps-off.gif');	
		$('#piImg').attr("src", 'images/btn-project-ideas-on.gif');
		$('#tgImg').attr("src", 'images/btn-teacher-guides-off.gif');
		$('#common-content').load('/index.php/site/_project-ideas/'+detail);
	}
}

function showUpload() {
	$('#upload-agree').css("display","none");
	$('#upload-box').css("display","block");
}
