var $ = jQuery.noConflict();
var timeout;
$(document).ready(function() {
	/* colorbox */
	if($('a.colorbox.imagefield').length) {
		$('a.colorbox.imagefield').append('<span class="enlarge">+ click to enlarge</span>');
	}
	/* client form */
	if($('.add-photo').length) orderPhotos();
	/* faq expandables */
	if($('#block-views-faq-block-1').length) {
		$('#block-views-faq-block-1 .views-field-title a').first().addClass('active');
		general = {buttonClass:'#block-views-faq-block-1 .views-field-title a', speed:12, expandAllBool:false} 
		var generalExpandables = new Expandable(general);
	}
	if($('#block-views-faq-block-2').length) {
		$('#block-views-faq-block-2 .views-field-title a').first().addClass('active');
		wedding = {buttonClass:'#block-views-faq-block-2 .views-field-title a', speed:12, expandAllBool:false} 
		var weddingExpandables = new Expandable(wedding);
	}
	// disable right click
	if(!$('body').hasClass('admin-nw')) {
		$(this).bind('contextmenu', function(e) {
			e.preventDefault();
		});
	}
	resetFields();
});

$(window).load(function() {
	$(window).resize(function() {
		clearTimeout(timeout);
		timeout = setTimeout(footerHeight, 100);
	});
	footerHeight();
});

/* rotatorInit - initializes all faders and rotators */
function rotatorInit() {
	if($('.front #block-system-main .views-row').length) {
		var constants = {container:'#block-system-main .view-content', item:'.views-row', opacitySpeed:125, intervalSpeed:125, pageDots:true};
		var fade = new tFade(constants);
	}
	/* page fader */
	if($('#hero img').length > 1) {
		var constants = {container:'#hero', item:'img', opacitySpeed:125, intervalSpeed:125, pageDots:true};
		var fade = new tFade(constants);
	}
	/* gallery scroller */
	if($('.node-gallery .view-gallery .views-row').length) {
		var constants = {container:'.view-gallery .view-content', btnLeft:'#btn-scroll-left', btnRight:'#btn-scroll-right', itemClass:'.views-row', pageDots:false, gallery:true, slideNumber:6, numberShown:6, speed:400};
		var scroll = new dScroll(constants);
		timeout = setTimeout(footerHeight, 800);
	}
}

/* resetFields - removes form input value on mouse click, returns value on blue */
function resetFields() {
	/*var inputArray = $('input.form-text');
	for(i=0; i<inputArray.length; i++){
		if(inputArray[i].type == 'text') {
			inputArray[i].onfocus = function() {
				if (this.value == this.defaultValue) this.value = '';
			}
			inputArray[i].onblur = function() {
				if(this.value == '') this.value = this.defaultValue;
			}
		}
	}*/
}

/* footerHeight - updates the footer height so the pattern will always be at the bottom of the users browser */
function footerHeight() {
	var containerHeight = $('#container').height();
	var footer = $('#footer');
	var footerPadding = parseInt($('#footer-wrapper').css('padding-bottom')) + parseInt($('#footer-wrapper').css('padding-top'));
	var footerHeight = $('#footer').height() + parseInt($('#footer').css('margin-bottom'));
	var bg = $('#bg');
	var height = parseInt($(window).height());
	if(containerHeight + footerHeight + footerPadding < height) {
		footer.css('height', height - (containerHeight + footerPadding + parseInt(footer.css('margin-bottom'))) + 'px');
		bg.css('height', containerHeight + 'px');
	} else {
		footer.css('height', 'auto');
		bg.css('height', containerHeight + 'px');
	}
}

