function toggleDescription(divId) {
	var collapseDiv = new fx.Height(divId, {duration:400});
	if (document.getElementById(divId).style.display == 'none'){
		collapseDiv.hide();
		document.getElementById(divId).style.display = 'block';
	}
	collapseDiv.toggle();
}

function showDescription(divId,opinionDivOpen) {
	descriptionDiv = document.getElementById(divId);
	var startHeight = parseFloat(parseHeight(document.getElementById(divId).style.height));
	var opinionInterfaceHeight = 130;
	var endHeight;
	if (opinionDivOpen){
		endHeight = startHeight - opinionInterfaceHeight;
	}else{
		endHeight = startHeight + opinionInterfaceHeight;
	}
	descriptionDiv.effect('height', {duration:700, wait:true, transition:Fx.Transitions.expoOut}).custom(startHeight,endHeight);
}

function toggleOpinion(divId,div2Id) {
	var opinionDivOpen = false;
	opinionDivHeight = parseFloat(parseHeight(document.getElementById(divId).style.height));
	
	if (opinionDivHeight>0){
		opinionDivOpen = true;
	}
	var collapseDiv = new fx.Height(divId, {duration:250});
	if (document.getElementById(divId).style.display == 'none'){
		collapseDiv.hide();
		document.getElementById(divId).style.display = 'block';
		opinionDivClosed = true;
	}
	toggleDescrip = function(div2Id,opinionDivOpen){
		showDescription(div2Id,opinionDivOpen);
	}
	
	collapseDiv.toggle().chain(function(){toggleDescrip(div2Id,opinionDivOpen)});
}

function jumpOpinion(opinionId, divId){
	opinionDiv = document.getElementById(opinionId);
	descripDiv = document.getElementById(divId);
	if (descripDiv.style.height<1 ||  parseFloat(parseHeight(descripDiv.style.height))<1){
		opinionDiv.style.display = 'block';
		opinionDiv.style.height = '123px';
		toggleDescription(divId);
	}else {
		toggleOpinion(opinionId,divId);
	}
	
	
}

function parseHeight(styleHeight){
	var slicePos = styleHeight.indexOf('px');
	var height = styleHeight.slice(0,slicePos);
	return height;
}

function toggleOpacity(divId) {
	var fadeDiv = new fx.Opacity(divId, {duration:400});
	collapseBlock = function(divId){
		var collapseDiv = new fx.Height(divId, {duration:400});
		collapseDiv.toggle();
	}	
	fadeDiv.toggle().chain(function(){collapseBlock(divId)});
}
function se(prod){
	bug = new Image(); 
	bug.src = '/download.php?name=' + prod + '&l=' + document.location + '&d=' + window.status.substring(6); 	
}
function saveItem2(divId, product) {
	var url = '/saveItem.php?product=' + product; 
	var ajaxSaveItem = new Ajax(url, {method: 'get'}).request();
	displayNotification2('visitSavedItems');
}


function displayNotification2(divId){
	
	activeDiv = document.getElementById(divId);
	function completed(activeDiv){
		function fadeOut(){
			function postInit(activeDiv){
				activeDiv.style.display = 'none';
				
				
			}
			activeDiv.effect('opacity', {duration:2500, wait:true, onComplete:postInit, transition:Fx.Transitions.expoOut}).custom(.95,0);
		}
		var showBtn = new Fx.Opacity($('viewSavedItems'),{duration:1000, wait:true, transition:Fx.Transitions.bounceOut})
		showBtn.set(0);
		document.getElementById('visitSavedItems').style.display = 'block';
		showBtn.custom(0,1);
		fadeOut.delay(2000);	
	}
	var fadeSaveLink = new Fx.Opacity($('saveItem'),{duration:1000, wait:true, transition:Fx.Transitions.bounceOut})
	fadeSaveLink.custom(1,0);
	var showViewSavedLink = new Fx.Opacity($('visitSavedItems'),{duration:1000, wait:true, transition:Fx.Transitions.bounceOut})
	showViewSavedLink.set(0);
	document.getElementById('visitSavedItems').style.display = 'block';
	showViewSavedLink.custom(0,1);
}

function saveItem(divId, product) {
	var url = '/saveItem.php?product=' + product; 
	var ajaxSaveItem = new Ajax(url, {method: 'get'}).request();
	displayNotification(divId);
}


