var pageSize = 20, pageSizePre = 20, pageSizeExpo = 20, pageSizeSession = 20, pageSizeGeneral = 20, currentPagePre = 1, currentPageGeneral = 1, currentPageSession = 1, currentPageExpo = 1, currentPage = 1, combinefilter = true, filterPopup = false, xhr = "", xhrLoad = false, xhrsid = "", scrollpos = 0, filtersSet = false;
function videoWatch(parentElement) {
    if ($(parentElement).find(".video").text().indexOf("Watch") >= 0) {
        $(parentElement).find("#videoHolder").slideDown(function () { createVideo($(parentElement).find("#videoHolder").attr("title"), $(parentElement).find("#videoHolder")); });
        $(parentElement).find(".video").text($(parentElement).find(".video").text().replace("Watch", "Close"));
    }
    else {
        $(parentElement).find("#videoHolder").html("").slideUp();
        $(parentElement).find(".video").text($(parentElement).find(".video").text().replace("Close", "Watch"));
    }
}
function videoWatch2(parentElement) {
    if ($(parentElement).find("a").text().indexOf("Watch") >= 0) {
        $(parentElement).parent().find("#videoHolder").slideDown(function () { createVideo($(parentElement).parent().find("#videoHolder").attr("title"), $(parentElement).parent().find("#videoHolder")); });
        $(parentElement).find("a").text($(parentElement).find("a").text().replace("Watch", "Close"));
    }
    else {
        $(parentElement).parent().find("#videoHolder").html("").slideUp();
        $(parentElement).find("a").text($(parentElement).find("a").text().replace("Close", "Watch"));
    }
}
function createVideo(videoURL, parentElement, autop) {
    if (autop == undefined) { autop = true; }
    if (Silverlight.isInstalled()) {
        $(parentElement).html('<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="640" height="360"><param name="source" value="http://www.microsoft.com/showcase/silverlight/player/1/player-en.xap"/><param name="enableHtmlAccess" value="true" /><param name="background" value="#FF000000" /><param name="allowHtmlPopupwindow" value="true" /><param name="minRuntimeVersion" value="3.0.40624.0" /><param name="autoUpgrade" value="true" /><param name="initParams" value="Culture=en-US,Autoplay=' + autop + ',MarketingOverlayText=Visit this videos website,ShowWaterMark=false,ShowMarketingOverlay=false,MiscControls=FullScreen,ShowMenu=false,Tabs=Embed;Email;Share;Info,MediaSource=' + videoURL + ',Mode=Player" /></object>');
    }
    else {
        var wmvObject = "<object id='Player' width='640' height='405' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701' type='application/x-oleobject'><param name='URL' value='" + videoURL + "'><param name='uiMode' value='full'> <param name='autoStart' value='false'> <param name='enableContextMenu' value='True'> <param name='windowlessVideo' value='True'><embed type='application/x-mplayer2' pluginspage='http://microsoft.com/windows/mediaplayer/en/download/' id='Player' uimode='mini' enablecontextmenu='True' name='Player' width='640' height='405' src='" + videoURL + "' autostart='" + autop + "'></embed></object>";
        $(parentElement).html(wmvObject);
    }
}
function buttonControls(catalog) {
    $(".topicid:contains('4c892150-5a3f-e011-86d4-001ec953730b')").parent().find(".addprice").removeClass("Seminar").addClass("SeminarPDC");
    $(catalog).find('.topic .expopromo').tooltip({ delay: 0, fade: 250, extraClass: "blue", positionLeft: true, showURL: false });
    $(catalog).find('.topic .download').tooltip({ delay: 0, fade: 250, extraClass: "blue", positionLeft: true, showURL: false });
    $(catalog).find('.topic .video').tooltip({ delay: 0, fade: 250, extraClass: "blue", positionLeft: true, showURL: false });
    $(catalog).find('.topic .vlab').tooltip({ delay: 0, fade: 250, extraClass: "blue", positionLeft: true, showURL: false });
    $(catalog).find('.topic .webcast').tooltip({ delay: 0, fade: 250, extraClass: "blue", positionLeft: true, showURL: false });
    $(catalog).find('.Seminar a').tooltip({ delay: 0, fade: 250, extraClass: "orangeleft", positionLeft: false, bodyHandler: function () { return $("#popPrecon").html(); }, showURL: false });
    $(catalog).find('.SeminarPDC a').tooltip({ delay: 0, fade: 250, extraClass: "orangeleft", positionLeft: false, bodyHandler: function () { return $("#popPDC").html(); }, showURL: false });
    $(catalog).find('.topic .video').click(function () {
        if ($(this).hasClass('videoOn')) { $(this).parent().find("#videoHolder").html("").slideUp(); }
        else { var videoURL = $(this).html(); $(this).parent().find("#videoHolder").slideDown(function () { createVideo(videoURL, $(this).parent().find("#videoHolder")); }); }
        $(this).toggleClass("videoOn");
    });
    $(catalog).find('.topic .webcast').click(function () {
        if ($(this).hasClass('webcastOn')) { $(this).parent().find("#videoHolder").html("").slideUp(); }
        else { var videoURL = $(this).html(); $(this).parent().find("#videoHolder").slideDown(function () { createVideo(videoURL, $(this).parent().find("#videoHolder")); }); }
        $(this).toggleClass("webcastOn");
    });
    $(catalog).find('.topic .download').click(function () {
        $(this).parent().find(".downloads").slideToggle();
        $(this).toggleClass("downloadOn");
    });
}
function filterClose() {
    showNews = false;
    $("#filterDetail,#filterArrow").fadeOut("fast");
    xhrsid = "";
    filterPopup = false;
}
jQuery.expr[':'].Contains = function (a, i, m) { return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase()) >= 0; };
var filterTimer = 0;
function filterFind(ffind) {
    $(ffind).keyup(function () {
        var filter = $(this).val();
        var list = $(this).parent();
        var timerCallback = function () {
            filterSearch(filter, list);
        };
        clearTimeout(filterTimer);
        filterTimer = setTimeout(timerCallback, 500);
        return false;
    });
    $(ffind).click(function () { if ($(this).val() == "Search Filter...") { $(this).val(''); } });
}
function filterSearch(filter, list) {
    if (filter != "Search Filter..." && filter != "") {
        $(list).find("li").hide();
        $(list).find(".labelSearch:Contains(" + decodeURI(filter) + ")").parent().show();
    } else {
        $(list).find("li").show();
    }
}
function filterSetup(filterLabel) {
    $(filterLabel).find(".element .labelLink").click(function () {
        if ($(this).parent().find("input").attr("value") != xhrsid) {
            filterPopup = true;
            filterDetailPop($(this), false);
        }
    });
    $(filterLabel).find(".element .labelLink").mouseenter(function () {
		if (filterPopup) {
			if (!xhrLoad) {
				if ($(this).parent().find("input").attr("value") != xhrsid) {
					filterDetailPop($(this), false);
				}
			}
		}
	  }
	);
	$("#catalogfilter .filter li span.labelInput input[type=checkbox]").click(function () {
	  var applySize = $('.labelInput input[type=checkbox]').filter(':checked').length;
	  if (applySize > 0) { $("#filterappy").addClass("fappyOn").text("Apply filters"); }
	  else if (applySize == 0 && filtersSet) { $("#filterappy").addClass("fappyOn").text("Clear filters"); }
	  else if (applySize == 0 && filtersSet == false) { $("#filterappy").removeClass("fappyOn").text("Apply filters"); }
	});
    /*$("#catalogfilter .filter li span.labelInput label").click(function () {
        var label = $(this).find("input");
        if ($(this).hasClass("checked")) {
            $(this).removeClass("checked");
            $(label).attr("checked", false);
        } else {
            $(this).addClass("checked");
            $(label).attr("checked", true);
        }
        doSearch();
        if ($.browser.msie && $.browser.version.substr(0, 1) < 7) { }
        else { return false; }
    });*/
}
function filterDetailPop(fDetail, fPos) {
    if (fPos) {
        fDetail = $("#catalogfilter").find("input[id=" + fDetail + "]").parent().parent().parent().find(".labelLink");
        $("body").scrollTo($(fDetail), 500, { offset: { top: -60} });
    }
    var filterPosAdd = 0, filterPosMinus = 0;
    var filterPosition = $(fDetail).position();
    var filterOffset = $(fDetail).offset();
    var filterElement = $(fDetail).parent().parent().parent().parent().parent();
    if ($(filterElement).find(".element div").hasClass("fscroll")) {
        filterPosition = $(filterElement).find(".label").position(); filterPosAdd = 10; filterPosMinus = 30;
    }
    $("#filterDetail").css({ "top": filterPosition.top + 20 + filterPosAdd + "px" });
    $("#filterArrow").css({ "top": filterPosition.top + 40 + filterPosAdd + "px" });
    $("#filterDetail").html("<div class='name' style='padding:5px 0 0 20px'><span style='float:left;padding-right:10px'><img src='/resources/images/loading-small.gif' alt='Loading' /></span>Loading...</div>");
    $("#filterDetail").fadeIn(function () { $("#filterArrow").fadeIn(); });
    var filterLabelName = $(fDetail).parent().parent().parent().parent().parent().find(".label").text().toLowerCase();
    xhrsid = $(fDetail).parent().find("input").attr("value");
    if (filterLabelName == "speaker") {
        var spname = $(fDetail).parent().find(".labelLink").html();
        $.ajax({
            type: "GET", url: "/speaker/details/" + $(fDetail).parent().find("input").attr("value") + "?format=html", cache: false,
            success: function (data) {
				$("body").append('<div style="display:none" id="spldbio">'+data+'</div>');
                var speakerDeets = "", speakerPhoto = "";
				var speakerImg = $("#spldbio").find(".profileleft img").attr("src");
				if (speakerImg != undefined) { speakerPhoto = "<img src=" + speakerImg + " class='popphoto' style='float:left;margin-right:10px' />"; }
				var speakerBio = $("#spldbio").find("pre").text();
				var speakerJob = $("#spldbio").find(".job").text();
				speakerDeets += speakerPhoto+"<h3>" + $("#spldbio").find("h2.spn").text() + "</h3>";
				$("#spldbio").remove();
				if (speakerBio.length < 5 && speakerJob.length < 5) { speakerDeets += "<p style='clear:both;margin-top:10px'>Biography to follow.</p>"; }
				else if (speakerBio.length < 5) { speakerDeets += "<p><strong>" + speakerJob + "</strong></p><pre style='clear:both;margin-top:10px'>Biography to follow.</pre>"; }
				else { speakerDeets += "<p><strong>" + speakerJob + "</strong></p><pre style='clear:both;margin-top:10px'>" + speakerBio + "</pre>"; }
                $("#filterDetail").css({ "top": filterPosition.top + 10 + "px" });
                $("#filterDetail").html("<a href='javascript:filterClose()' class='button_close'></a>" + speakerDeets).hide().fadeIn("fast");
            }
        });
    } else {
        $.ajax({
            type: "GET", url: "/category/details/" + $(fDetail).parent().find("input").attr("value") + "?format=html", cache: false,
            success: function (data) {
                $("#filterDetail").css({ "top": filterPosition.top + 10 + filterPosMinus + "px" });
                $("#filterDetail").html("<a href='javascript:filterClose()' class='button_close'></a>" + data).hide().fadeIn("fast");
            }
        });
    }
}
function spsFilter() {
    $("#catalogfilter .label").click(function () {
        var labelParent = $(this).parent();
        filterLoad(labelParent, false, null);
    });
}
function filterLoad(labelParent, showPop, popLink) {
    var labelName = $(labelParent).find(".label").text().toLowerCase();
    var labelPops = " class='labelSearch labelLink'";
    if (labelName == "country" || labelName == "state" || labelName == "industry" || labelName == "product/technology" || labelName == "timeslot" || labelName == "exhibitor type") { labelPops = " class='labelSearch'"; }
    if ($(labelParent).find("table").length) {
        $(labelParent).find("input").wrap('<span></span>');
        $(labelParent).find("div").html("<ul></ul>").hide();
        $(labelParent).find("td:even").each(function (index) {
            if (jQuery.trim($(this).html()) != "") {
                var labelInput = $(this).find("span").html();
                var labelText = $(this).text();
                var labelClass = '';
                if ($(this).find("span input:checked").val() !== undefined) { labelClass = ' class="checked"'; }
                $(labelParent).find("div ul").append("<li><span class='labelInput'><label" + labelClass + ">" + labelInput + "</label></span><span" + labelPops + ">" + jQuery.trim(labelText) + "</span></li>");
                if ($(this).find("span input:checked").val() !== undefined) { $(labelParent).find("div ul li:last").find("input").attr('checked', true); }
            }
        });
        $(labelParent).find("td:odd").each(function (index) {
            if (jQuery.trim($(this).html()) != "") {
                var labelInput = $(this).find("span").html();
                var labelText = $(this).text();
                var labelClass = '';
                if ($(this).find("span input:checked").val() !== undefined) { labelClass = ' class="checked"'; }
                $(labelParent).find("div ul").append("<li><span class='labelInput'><label" + labelClass + ">" + labelInput + "</label></span><span" + labelPops + ">" + jQuery.trim(labelText) + "</span></li>");
                if ($(this).find("span input:checked").val() !== undefined) { $(labelParent).find("div ul li:last").find("input").attr('checked', true); }
            }
        });
        $(labelParent).find("table").remove();
        filterSetup(labelParent);
    }
    if ($(labelParent).find("select").length) {
        $(labelParent).find(".element div").remove();
        $(labelParent).find(".element").prepend("<div></div>");
        $(labelParent).find("div").html("<ul></ul>").hide();
        $(labelParent).find("div").addClass("fscroll");
        $(labelParent).find("div").prepend('<input type="text" value="Search Filter..." class="filterfind">');
        filterFind($(labelParent).find("div input"));
        var selectName = $(labelParent).find("select").attr("name");
        $(labelParent).find("option").each(function (index) {
            if (jQuery.trim($(this).text()) != "" && jQuery.trim($(this).text()) != "--") {
                var labelInput = '<input type="checkbox" id="' + $(this).val() + '" name="' + selectName + '" value="' + $(this).val() + '" />';
                var labelText = $(this).text();
                if (labelName == "timeslot") {
                    labelText = labelText.replace("Tuesday, August 30", "Tuesday, August 30<br />");
                    labelText = labelText.replace("Wednesday, August 31", "Wednesday, August 31<br />");
                    labelText = labelText.replace("Thursday, September 1", "Thursday, September 1<br />");
					labelText = labelText.replace("Friday, September 2", "Friday, September 2<br />");
                }
                var labelClass = '';
                var attr = $(this).attr('selected');
                if (attr !== 'undefined' && attr !== false) { labelClass = ' class="checked"'; }
                $(labelParent).find("div ul").append("<li><span class='labelInput'><label" + labelClass + ">" + labelInput + "</label></span><span" + labelPops + ">" + jQuery.trim(labelText) + "</span></li>");
                if (attr !== 'undefined' && attr !== false) { $(labelParent).find("div ul li:last").find("input").attr('checked', true); }
            }
        });
        var category = ggetUrlVars()["categories"];
        if (category != undefined) {
            category = category.replace(/%20/g, " ");
            category = category.replace(/\+/g, " ");
            var categoryArr = category.split(",");
            for (var fc = 0; fc < categoryArr.length; fc++) {
                var fcfield = $(labelParent).find("div ul li:Contains(" + decodeURI(categoryArr[fc]) + "):first");
                if ($(fcfield).text().length > 0) {
                    $(fcfield).find("input").attr('checked', true);
                    $(fcfield).find("label").addClass("checked");
                }
            }
        }
        var timeslot = ggetUrlVars()["tsid"];
        if (timeslot != undefined) {
            var fcfield = $(labelParent).find("div ul li input[value=" + timeslot + "]");
            if ($(fcfield).val().length > 0) {
                $(fcfield).find("input").attr('checked', true);
                $(fcfield).parent().parent().find("label").addClass("checked");
            }
        }
        $(labelParent).find("select").remove();
        filterSetup(labelParent);
    }
    $(labelParent).find("div.fscroll").removeClass("fscrollani");
    $(labelParent).find("div").slideToggle(function () { if (showPop) { filterDetailPop(popLink, true); } $(labelParent).find("div.fscroll").addClass("fscrollani"); });
    $(labelParent).find(".label").toggleClass("labelOn");
}
function speakerClose(speakerpop) { $(speakerpop).parent().parent().slideUp(function () { $(this).html(""); }); }
function speakerPopup(speakername, speakerbox) {
	$(speakerbox).html("<div class='biobox clearfix'><div class='loading'>Loading Speaker Details</div></div>").hide().fadeIn("fast");
	$(speakerbox).find(".loading").show();
	$.ajax({
		type: "GET", url: "/speaker/details/" + speakername + "?format=html", cache: false,
		success: function (data) {
			if (data.indexOf("<html>") < 0) {
				$("body").append('<div style="display:none" id="spldbio">'+data+'</div>')
				var speakerDeets = "", speakerPhoto = "";
				var speakerImg = $("#spldbio").find(".profileleft img").attr("src");
				if (speakerImg != undefined) { speakerPhoto = "<img src=" + speakerImg + " class='popphoto' />"; }
				var speakerBio = $("#spldbio").find("pre").text();
				var speakerJob = $("#spldbio").find(".job").text();
				speakerDeets += speakerPhoto+"<h3>" + $("#spldbio").find("h2.spn").text() + "</h3>";
				$("#spldbio").remove();
				if (speakerBio.length < 5 && speakerJob.length < 5) { speakerDeets += "<p>Biography to follow.</p>"; }
				else if (speakerBio.length < 5) { speakerDeets += "<p><strong>" + speakerJob + "</strong></p><pre>Biography to follow.</pre>"; }
				else { speakerDeets += "<p><strong>" + speakerJob + "</strong></p><pre>" + speakerBio + "</pre>"; }
				$(speakerbox).find(".biobox").html("<a href='#closesppop' class='button_close'></a>" + speakerDeets).hide().fadeIn("fast");
			} else {
				$(speakerbox).find(".biobox").html("<a href='#closesppop' class='button_close'></a><p>Biography to follow.</p>").hide().fadeIn("fast");
			}
			$("body").scrollTo($(speakerbox).parent());
		}
	});
}
function ggetUrlVars(tolow) {
    var vars = [], hash;
	if (tolow) { var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); }
	else { var hashes = window.location.href.toLowerCase().slice(window.location.href.indexOf('?') + 1).split('&'); }
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