/* orderPhotos - provides the form addition functionality for the client gallery form */
function orderPhotos() {		
	var chosen = $('#chosen-photos');
	var orderSave = $('#edit-submitted-order');
	if(orderSave.attr('value')) {
		chosen.html(orderSave.attr('value'));
	}
	$('.add-photo').click(function() {
		var photoObj = $(this).parent().parent().parent().parent();
		var order = $('#chosen-photos .order');
		var rows = $('#chosen-photos .order .row');
		var subtotal = $('#order-subtotal .subtotal');
		var tax = $('#order-tax .tax');
		var total = $('#order-total .total');
		var title = photoObj.find('.views-field-counter span').html();
		var quantity = photoObj.find('.views-field-php input').attr('value');
		var size = photoObj.find('.views-field-php option:selected').html();
		var cost = size.replace(/.*\(\$/, '').replace(/\)/, '');
		var taxTotal = round(quantity * cost * .0975);
		var match = false;
		if(!quantity) {
			alert('You must enter a quantity.');
			return false;
		}
		for(i=0; i<rows.length; i++) {
			if($(rows[i]).children('.title').html() == title+': ' && $(rows[i]).children('.size').html() == size) match = true;
		}
		if(match) {
			alert('You have already added this photo/size combination. Please remove your previous choice if you want to re-add the photo.');
		} else {
			if(!rows || rows.length == 0) chosen.find('.count span').html(rows.length + 1 + ' photo');
			else chosen.find('.count span').html(rows.length + 1 + ' photos');
			subtotal.html(parseFloat(round(subtotal.html()) + round(quantity * cost)));
			tax.html(round(round(parseFloat(tax.html())) + taxTotal));
			total.html(round(round(parseFloat(total.html())) + round(quantity * cost) + taxTotal));
			order.append('<div class="row row-'+rows.length+'"><span class="title">'+title+': </span><span class="quantity">'+quantity+'</span> - <span class="size">'+size+'</span><a href="javascript:removePhoto('+rows.length+');" title="Remove" class="remove-photo">Remove</a></div>');
			orderSave.attr('value', chosen.html());
		}
		return false;
	});
}

/* removePhoto - removes photos from the photo order form */
function removePhoto(row) {
	var count = $('#chosen-photos .order .row').length;
	var el = $('#chosen-photos .order .row-'+row);
	var quantity = el.find('.quantity').html();
	var cost = el.find('.size').html().replace(/.*\(\$/, '').replace(/\)/, '');
	var subtotal = $('#order-subtotal .subtotal');
	var tax = $('#order-tax .tax');
	var taxTotal = round(quantity * cost * .0975);
	var total = $('#order-total .total');
	subtotal.html(parseFloat(subtotal.html()) - quantity * cost);
	tax.html(round(round(parseFloat(tax.html())) - taxTotal));
	total.html(round(round(parseFloat(total.html())) - taxTotal - round(cost * quantity)));
	el.remove();
	if(count == 2) $('#chosen-photos').find('.count span').html(count - 1 + ' photo');
	else $('#chosen-photos').find('.count span').html(count - 1 + ' photos');
	$('#edit-submitted-order').attr('value', $('#chosen-photos').html());
	return false;
}

/* round - round numbers to two decimal places */
function round(num) {
	return Math.round(num*100)/100;
};
/* Begin: TragicMedia.com - jQuery Fade Script
/* created 1/10 by Rich Rudzinski
/*------------------------------------------*/
	// opacitySpeed is how fast the item will fade in/out, the intervalSpeed is how often the items will change (in milliseconds), opacitySpeed is in reverse, the lower the number the slower the fade
	// var constants = {container:'#fadeCont', item:'.item', opacitySpeed:60, intervalSpeed:100, pageDots:true};
	// var fade = new tFade(constants);