function displayNotification(divId){
	
	activeDiv = document.getElementById(divId);
	function completed(activeDiv){
		function fadeOut(){
			function postInit(activeDiv){
				activeDiv.style.display = 'none';
				
			}
			activeDiv.effect('opacity', {duration:2500, wait:true, onComplete:postInit, transition:Fx.Transitions.expoOut}).custom(.95,0);
		}
		var showBtn = new Fx.Opacity($('viewSavedItems'),{duration:1000, wait:true, transition:Fx.Transitions.bounceOut})
		showBtn.set(0);
		document.getElementById('viewSavedItems').style.display = 'block';
		showBtn.custom(0,1);
		fadeOut.delay(2000);	
	}
	
	if (!(activeDiv.style.display == 'block')){
		var fadeDiv = new fx.Opacity(divId, {duration:2000, onComplete:completed});
		fadeDiv.set(0);
		activeDiv.style.display = 'block';
		fadeDiv.custom(0,.95);
	}	
}

function removeItem(divId, product) {
	var url = '/removeItem.php?product=' + product; 
	var ajaxRemoveItem = new Ajax(url, {method: 'get'}).request();
	toggleOpacity(divId);
}

Fx.ScrollWindow = Fx.Base.extend({

	initialize: function(options){
		this.setOptions(options);
		this.now = [];
		var b = document.body;
		var stop = this.clearTimer.bind(this);
		if (!this.options.continuer){
			if (b.addEventListener) b.addEventListener('DOMMouseScroll', stop, false);
			else b.onmousewheel = stop;
		}
	},

	setNow: function(){
		[0,1].each(function(i){
			this.now[i] = this.compute(this.from[i], this.to[i]);
		}, this);
	},

	scrollTo: function(x, y){
		if (this.timer && this.options.wait) return;
		var left = Window.getScrollLeft();
		var top =  Window.getScrollTop();
		var width = Window.getWidth();
		var height = Window.getHeight();
		var fullWidth = Window.getScrollWidth();
		var fullHeight = Window.getScrollHeight();
		var maxScrollWidth = fullWidth - width;
		var maxScrollHeight = fullHeight - height;
		if (x > maxScrollWidth) x = maxScrollWidth;
		if (y > maxScrollHeight) y = maxScrollHeight;
		return this.custom([left, top], [x, y]);
	},

	toElement: function(el){
		return this.scrollTo($(el).getLeft(), $(el).getTop());
	},

	increase: function(){
		window.scrollTo(this.now[0], this.now[1]);
	}

});

function $random(min, max){
	return Math.floor(Math.random() * (max - min + 1) + min);
};

function intializeOpinions(){
	var myTips = new Tips($$('.toolTipImg'), {
		maxTitleChars: 50, 
		maxOpacity: .97, 
		className: 'tooltip'
		}
	);	
}
/*
window.onload = function() {
	var skroll = new Fx.ScrollWindow({duration: 1000, wait: false, transition: Fx.Transitions.sineInOut});
			
			
	$('downloadNow').addEvent('click', function(){
		skroll.toElement('downloadAnchor');
	});
	$('downloadNow2').addEvent('click', function(){
		skroll.toElement('downloadAnchor');
	});
	$('downloadNow3').addEvent('click', function(){
		skroll.toElement('downloadAnchor');
	});
}

//Height Parsing
function parseHeight(styleHeight){
	var slicePos = styleHeight.indexOf('px');
	var height = styleHeight.slice(0,slicePos-2);
	//var displayHeight = 
}
function getDisplayHeight(){
	var displayHeight = $('softwareDescription').getStyle('height');
	//alert(displayHeight);
	var additionalHeight = 280;
	var slicePos = displayHeight.indexOf('px');
	var height = displayHeight.slice(0,slicePos-2);
	
	height = parseInt(height);
	
	height += additionalHeight;
	height = height + 'px';
	$('contentContainer').setStyle('height',height);
	
}
window.onload = function() {
	//getDisplayHeight();
	//alert('hello');
	//var height = document.getElementById('contentContainer').style.height;
	//alert('height: ' + height);
	//$('contentContainer').setStyle('height','500px');
	
}

*/