﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="../../../YUI2.7/yahoo.js"/>
/// <reference path="../../../YUI2.7/dom.js"/>
/// <reference path="../../../YUI2.7/event.js"/>
/// <reference path="../../../YUI2.7/container.js"/>
/// <reference path="../../../YUI2.7/animation.js"/>
/// <reference path="../../../YUI2.7/dragdrop.js"/>

var mp = "ctl00_";
var p = mp + "ContentPlaceHolder1_";
var yDom = YAHOO.util.Dom, yEvent = YAHOO.util.Event;
var aPop = new Array(), aTxt = new Array();
var fade = { effect: YAHOO.widget.ContainerEffect.FADE, duration: 0.5 };
var nCPage = new Number(), nNumPages = new Number(), CarouselType, hdCarousel, pnlSlider, y, len, bR, tLen;
var Cats = new Array();
var bBskSum = false;
var bLockScroll = false;

function ShowPop(e, arg)
{
	yEvent.preventDefault(e);
	aPop[arg].show();
}

function HidePop(e, arg)
{
	aPop[arg].hide();
}

function ToggleBskSum(e, arg)
{
	yEvent.preventDefault(e);
	if(bBskSum == false)
	{
		aPop[arg].show();
		bBskSum = true;
	}
	else
	{
		aPop[arg].hide();
		bBskSum = false;
	}
	if(this.id == mp+"ibHUDExp" || this.id == "pnlBskDtl")
		yDom.setStyle(mp+"ibHUDExp", "background-position", "-25px -69px");
}

function ShowTextPop(e, arg)
{
	aTxt[arg].show();
}

function UnlockScroll()
{
	bLockScroll = false;
}

function ScrollCarousel(e, arg)
{
	yEvent.preventDefault(e);
	if(((arg < 0 && nCPage > 0) || (arg > 0 && nCPage < nNumPages - 1)) && bLockScroll == false)
	{
		bLockScroll = true;
		nCPage += arg;
		hdCarousel.innerHTML = CarouselType + " (page " + (nCPage+1) + "/" + nNumPages + ")";
		var x = yDom.getX(pnlSlider);
		var dx = -1 * arg * 99 * 4;
		var yEasing = YAHOO.util.Easing.easeBoth;
		var anim = new YAHOO.util.Motion(mp + "pnlSlider", { points: { to: [x + dx, y]} }, 1.5, yEasing);
		anim.onComplete.subscribe(UnlockScroll);
		anim.animate();
	}
}

function Resize()
{
	if(bR == false)
	{
		bR = true;
		setTimeout(Resize, 0);
	}
	else
	{
		for(var i = 0; i < len; i++)
		{
			aPop[i].cfg.setProperty("context", [Cats[i], "tl", "bl"]);
		}
		aPop[len].cfg.setProperty("context", [mp + "ibHUDExp", "tr", "br"]);
		for(var j = 0; j < tlen; j++)
		{
			aTxt[j].cfg.setProperty("context", ["lbMore" + j.toString(), "tl", "tl"]);
			aTxt[j].cfg.setProperty("x", aTxt[j].cfg.getProperty("x") - 40);
			aTxt[j].cfg.setProperty("y", aTxt[j].cfg.getProperty("y") - 5);
		}
		bR = false;
	}
}

yEvent.on(this, "load", function()
{
	var aSubCats = yDom.getElementsByClassName("pnlSubCat");
	len = aSubCats.length;
	for(var i = 0; i < len; i++)
	{
		Cats.push(aSubCats[i].parentNode);
		aPop.push(new YAHOO.widget.Panel(aSubCats[i], { width: "auto", underlay: "shadow", close: false, context: [Cats[i], "tl", "bl"], visible: false }));
		aPop[i].render(document.body);
		yEvent.on(Cats[i], "mouseover", ShowPop, i);
		yEvent.on(aSubCats[i], "mouseover", ShowPop, i);
		yEvent.on(Cats[i], "mouseout", HidePop, i);
		yEvent.on(aSubCats[i], "mouseout", HidePop, i);
	}
	aPop.push(new YAHOO.widget.Panel("pnlBskDtl", { width: "205px", underlay: "shadow", close: true, context: [mp + "ibHUDExp", "tr", "br"], visible: false, effect: fade }));
	aPop[len].render("aspnetForm");
	yEvent.on(mp + "ibHUDExp", "click", ToggleBskSum, len);
	aPop[len].hideEvent.subscribe(function() { yDom.setStyle(mp + "ibHUDExp", "background-position", "-25px -38px"); bBskSum = false; });
	var aTexts = yDom.getElementsByClassName("pText");
	tlen = aTexts.length;
	var More;
	for(var j = 0; j < tlen; j++)
	{
		More = document.createElement("a");
		More.id = "lbMore" + j.toString();
		More.className = "lbMore";
		More.innerHTML = "[more info +]";
		More.title = "Click to view more info";
		aTexts[j].parentNode.appendChild(More);
		aTxt.push(new YAHOO.widget.Panel(aTexts[j], { width: "150px", height: "auto", underlay: "shadow", close: true, visible: false, context: [More, "tl", "tl"], effect: fade }));
		aTxt[j].render("aspnetForm");
		aTxt[j].cfg.setProperty("x", yDom.getX(aTexts[j]) - 40);
		aTxt[j].cfg.setProperty("y", yDom.getY(aTexts[j]) - 5);
		yEvent.on(More, "click", ShowTextPop, j);
	}
	nCPage = parseInt(yDom.get(mp + "hdnCPage").value);
	nNumPages = parseInt(yDom.get(mp + "hdnNPages").value);
	CarouselType = yDom.get(mp + "hdnHeading").value;
	hdCarousel = yDom.get(mp + "hdCarousel");
	pnlSlider = yDom.get(mp + "pnlSlider");
	y = yDom.getY(pnlSlider);
	yEvent.on(mp + "ibScrollLeft", "click", ScrollCarousel, -1);
	yEvent.on(mp + "ibScrollRight", "click", ScrollCarousel, 1);
	bR = false;
	Resize();
});

yEvent.on(this, "resize", Resize);