function tFade(values) {
	var obj = this;
	var img;
	this.animate = false;
	this.values = values;
	// set default values if not filled in
	this.container = $(values.container);
	if(this.values.opacitySpeed == undefined) this.values.opacitySpeed = 60;
	this.values.opacitySpeed = this.values.opacitySpeed * 10;
	if(this.values.intervalSpeed == undefined) this.values.intervalSpeed = 100;
	this.values.intervalSpeed = this.values.intervalSpeed * 100;
	this.values.pageDots = (values.pageDots == undefined) ? false : values.pageDots;
	this.fadeItems = $(this.values.container+' '+values.item);
	if(this.fadeItems[0].tagName == 'IMG' || this.fadeItems.find('img').length) {
		if(this.fadeItems[0].tagName == 'IMG') img = this.fadeItems.first();
		else img = this.fadeItems.find('img').first();
		if (img[0].complete || img[0].readyState === 4) {
			obj.initCss();
		} else {
			img.bind('load', function(){	
				obj.initCss();
			});
		}
	} else {
		this.initCss();
	}
}	
// initial CSS settings
tFade.prototype.initCss = function() {
	this.container.css({
		'width':this.fadeItems[0].offsetWidth + 'px',
		'height':this.fadeItems[0].offsetHeight + 'px',
		'overflow':'hidden',
		'position':'relative'
	});
	this.fadeItems.css({
		'width':this.fadeItems[0].offsetWidth + 'px',
		'height':this.fadeItems[0].offsetHeight + 'px',
		'overflow':'hidden',
		'position':'absolute',
		'top':this.container.css('padding-top'),
		'left':0,
		'opacity':1
	});
	this.createFade();
}
// Sets container width, shifts elements if startPosition != 1			
tFade.prototype.orderItems = function() {
	this.fadeItems = $(this.values.container+' '+this.values.item);
	for(var i=0; i<this.fadeItems.length; i++) {
		$(this.fadeItems[i]).css({
			'zIndex':this.fadeItems.length - i,
			'opacity':1
		});
	}
}
// Creates the fade animation
tFade.prototype.createFade = function() {
	var obj = this;
	this.currItem = 0;
	this.orderItems();
	this.fadeInterval = setInterval(function() { 
		obj.animate = true;
		$(obj.fadeItems[0]).animate({
			opacity: 0
		}, obj.values.opacitySpeed, function() {
			$(obj.fadeItems[0]).insertAfter($(obj.fadeItems[obj.fadeItems.length - 1]));
			obj.orderItems();
			obj.animate = false;
		});
		if(obj.currItem + 1 == obj.fadeItems.length) obj.currItem = 0;
		else obj.currItem++;
		if(obj.values.pageDots) { 
			obj.changePageDot(obj.currItem);
		}
	}, this.values.intervalSpeed);
	if(this.values.pageDots) {
		this.makePageDots();
	}
}
// create new page element for page dots
tFade.prototype.makePageDots = function() {
	var obj = this;
	this.container.prepend('<div class="page-dots"></div>');
	this.dotContainer = $(this.values.container+' .page-dots');
	for(i=1; i<this.fadeItems.length+1; i++) {
		this.dotContainer.append('<a href="#" class="img-dots img-dot-'+i+'" rel="'+i+'">'+i+'</a>');
	}
	this.dotLinks = $(this.values.container+' .img-dots');
	this.dotLinks.click(function() {
		if(!obj.animate) obj.dotSkip($(this).attr('rel')-1);
		return false;
	});
	// define css
	this.dotLinks.css('float', 'left');
	this.dotContainer.css({
		'position':'absolute',
		'z-index':50
	});
	$($(this.values.container+' .img-dots')[0]).addClass('active');
}
// handle dot click
tFade.prototype.dotSkip = function(num) {
	if(num>=this.fadeItems.length) num = num - this.fadeItems.length;
	this.animate = true;
	var obj = this;
	currentItem = $(this.fadeItems[0]);
	var nextNum = ((num-this.currItem)>0) ? num-this.currItem : num-this.currItem+this.fadeItems.length;
	nextItem = $(this.fadeItems[nextNum]);
	if(num != this.currItem) {
		clearInterval(this.fadeInterval);		
		for(i=0; i<this.fadeItems.length; i++) {
			if(i==0 || i==nextNum) {
				continue;
			} else {
				$(this.fadeItems[i]).css('opacity', 0);
			}
		}
		var skip = (num - this.currItem > 0) ? num - this.currItem : parseInt(this.fadeItems.length) - this.currItem + parseInt(num);
		currentItem.animate({
			opacity:0
		}, this.values.opacitySpeed, function() {
			for(var n=0; n<skip; n++) {
				$(obj.fadeItems[0]).insertAfter($(obj.fadeItems[obj.fadeItems.length - 1]));
				obj.orderItems();
			}
			obj.animate = false;
		});
		
		this.currItem = (num >= 0) ? num : parseInt(this.fadeItems.length) - this.currItem + parseInt(num);
		if(this.values.pageDots) { 
			this.changePageDot(this.currItem);
		}
	}
}
// adjust dots according to scroll position
tFade.prototype.changePageDot = function(num) {
	this.dotLinks.removeClass('active');
	$(this.dotLinks[num]).addClass('active');
}
//------------------------------- End Rich's jQuery Fade Script --------------------------------------->;
/* Begin: TragicMedia.com - JQuery
/* updated 4/10 by Rich Rudzinski
/*------------------------------------------*/
//var constants = {container:'', btnLeft:'', btnRight:'', itemClass:'', pageDots:bool, interval:bool, intervalSpeed:#, gallery:bool, galleryBtns:bool, slideNumber:#, numberShown:#, speed:#};
//var scroll = new dScroll(constants);
//Notes: speed works as a "duration". The smaller the number, the faster it will animate
function dScroll(constants) {
	this.container = $(constants.container);
	this.containerId = constants.container;
	this.frame = this.container.parent();
	// hide frame to reduce element bouncing
	this.frame.css({'position':'relative', 'opacity':0});
	this.itemClass = constants.itemClass;
	this.slideItems = $(constants.container + ' ' + constants.itemClass);
	this.btnLeft = (constants.btnLeft == '' || constants.btnLeft == undefined) ? false : $(constants.btnLeft);
	this.btnRight = (constants.btnRight == '' || constants.btnRight == undefined) ? false : $(constants.btnRight);
	this.slideNumber = (constants.slideNumber == undefined) ? this.slideNumber = 1 : this.slideNumber = constants.slideNumber;
	this.currSlide = this.slideNumber;
	this.dir = 'right';
	this.numberShown = (constants.numberShown == undefined) ? this.numberShown = this.slideNumber : this.numberShown = constants.numberShown;
	this.speed = (constants.speed == undefined) ? this.speed = 300 : this.speed = constants.speed;
	this.pageDots = (constants.pageDots == undefined) ? false : constants.pageDots;
	this.interval = (constants.interval == undefined) ? false : constants.interval;
	this.intervalSpeed = (constants.intervalSpeed == undefined) ? 5000 : constants.intervalSpeed * 10;
	this.galleryBool = (constants.gallery == undefined) ? false : constants.gallery;
	this.galleryBtns = (constants.galleryBtns == undefined) ? false : constants.galleryBtns;
	if(this.galleryBool) {
		this.container.wrap('<div id="scroll-wrapper" />');
		this.frame = this.frame.find('#scroll-wrapper');
	}
	if(this.slideItems.length%this.numberShown != 0) this.addNodes(this.slideNumber - this.slideItems.length%this.numberShown);
	if(this.slideItems.find('img').length) {
		var obj = this;
		var img = this.slideItems.find('img')[0];
		if(img.complete || img.readyState === 4) {
			obj.initScroll();
		} else {
			$(img).load(function(){
				obj.initScroll();
			});
		}
	} else {
		this.initScroll();
	}
	if(this.interval && !this.disabled) this.createInterval();
}
// initialize scroller
dScroll.prototype.initScroll = function() {
	this.itemWidth = this.slideItems.width();
	this.itemHeight = this.slideItems.height();
	this.totalItemHeight = this.slideItems.outerHeight(true);
	this.totalItemWidth = this.slideItems.outerWidth(true);
	this.totalWidth = this.totalItemWidth * this.slideItems.length;
	this.totalSlide = this.slideNumber * this.totalItemWidth;
	this.container.left = 0;
	if(this.pageDots && this.slideItems.length > this.numberShown) this.makePageDots();
	if(this.galleryBool) this.createGallery();
	this.animateState(false);
	this.disabled = false;
	this.createScroll();
}
// add nodes to slideItems when not enough elements for pages
dScroll.prototype.addNodes = function(number) {
	for(i=0; i<number; i++) {
		var tempNode = this.slideItems[this.slideItems.length-1].cloneNode(false);
		this.container.append(tempNode);
	}
	this.slideItems = $(this.containerId + ' ' + this.itemClass);
}
// Set start position and adjust css for container and frame
dScroll.prototype.createScroll =  function() {
	var itemMargin = ($(this.slideItems[0]).css('margin-right')) ? parseInt($(this.slideItems[0]).css('margin-right')) : 0;
	var frameWidth = this.totalItemWidth * this.numberShown - itemMargin;
	this.container.css({'width': this.totalWidth + 'px',
		'height': this.totalItemHeight + 'px',
		'position': 'absolute',
		'left': this.container.left + 'px',
		'overflow': 'hidden'});
	this.frame.css({'width': frameWidth + 'px',
		'height': this.totalItemHeight + 'px',
		'position':'relative',
		'overflow': 'hidden'});
	this.slideItems.css({'width': this.itemWidth + 'px',
		'height': this.itemHeight + 'px',
		'float': 'left'});
	this.addBtnEvent();	// add arrow events
}
// add click event
dScroll.prototype.addBtnEvent = function() {
	var obj = this;
	var temp;
	if(this.slideItems.length <= this.numberShown) {
		this.disabled = true;
		if(this.btnLeft) this.btnLeft.addClass('disabled-btn');
		if(this.btnRight) this.btnRight.addClass('disabled-btn');
	} else {
		if(this.btnLeft) {
			this.btnLeft.click(function() {
				if(!obj.animate && !obj.disabled) {
					if(obj.scrollInterval) clearInterval(obj.scrollInterval);
					obj.dir = 'left';
					obj.shiftElementsLeft(obj.slideNumber);
					obj.slideLeft();		
				}
				return false;
			});
		}
		if(this.btnRight) {
			this.btnRight.click(function() {
				if(!obj.animate && !obj.disabled) {
					if(obj.scrollInterval) clearInterval(obj.scrollInterval);
					obj.dir = 'right';
					obj.slideRight();
				}
				return false;
			});
		}
	}
	// reveal frame
	if(this.galleryBool) temp = this.frame.parent();
	else temp = this.frame;
	temp.animate({
		opacity: 1
	}, 1500);
}
// Create interval
dScroll.prototype.createInterval =  function() {
	var obj = this;
	this.scrollInterval = setInterval(function() { 
		obj.animateState(true);
		obj.slideRight();
	}, this.intervalSpeed);
}
// moves the elements on the page in preparation for the slide
dScroll.prototype.shiftElementsLeft = function(shiftNumber) {
	this.container.left = this.container.left - shiftNumber * this.totalItemWidth;
	this.container.css('left', this.container.left + 'px');
	for(i=shiftNumber; i>0; i--) {
		$(this.slideItems[this.slideItems.length - 1]).insertBefore(this.slideItems[0]);
		this.slideItems = $(this.containerId + ' ' + this.itemClass);
	} 
}
dScroll.prototype.shiftElementsRight = function(shiftNumber) {
	this.container.left = this.container.left + shiftNumber * this.totalItemWidth;
	this.container.css('left', this.container.left + 'px');
	for(i=shiftNumber; i>0; i--) {
		$(this.slideItems[0]).insertAfter(this.slideItems[this.slideItems.length - 1]);
		this.slideItems = $(this.containerId + ' ' + this.itemClass);
	}
	this.animateState(false);
	if(this.pageDots) this.resetSlide();
}
// slide elements left
dScroll.prototype.slideLeft = function() {
	var obj = this;
	this.container.left = this.container.left + this.totalSlide;
	this.container.animate({
		left: this.container.left
	}, this.speed + 1/this.totalItemWidth + this.currSlide * 180, function() {obj.animateState(false); if(obj.pageDots) obj.resetSlide();});		
}
// slide elements right
dScroll.prototype.slideRight = function() {
	var obj = this;
	this.container.left = this.container.left - this.totalSlide;
	this.container.animate({
		left: this.container.left
	}, this.speed + 1/this.totalItemWidth + this.currSlide * 180, function() {obj.shiftElementsRight(obj.currSlide);});
}
// toggles the animation variable and loading class
dScroll.prototype.animateState = function(state) {
	if(state == true) {
		this.animate = true;
		if(this.galleryBool) this.galleryFrame.addClass('loading');
	} else {
		this.animate = false;
		if(this.galleryBool) this.galleryFrame.removeClass('loading');
	}	
}
// create new page element for page dots
dScroll.prototype.makePageDots = function() {
	this.frame.prepend('<div class="page-dots"></div>');
	this.dotContainer = this.frame.find('.page-dots');
	for(i=1; i<(this.slideItems.length/this.slideNumber)+1; i++) {
		this.dotContainer.append('<a href="#" class="slide-dot slide-dot-'+i+'" rel="'+i+'">0'+i+'</a>');
	}
	this.dotLinks = this.dotContainer.find('.slide-dot');
	$(this.dotLinks[0]).addClass('active');
	this.curr = 1;
	// define css
	this.dotLinks.css('float', 'left');
	var dotContainer_css = {
		'position': 'absolute',
		'z-index': 50
	}
	this.dotContainer.css(dotContainer_css);
	this.addDotClick();
}
// add dot click event
dScroll.prototype.addDotClick = function() {
	var obj = this;
	for(i=0; i<this.dotLinks.length; i++) {
		$(this.dotLinks[i]).click(function() {
			if(obj.scrollInterval) clearInterval(obj.scrollInterval);
			obj.curr = obj.dotContainer.find('.active').attr('rel')*1;
			var skip = this.rel*1;
			if(!obj.animate && skip != obj.curr) {
				if(skip > obj.curr) {
					if(skip - obj.curr <= obj.slideItems.length - skip + obj.curr) {
						obj.dir = 'right';
						obj.currSlide = skip-obj.curr;
					} else {
						obj.dir = 'left';
						obj.currSlide = obj.slideItems.length - skip + obj.curr;
					}
				} else {
					if(obj.curr - skip < (obj.slideItems.length - obj.curr) + skip) {
						obj.dir = 'left';
						obj.currSlide = obj.curr - skip;
					} else {
						obj.dir = 'right';
						obj.currSlide = (obj.slideItems.length - obj.curr) + skip
					}
				}
				obj.totalSlide = Math.abs(obj.currSlide)*obj.totalItemWidth;
				if(obj.dir == 'right') {
					obj.animateState(true);
					obj.slideRight();
				} else {
					obj.animateState(true);
					obj.shiftElementsLeft(obj.currSlide);
					obj.slideLeft();
				}
			}
			return false;
		});
	}
}
// change page dot
dScroll.prototype.changePageDot = function() {
	if(this.dir == 'right') {
		this.curr = this.curr + this.currSlide;
	} else {
		this.curr = this.curr - this.currSlide;
	}
	if(this.curr > this.slideItems.length) {
		this.curr = this.curr%this.slideItems.length;
	} else if(this.curr <= 0) {
		this.curr = this.slideItems.length + this.curr;
	}
	this.dotContainer.find('.active').removeClass('active');
	$(this.dotLinks[this.curr - 1]).addClass('active');
}
// reset slide number
dScroll.prototype.resetSlide = function() {
	if(this.pageDots) this.changePageDot();
	this.totalSlide = this.slideNumber * this.totalItemWidth;
	this.currSlide = this.slideNumber;
}
// Creates and loads main image for the gallery view
dScroll.prototype.createGallery = function() {
	var obj = this;
	this.slideItemActive = $(this.slideItems[0]);
	this.frame.parent().prepend('<div id="gallery-wrapper" class="container" style="position:relative; opacity:0;"><div id="gallery"></div><img class="loading" src="/sites/all/themes/elsass/images/loading.gif" /></div>');
	this.gallery = $('#gallery');
	this.galleryFrame = $('#gallery-wrapper');
	var img = new Image();
	this.gallery.prepend(img);
	this.galleryImg = $('#gallery img');
	this.galleryImg.load(function() {
		$(this).attr('width', this.width);
		$(this).attr('height', this.height);
		if(this.width > this.height) {
			$(this).addClass('landscape').css('top', Math.ceil((obj.gallery.height() - this.height)/2) + 'px');
		} else {
			$(this).addClass('portrait').css('left', Math.ceil((obj.gallery.width() - this.width)/2) + 'px');
		}
		obj.initGalleryCss();
		obj.gallery.parent().animate({
			opacity: 1
		}, 1500);
	});
	this.galleryImg.attr('src', this.slideItemActive.find('a').attr('href'));
	this.slideItemActive.addClass('gallery-active');
	for(i=0; i<this.slideItems.length; i++) {
		$(this.slideItems[i]).addClass('slide-' + i);
	}
	if(this.galleryBtns) {
		this.galleryFrame.prepend('<a href="#" title="Previous" id="btn-gallery-left" class="gallery-btn">Gallery Left</a>').append('<a href="#" title="Next" id="btn-gallery-right" class="gallery-btn">Gallery Right</a>');
		this.addGalleryBtnEvent();	// add gallery button events
	}
	this.addScrollClick();
}
// initialize Gallery CSS
dScroll.prototype.initGalleryCss = function() {
	this.gallery.parent().css({'position': 'relative'});
	this.gallery.css({'width': this.galleryImg.width(),
		'height': this.galleryImg.height(),
		'position': 'relative'});
	this.galleryImg.css({'position': 'absolute',
		'opacity': 1,
		'z-index': 1});
	$(this.galleryImg[0]).css('z-index', 2);
	$('.gallery-btn').css('position', 'absolute');
}
// Add Gallery button event
dScroll.prototype.addGalleryBtnEvent = function() {
	var obj = this;
	var slideNum;
	// add gallery left click
	$('#btn-gallery-left').click(function() {
		if(!obj.animate) {
			if(obj.scrollInterval) clearInterval(obj.scrollInterval);
			obj.animateState(true);
			obj.dir = 'left';
			slideNum = obj.slideItemActive.attr('class').split(/slide-/)[1].split(/ /)[0];
			if(slideNum == 0 || slideNum%obj.slideNumber == 0) {
				obj.shiftElementsLeft(obj.slideNumber);
				obj.slideLeft();
			}
			obj.slideItemActive.removeClass('gallery-active');
			if(obj.slideItemActive.prev().html() != null && obj.slideItemActive.prev().html() != '') {
				obj.slideItemActive = obj.slideItemActive.prev();
			} else {
				if(obj.slideItemActive.prev().html() == null) {
					obj.slideItemActive = $(obj.slideItems[obj.slideItems.length - 1]);
				} else {
					obj.slideItemActive = obj.slideItemActive.prev();
				}
				while(obj.slideItemActive.html() == '') {
					if(obj.slideItemActive.prev().html() != null) {
						obj.slideItemActive = obj.slideItemActive.prev();					
					} else {
						obj.slideItemActive = $(obj.slideItems[obj.slideItems.length - 1]);
					}
				}
			}
			obj.slideItemActive.addClass('gallery-active');
			obj.gallerySwap();	// swap gallery image
		}
		return false;
	});
	// add gallery right click
	$('#btn-gallery-right').click(function() {
		if(!obj.animate) {
			if(obj.scrollInterval) clearInterval(obj.scrollInterval);
			obj.animateState(true);			
			obj.dir = 'right';
			obj.slideItemActive.removeClass('gallery-active');
			if(obj.slideItemActive.next().html() != null && obj.slideItemActive.next().html() != '') {
				obj.slideItemActive = obj.slideItemActive.next();
			} else {
				if(obj.slideItemActive.next().html() == null) {
					obj.slideItemActive = $(obj.slideItems[0]);
				} else {
					obj.slideItemActive = obj.slideItemActive.next();
					while(obj.slideItemActive.html() == '') {
						if(obj.slideItemActive.next().html() != null) {
							obj.slideItemActive = obj.slideItemActive.next();					
						} else {
							obj.slideItemActive = $(obj.slideItems[0]);
						}
					}
				}
			}
			obj.slideItemActive.addClass('gallery-active');
			slideNum = obj.slideItemActive.attr('class').split(/slide-/)[1].split(/ /)[0];
			if(slideNum%obj.slideNumber == 0) {
				obj.slideRight();
			}
			obj.gallerySwap();	// swap gallery image
		}
		return false;
	});
}
// Update gallery on thumbnail click
dScroll.prototype.addScrollClick = function() {
	var obj = this;
	this.slideItems.click(function() {
		if(!$(this).hasClass('gallery-active') && !obj.animate) {
			obj.animateState(true);
			obj.slideItemActive.removeClass('gallery-active');
			$(this).addClass('gallery-active');
			obj.gallerySwap();
		}
		return false;
	});
}
// Load, insert, and fade new image
dScroll.prototype.gallerySwap = function() {
	var obj = this;
	var image = new Image();
	$(image).css({'position': 'absolute',
		'opacity': 0,
		'z-index': 1,
		'bottom': 0});
	this.slideItemActive = this.frame.find('.gallery-active');
	this.gallery.append(image);
	this.galleryImg = $('#gallery img');
	var galleryFirst = $(this.galleryImg[0]);
	var galleryLast = $(this.galleryImg[this.galleryImg.length -1]);
	$(image).load(function() {
		$(this).attr('width', this.width);		
		$(this).attr('height', this.height);
		if(this.width > this.height) {
			$(this).addClass('landscape').css('top', Math.ceil((obj.gallery.height() - this.height)/2) + 'px');
		} else {
			$(this).addClass('portrait').css('left', Math.ceil((obj.gallery.width() - this.width)/2) + 'px');
		}
		galleryFirst.animate({
			opacity: 0
		}, 1000, function() {
			$(this).css('z-index', 1);
			galleryLast.css('z-index', 2);
			
		});
		galleryLast.animate({
			opacity: 1
		}, 1000, function() { galleryFirst.remove(); obj.animateState(false); });
	});
	$(image).attr('src', this.slideItemActive.find('a').attr('href'));	
};
/* Begin: TragicMedia.com - Expandable Divs
/* created 1/11 by Rich Rudzinski
/*------------------------------------------*/
//constants={buttonClass:'class', speed:#, expandAllBool:bool} 
//var expandables = new Expandable(constants);
//Only buttonClass is required. Put the unique id with # of expanding object in rel of trigger, add class 'active' to trigger if you want it to start open. 'expandAllBool' if true will allow all of the expandables to open at once
//Other variables include 'speed' *for best results set between 5-20*

