function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();
var vertSlider = null;
var vertBg = null;
var vertDownButton = null;
var vertUpButton = null;
var picSlidey = null;
var picSlideyLimit = 0;
var a = null;
var b = null;

function init() {
	if(browser.isIE) {
		if(browser.version <= 6) {
			document.getElementById("mainIE").style.height = document.getElementById("main").offsetHeight + "px";
			//alert(document.getElementById("mainIE").style.height);
		}
	}
	
	vertSlider = document.getElementById("galleryContainer");
	vertBg = document.getElementById("sliderBg");
	vertDownButton = document.getElementById("contentbottomgaltitle");
	vertUpButton = document.getElementById("contentbottomtext");
	picSlidey = document.getElementById("picSlider");
	picSlideyLimit = 528 - parseInt(picSlidey.style.width);
}

function galleryUp() {
	if (a != null) {
		return;
	}
	
	a = new Accelimation(vertSlider.style, "height", 147, 400, .8, "px");
	a.onend = onSlideEnd;
	a.onframe = gallerySlide;
	a.start();
	
//	vertSlider.style.height = "167px";
	vertBg.className = "galleryBgUp";
	vertDownButton.style.display = "inline";
	vertUpButton.style.display = "none";
	
}

function galleryDown() {
//	vertSlider.style.height = "33px";
	if (a != null) {
		return;
	}
	
	a = new Accelimation(vertSlider.style, "height", 33, 400, .8, "px");
	a.onend = onSlideDownEnd;
	a.onframe = gallerySlide;
	a.start();

	vertDownButton.style.display = "none";
	vertUpButton.style.display = "inline";
}

function gallerySlide(x) {
	vertSlider.style.height = x + "px";
}

function onSlideEnd() {
	a.stop();
	a = null;
}

function onSlideDownEnd() {
	vertBg.className = "galleryBgDown";
	a.stop();
	a = null;
}


function galleryLeft() {
	if (b != null) {
		b.stop();
		b = null;
	}

	b = new Accelimation(picSlidey.style, "left", picSlideyLimit, 2000, .8, "px");
	b.onend = onPicEnd;
	b.onframe = picSlide;
	b.start();
}

function galleryRight() {
	if (b != null) {
		b.stop();
		b = null;
	}

	b = new Accelimation(picSlidey.style, "left", 0, 2000, .8, "px");
	b.onend = onPicEnd;
	b.onframe = picSlide;
	b.start();
}

function picSlide(x) {
	picSlidey.style.left = x + "px";
}

function onPicEnd() {
	b.stop();
	b = null;
}

function popImage(image) {
	win = window.open("/imageViewer.php?i=" + image,"ImageViewer","width=790,height=500,scrollbars=yes");
}

function popArticleImage(imageID,articleID,category) {
	win = window.open("/articleImageViewer.php?i=" + imageID + "&a=" + articleID + "&c=" + category,"ImageViewer","width=790,height=500,scrollbars=yes");
}

function addToCart(type,id) {
	$('#result_'+type+'_'+id).html('Updating cart...');
	$.get('/customer_admin/cart_backup.php',$('#form_'+type+'_'+id).serialize(), function(data,status) { 
		$('#result_'+type+'_'+id).html(data);
		$('#btn_'+type+'_'+id).attr("src","/images/button_updatequantity.png");
	});
}