/*------------- BEGIN: animateTab ----------------*/
function Expandable(values) { //create container object which will hold booleans and child objects
	var links = $(values.buttonClass); //get all the links with the accordian class
	this.expandables = [];
	this.expandAllBool = (values.expandAllBool != undefined) ? values.expandAllBool : true;
	for(i=0; i<links.length; i++) {
		this.expandables.push(new ExpandableObj(links[i], values.speed, this));
	}
}
function ExpandableObj(button, speed, objVar) {   //create individual tab objects
	var obj = this;
	this.objVar = objVar;
	this.contentObj = $('#'+$(button).attr('rel'));
	this.content = this.contentObj[0];
	this.contentObj.css('overflow', 'hidden');
	this.button = button;
	// set initial parameters based on user presets
	this.content.max = this.content.offsetHeight;
	this.speed = (speed != undefined) ? (this.content.max/speed)*50 : 800; 	 // define obj vars
	if($(this.button).hasClass('active')) this.contentObj.css('height', this.content.max + 'px');
	else this.contentObj.css('height', '0px');
	this.content.current = parseInt(this.contentObj.css('height'));
	// add click event
	$(this.button).click(function() {
		obj.expand();
		return false;
	});	
}
ExpandableObj.prototype.expand = function() {
	var obj = this;
	if($(this.button).hasClass('active')) { // if open, close
		this.contentObj.stop().animate({
			height: 0
		}, this.speed, function() { $(obj.button).removeClass('active'); });
	} else { 
		if(!this.objVar.expandAllBool) { // manages other expandables when expandAll is false
			for(i=0; i<this.objVar.expandables.length; i++) {
				if($(this.objVar.expandables[i].button).hasClass('active')) {
					var button = $(this.objVar.expandables[i].button);
					$(this.objVar.expandables[i].contentObj).stop().animate({
						height: 0
					}, this.speed, function() {  button.removeClass('active'); });
				}
			}
		}
		$(this.button).addClass('active');  // else close
		this.contentObj.stop().animate({
			height: this.content.max
		}, this.speed);
	}
	
}


;

