﻿var defaultFrameID = 9;
var xmlhttp
var xmlhttp = null;
xmlhttp = createXMLHttp();

function selectAll(id) {
    document.getElementById(id).focus();
    document.getElementById(id).select();
}
function Clear(i) {document.getElementById(i).innerHTML = '';}
function SD(d) {document.getElementById(d).style.display = 'block'; }
function HD(d) {document.getElementById(d).style.display = 'none'; ; }
function setFocus(e) { document.getElementById(e).focus(); }
function timedMsg(id) { var t = setTimeout(function () { Clear(id) }, 3000) }
function timedMsg2(id, message) { var t = setTimeout(function () { showMessage2(id, message) }, 1000) }
function ToggleDiv(a) { var d = document.getElementById(a); if (d.style.display == 'block') { d.style.display = 'none'; } else { d.style.display = 'block'; } }
function loc() { window.location = 'basket.aspx'; }
function showMessage(id, message) { document.getElementById(id).innerHTML = message; }
function showMessage2(id, message) { document.getElementById(id).innerHTML = message; }
function isAlpha(evt) {
    var keyCode = evt.which ? evt.which : evt.keyCode;
    alpha = (keyCode >= 'a'.charCodeAt() &&
    keyCode <= 'z'.charCodeAt()) ||
    (keyCode >= 'A'.charCodeAt() &&
    keyCode <= 'Z'.charCodeAt()) ||
    (keyCode >= 8 && keyCode <= 46);
    return (alpha);
}
function popup(h, w, ref) {
    var iMyWidth, iMyHeight, win2;
    iMyWidth = (window.screen.width / 2) - ((w / 2));
    iMyHeight = (window.screen.height / 2) - ((h / 2));
    win2 = window.open(ref, "Window2", "status=no,height=" + h + ",width=" + w + ",resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
    win2.focus();
}
function clickDefaultButton(e, buttonid) {
    var evt = e ? e : window.event;
    var btn = document.getElementById(buttonid);
    if (btn) {
        if (evt.keyCode == 13) {
            alert('here');
            btn.click();
            return false;
        }
   }
}
function AB(itemID, divOfLabel, updatebasket) {
    var q = 1
    if (document.getElementById('txtRetailQuantity_' + itemID)) {
        q = document.getElementById('txtRetailQuantity_' + itemID).value;
        if (q) {} else {q = 1}
    }
    ajxSDACDCNA(page, 'fn=AB&apid=' + apid + '&iid=' + itemID + '&q=' + q, divOfLabel);
    document.getElementById(divOfLabel).innerHTML = '<span style="color:green;font-weight:bold;">Item added to cart!</span>';
    timedMsg(divOfLabel);
    UB();
    loc();
}
function AFB(iID, divOfLabel) {
    var q = 1;
    var msg;
    var ddl = document.getElementById('ddlFrameOpening');
    var div = document.getElementById(divOfLabel);
    var num = 0
    if (ddl) {
        if (ddl.selectedIndex == 0) {
            msg = '<span style="color:red;font-weight:bold;">Please select a frame opening.</span>';
        } else {
            num = ddl.options[ddl.selectedIndex].value;
            iID = iID + num
            msg = '<span style="color:green;font-weight:bold;">Item added to cart. </span>';
            var datatopost = 'fn=AB&apid=' + apid + '&iid=' + iID + '&q=' + q;
            ajxSDACDCNA(page, datatopost, divOfLabel);
            UB();
        }
        div.innerHTML = msg;
        timedMsg(divOfLabel);
    }
    loc();
}
function AFW(apid, letters, lettersCount, fid, word) { /*Add Framed Word*/
    return SendDataNonAsync(page, 'fn=AFWTC&apid=' + apid + '&l=' + letters + '&lc=' + lettersCount + '&fid=' + fid + '&w=' + word);
}
function GBIT(d) { /*Get Basket Item Total*/
    ajxSDACDC(page, 'fn=GBIT&apid=' + apid, d);
}
function UB() { /*Update Basket*/
    var d = 'basket-item-count';
    if (document.getElementById(d)) {
        GBIT(d);
    }
}
function cwSS1() {
    SD('step1');
    HD('step2');
    HD('step3');
}

function cwSS2() {
    HD('step3');
   // HD('step1');
    $('#step1').fadeOut(600, function () {
        // Animation complete.
        $('#step2').fadeIn(600, function () {
            //HD('step3');
            //setFocus('ctl00_ContentPlaceHolder1_cawMain_txtWord');
            selectAll('ctl00_ContentPlaceHolder1_cawMain_txtWord');
        });
        //SD('step2');

    });
   
   
}
function cwSS3() {
    HD('step1');
    HD('step2');
    SD('step3');
    cwAdjustBuyButtonLocation();
    
}
function cwAdjustBuyButtonLocation() {
    $(document).ready(function () {
        if ($("#caw-frame").length > 0) {

            var w = $("#caw-frame").width();
            w = (w - 65);

            if ($(".buy-my-word").length > 0) {

                $(".buy-my-word").css({
                    'margin-left': w,
                    'margin-top': '-55px'
                }
                );
            }

        } else if ($("#caw-noframe").length > 0) {

            var w = $("#caw-noframe").width();
            w = (w + 215);

            if ($(".buy-my-word").length > 0) {

                $(".buy-my-word").css({
                    'margin-left': w,
                    'margin-top': '0px'
                }
                );
            }
            if ($("#details-and-options").length > 0) {

                $("#details-and-options").css({
                    'margin-top': '-100px'

                }
                );
            }
        }
    });
}

function cwC() {
    document.getElementById('ctl00_ContentPlaceHolder1_cawMain_txtWord').value = '';
    cwSS2();
}

function cwCF(num) {
    ajxSDACDCNA(page, 'fn=AF&apid=' + apid + '&n=' + num, 'selectFrameData');
    if (framing) { framing = true; }
    $(document).ready(function () {
        $.colorbox.init()
        $.colorbox({ width: "960px", inline: true, href: "#select-frame-container" });
    });
}

function cwRF() {
    cwCRAW(0);
    if (framing) { framing = false; }
}

function cwCAW() {
    //if (f) { defaultFrameID = f }

    var word = document.getElementById('ctl00_ContentPlaceHolder1_cawMain_txtWord').value;
    document.getElementById('ctl00_ContentPlaceHolder1_cawMain_hdnWord').value = word;
    if (caw_src == 'a') {
        dp = 'fn=CAW&apid=' + apid + '&word=' + word + '&frameid=0' + '&ab_me=Y' + '&category=SIGNS' + '&src=' + caw_src;
    }
    else {
        dp = 'fn=CAW&apid=' + apid + '&word=' + word + '&frameid=' + defaultFrameID + '&src=' + caw_src
    }

    ajxSDACDCNA(page, dp, 'step3');
    cwSS3();
    //_gaq.push(['_trackEvent', 'CreateAWord', 'CreatedWord', '']);
}
function cwCAWFL(l, w) {
  
    var word = document.getElementById('ctl00_ContentPlaceHolder1_cawMain_txtWord').value;
    document.getElementById('ctl00_ContentPlaceHolder1_cawMain_hdnWord').value = word;
    
    if (caw_src == 'a') {
        dp = 'fn=CAW&apid=' + apid + '&letters=' + l + '&word=' + w + '&frameid=0' + '&ab_me=Y' + '&category=SIGNS' + '&src=' + caw_src;
    }
    else {
        dp = 'fn=CAW&apid=' + apid + '&letters=' + l + '&word=' + word + '&frameid=0' + '&src=' + caw_src;
    }

    ajxSDACDCNA(page, dp, 'step3');
    cwSS3();
    //_gaq.push(['_trackEvent', 'CreateAWord', 'CreatedWord', '']);
}

//function AlphabetizeMe(l, w) {
//    if (l && l.length > 0) {
//        // 1. We can build the word from letters passed in.
//        var datatopost = 'fn=CreateAWord&apid=' + apid + '&letters=' + l + '&word=' + w + '&frameid=0' + '&ab_me=Y' + '&category=SIGNS';
//        document.getElementById('ctl00_ContentPlaceHolder1_txtWord').value = w;
//    } else {
//        //2. We can either build a word from the textbox
//        var word = document.getElementById('ctl00_ContentPlaceHolder1_txtWord').value;
//        document.getElementById('ctl00_ContentPlaceHolder1_hdnWord').value = word;
//        var datatopost = 'fn=CreateAWord&apid=' + apid + '&word=' + word + '&frameid=0' + '&ab_me=Y' + '&category=SIGNS';
//    }

//    //ajxSDACDC(page, datatopost, 'searchResults');
//    //HD('FilterLetters');
//    //HD('AddAFrame');
//    //SD('searchResults');
//    //SD('SocalNetworks');
//    //_gaq.push(['_trackEvent', 'AlphabetizeMe', 'CreatedWord', '']);     //Google track event.

//}


function cwKH(e, form) {
    var evt = e ? e : window.event;
    if (evt.keyCode == 13) { cwCAW(); return false; } else { if (!isAlpha(evt)) { return false; } }
}

function cwCRAW(f) {
    var tag = document.getElementsByTagName('input');
    var letters = '';
    for (x = 0; x < tag.length; x++) {
        var name = tag[x].name
        if (name.indexOf('hdn_letter_') != -1) {
            letters = letters + tag[x].value + '|';
        }
    }
    var datatopost = 'fn=CAW&apid=' + apid + '&letters=' + letters + '&frameid=' + f + '&src=' + caw_src;

    ajxSDACDCNA(page, datatopost, 'step3');

    if ($.colorbox) {
        $.colorbox.close();
    }
    SD('step3');
    cwAdjustBuyButtonLocation();
}

function cwSL(letter, div, hid) { //ShowLetter
    var dp = '';
    if (caw_src == 'a') {
        dp = 'fn=GLFCAW&apid=' + apid + '&letter=' + letter + '&div=' + div + '&hid=' + hid + '&category=SIGNS' + '&ab_me=Y';
    }
    else {
        dp = 'fn=GLFCAW&apid=' + apid + '&letter=' + letter + '&div=' + div + '&hid=' + hid;
    }

    ajxSDACDCNA(page, dp, 'selectLettersData');
    $(document).ready(function () {
        $.colorbox.init()
        $.colorbox({ width: "65%", height: "600px", inline: true, href: "#select-letter-container" });
    });
}

function cwCL(letter, item_id, newimage, divtochange, hid) {
    var ahref = '<a href="javascript:cwSL(\'' + letter + '\', \'' + divtochange + '\',\'' + hid + '\')">';
    var i = '';
    if (caw_src == 'a') {
        i = '/images/ab_me/';
    }
    else {
        i = '/images/medium/';
    }

    document.getElementById(hid).value = item_id;
    document.getElementById(divtochange).innerHTML = ahref + '<img class="letter-size" src="' + i + newimage + '"  /></a>';

    if ($.colorbox) {
        $.colorbox.close();
    }
    SD('step3');
}

function cwSTF() {
    $(document).ready(function () {
        $.colorbox.init()
        $.colorbox({ width: "500px", inline: true, href: "#send-to-friend-container" });
    });
    document.getElementById('sendToAFriendValidationMessage').innerHTML = '';
}

function cwAFWTC() {

    var FormEdit = document.getElementById('aspnetForm');
    var letters, lettersCount, frameid, addAFrameResult;
    //var div = document.getElementById('add-letters-result');
    //div.innerHTML = '<div style="text-align: center; "><br /><br /><img src="/images/loading.gif" alt="loading" /><br /><br /><p>Loading - Please wait</p></div>'
    //1. Initialise variables
    letters = '';
    lettersCount = 0;
    //2. Loop through letters and add the ID's of letters to save
    var tag = document.getElementsByTagName('input');
    for (x = 0; x < tag.length; x++) {
        var name = tag[x].name
        var val = tag[x].value;
        if (name.indexOf('hdn_letter_') != -1) {
            letters = (letters + val + ',');
            lettersCount = lettersCount + 1;
        }
    }
    //3. ensure the letters used are formatted correctly.
    if (letters.length > 0) { letters = letters.substring(0, letters.length - 1); } //remove last commar
    else { letters = ''; } //otherwise set letters to default
    //4. Get frame
    var frameid = document.getElementById('hdn_frame').value;
    var word = document.getElementById('ctl00_ContentPlaceHolder1_cawMain_hdnWord').value;
    //5. Check for errors
    var addAFrameResult = AFW(apid, letters, lettersCount, frameid, word);
    loc();
}

function cwALFWTC(currentpage) {
    //var div = document.getElementById('add-letters-result');
    //div.innerHTML = '<div class="c"><br /><br /><img src="/images/loading.gif" alt="loading" /><br /><br /><p>Loading - Please wait</p></div>'
    var tag = document.getElementsByTagName('input');
    for (x = 0; x < tag.length; x++) {
        var name = tag[x].name
        if (name.indexOf('hdn_letter_') != -1) { cwATBFCAW(tag[x].value) }
    }
    loc();
}
function cwATBFCAW(i) {
    SendDataNonAsync(page, 'fn=AB&apid=' + apid + '&iid=' + i);
}

function cwSWTAF() {
    var FormEdit = document.getElementById('aspnetForm');
    var divLoadingMsg = document.getElementById('sendToAFriendLoadingMessage');
    var divValMsg = document.getElementById('sendToAFriendValidationMessage');
    var divForm = document.getElementById('sendToAFriendForm');
    var letters;
    var lettersCount;
    var sendToAFriendResult;
    var frameid;

    //Initialise variables
    letters = '';
    lettersCount = 0;
    //1. Show/Hide screens
    SD('sendToAFriendLoadingMessage');
    HD('sendToAFriendForm');
    //2. Loop through letters and add the ID's of letters to save
    var tag = document.getElementsByTagName('input');
    for (x = 0; x < tag.length; x++) {
        var name = tag[x].name
        var val = tag[x].value;
        if (name.indexOf('hdn_letter_') != -1) {
            letters = (letters + val + ',');
            lettersCount = lettersCount + 1;
        }
    }

    //3. ensure the letters used are formatted correctly.
    if (letters.length > 0) {
        letters = letters.substring(0, letters.length - 1); //remove last commar
    }
    else {
        letters = ''; //otherwise set letters to default
    }
    //4A. Validate credentials
    var txtYourName = document.getElementById('txtYourName');
    var txtYourEmail = document.getElementById('txtYourEmail');
    var txtFriendsName = document.getElementById('txtFriendsName');
    var txtFriendsEmail = document.getElementById('txtFriendsEmail');

    //4B. Frame
    if (document.getElementById('hdn_frame')) {
        frameid = document.getElementById('hdn_frame').value;
    } else {
        frameid = 0;
    }
    //5. Check for errors
    var sendToFriendResult = cwSTFE(apid, letters, lettersCount, txtYourName.value, txtYourEmail.value, txtFriendsName.value, txtFriendsEmail.value, frameid)
    if (sendToFriendResult == 'SUCCESS') {
        divValMsg.innerHTML = '<span style="color:green;font-weight:bold;">Your message to ' + txtFriendsName.value + ' was successfully sent!</span>'
        // 6. Clear form
        txtYourName.value = ''
        txtYourEmail.value = ''
        txtFriendsName.value = ''
        txtFriendsEmail.value = ''
    } else {
        divValMsg.innerHTML = '<span style="color:red;font-weight:bold;">' + sendToFriendResult + '</span>'
    }
    //7. Show/Hide screens
    SD('sendToAFriendValidationMessage');
    SD('sendToAFriendForm');
    HD('sendToAFriendLoadingMessage');
}
function cwSTFE(apid, letters, lettersCount, yn, ye, frn, fre, fid) {
    var datatopost = 'fn=STAF&apid=' + apid + '&l=' + letters + '&yn=' + yn + '&ye=' + ye + '&frn=' + frn + '&fre=' + fre + '&lc=' + lettersCount + '&fid=' + fid;
    var msg = SendDataNonAsync(page, datatopost);
    return msg;
}
function cwCWordFSBFID(sbf_apid, sbf_sbfid, frameid) { /*CreateAWordFromSBFID*/
    ajxSDACDC(page, 'fn=CAW&apid=' + sbf_apid + '&sbfid=' + sbf_sbfid + '&frameid=' + frameid, 'step3');
    cwSS3();
}
function cwCWFSFID(word_apid, sfid, frameid) {
    ajxSDACDCNA(page, 'fn=CAW&word_apid=' + word_apid + '&sfid=' + sfid + '&frameid=' + frameid, 'step3');
    cwSS3();
}

function cwDownload() {

    var letters;
    var lettersCount;
    var word;
    letters = '';
    lettersCount = 0;
    word = '';
    //2. Loop through letters and add the ID's of letters to save
    var tag = document.getElementsByTagName('input');
    for (x = 0; x < tag.length; x++) {
        var name = tag[x].name
        var val = tag[x].value;
        if (name.indexOf('hdn_letter_') != -1) {
            letters = (letters + val + '|');
            lettersCount = lettersCount + 1;
            word = word + val.substring(0, 1);
        }
    }
    if (letters.length > 0) {
        letters = letters.substring(0, letters.length - 1); //remove last commar
    }
    else {
        letters = ''; //otherwise set letters to default
    }

    //_gaq.push(['_trackEvent', 'AlphabetizeMe', 'Downloaded', '']);
    window.location = 'create_a_word.aspx?fn=download&l=' + letters + '&w=' + word;
}


/*--Ajax functions --*/
// ### Instantiate XMLHTTP Object - cross browser (new IE / new Mozilla)


function createXMLHttp() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        var aVersions = ["Microsoft.XMLHttp", "MSXML2.XMLHttp", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.5.0"];

        for (var i = 0; i < aVersions.length; i++) {
            try {
                var oXmlHttp = new ActiveXObject(aVersions[i]);
                return oXmlHttp;
            } catch (oError) {
                //Do nothing
            }
        }
    }
    throw new Error("XMLHttp object could be created.");
}

function ajxSDACDC(page, datatopost, divid) {

    var httpreq = null;
    httpreq = createXMLHttp();
    httpreq.onreadystatechange = function() {
        if (httpreq.readyState == 1) {
            var div = document.getElementById(divid);
            div.innerHTML = 'Loading - Please wait...';
        }

        if (httpreq.readyState == 4) {
            datareturned = httpreq.responseText;
            var div = document.getElementById(divid);
            div.innerHTML = datareturned;
        }
    };
    httpreq.open("POST", page, true);
    httpreq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
    httpreq.send(datatopost);
}

function ajxSDACDCNA(page, datatopost, divid) {
    xmlhttp.open("POST", page, false);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
    xmlhttp.send(datatopost);
    if (xmlhttp.status == 200) {
        datareturned = xmlhttp.responseText;
        var div = document.getElementById(divid);
        div.innerHTML = datareturned;
    }
}
function SendDataNonAsync(page, datatopost) {
    xmlhttp.open('POST', page, false);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xmlhttp.send(datatopost);
    return xmlhttp.responseText;
}
function SendDataNonAsyncAndChangeDiv(page, datatopost, divid) {
    xmlhttp.open('POST', page, false);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xmlhttp.send(datatopost);
    document.getElementById(divid).innerHTML = xmlhttp.responseText;
}

function AlphabetizeMeFromSBFID(sbf_apid, sbf_sbfid, frameid) {
    var datatopost = 'fn=CreateAWord&apid=' + sbf_apid + '&sbfid=' + sbf_sbfid + '&frameid=' + frameid + '&ab_me=Y' + '&category=SIGNS';
    var divid = 'searchResults';
    ajxSDACDC(page, datatopost, divid);
    HD('FilterLetters');
    HD('AddAFrame');
    SD('searchResults');
    SD('SocalNetworks');
}


// ColorBox v1.3.17.2 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
// Copyright (c) 2011 Jack Moore - jack@colorpowered.com
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
(function (a, b, c) { function bc(b) { if (!U) { P = b, _(), y = a(P), Q = 0, K.rel !== "nofollow" && (y = a("." + g).filter(function () { var b = a.data(this, e).rel || this.rel; return b === K.rel }), Q = y.index(P), Q === -1 && (y = y.add(P), Q = y.length - 1)); if (!S) { S = T = !0, r.show(); if (K.returnFocus) try { P.blur(), a(P).one(l, function () { try { this.focus() } catch (a) { } }) } catch (c) { } q.css({ opacity: +K.opacity, cursor: K.overlayClose ? "pointer" : "auto" }).show(), K.w = Z(K.initialWidth, "x"), K.h = Z(K.initialHeight, "y"), X.position(), o && z.bind("resize." + p + " scroll." + p, function () { q.css({ width: z.width(), height: z.height(), top: z.scrollTop(), left: z.scrollLeft() }) }).trigger("resize." + p), ba(h, K.onOpen), J.add(D).hide(), I.html(K.close).show() } X.load(!0) } } function bb() { var a, b = f + "Slideshow_", c = "click." + f, d, e, g; K.slideshow && y[1] ? (d = function () { F.text(K.slideshowStop).unbind(c).bind(j, function () { if (Q < y.length - 1 || K.loop) a = setTimeout(X.next, K.slideshowSpeed) }).bind(i, function () { clearTimeout(a) }).one(c + " " + k, e), r.removeClass(b + "off").addClass(b + "on"), a = setTimeout(X.next, K.slideshowSpeed) }, e = function () { clearTimeout(a), F.text(K.slideshowStart).unbind([j, i, k, c].join(" ")).one(c, d), r.removeClass(b + "on").addClass(b + "off") }, K.slideshowAuto ? d() : e()) : r.removeClass(b + "off " + b + "on") } function ba(b, c) { c && c.call(P), a.event.trigger(b) } function _(b) { K = a.extend({}, a.data(P, e)); for (b in K) a.isFunction(K[b]) && b.substring(0, 2) !== "on" && (K[b] = K[b].call(P)); K.rel = K.rel || P.rel || "nofollow", K.href = K.href || a(P).attr("href"), K.title = K.title || P.title, typeof K.href == "string" && (K.href = a.trim(K.href)) } function $(a) { return K.photo || /\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(a) } function Z(a, b) { return Math.round((/%/.test(a) ? (b === "x" ? z.width() : z.height()) / 100 : 1) * parseInt(a, 10)) } function Y(c, d, e) { e = b.createElement("div"), c && (e.id = f + c), e.style.cssText = d || ""; return a(e) } var d = { transition: "elastic", speed: 300, width: !1, initialWidth: "600", innerWidth: !1, maxWidth: !1, height: !1, initialHeight: "450", innerHeight: !1, maxHeight: !1, scalePhotos: !0, scrolling: !0, inline: !1, html: !1, iframe: !1, fastIframe: !0, photo: !1, href: !1, title: !1, rel: !1, opacity: .9, preloading: !0, current: "image {current} of {total}", previous: "previous", next: "next", close: "close", open: !1, returnFocus: !0, loop: !0, slideshow: !1, slideshowAuto: !0, slideshowSpeed: 2500, slideshowStart: "start slideshow", slideshowStop: "stop slideshow", onOpen: !1, onLoad: !1, onComplete: !1, onCleanup: !1, onClosed: !1, overlayClose: !0, escKey: !0, arrowKey: !0, top: !1, bottom: !1, left: !1, right: !1, fixed: !1, data: !1 }, e = "colorbox", f = "cbox", g = f + "Element", h = f + "_open", i = f + "_load", j = f + "_complete", k = f + "_cleanup", l = f + "_closed", m = f + "_purge", n = a.browser.msie && !a.support.opacity, o = n && a.browser.version < 7, p = f + "_IE6", q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X; X = a.fn[e] = a[e] = function (b, c) { var f = this; b = b || {}; if (!f[0]) { if (f.selector) return f; f = a("<a/>"), b.open = !0 } c && (b.onComplete = c), f.each(function () { a.data(this, e, a.extend({}, a.data(this, e) || d, b)), a(this).addClass(g) }), (a.isFunction(b.open) && b.open.call(f) || b.open) && bc(f[0]); return f }, X.init = function () { z = a(c), r = Y().attr({ id: e, "class": n ? f + (o ? "IE6" : "IE") : "" }), q = Y("Overlay", o ? "position:absolute" : "").hide(), s = Y("Wrapper"), t = Y("Content").append(A = Y("LoadedContent", "width:0; height:0; overflow:hidden"), C = Y("LoadingOverlay").add(Y("LoadingGraphic")), D = Y("Title"), E = Y("Current"), G = Y("Next"), H = Y("Previous"), F = Y("Slideshow").bind(h, bb), I = Y("Close")), s.append(Y().append(Y("TopLeft"), u = Y("TopCenter"), Y("TopRight")), Y(!1, "clear:left").append(v = Y("MiddleLeft"), t, w = Y("MiddleRight")), Y(!1, "clear:left").append(Y("BottomLeft"), x = Y("BottomCenter"), Y("BottomRight"))).children().children().css({ "float": "left" }), B = Y(!1, "position:absolute; width:9999px; visibility:hidden; display:none"), a("body").prepend(q, r.append(s, B)), t.children().hover(function () { a(this).addClass("hover") }, function () { a(this).removeClass("hover") }).addClass("hover"), L = u.height() + x.height() + t.outerHeight(!0) - t.height(), M = v.width() + w.width() + t.outerWidth(!0) - t.width(), N = A.outerHeight(!0), O = A.outerWidth(!0), r.css({ "padding-bottom": L, "padding-right": M }).hide(), G.click(function () { X.next() }), H.click(function () { X.prev() }), I.click(function () { X.close() }), J = G.add(H).add(E).add(F), t.children().removeClass("hover"), q.click(function () { K.overlayClose && X.close() }), a(b).bind("keydown." + f, function (a) { var b = a.keyCode; S && K.escKey && b === 27 && (a.preventDefault(), X.close()), S && K.arrowKey && y[1] && (b === 37 ? (a.preventDefault(), H.click()) : b === 39 && (a.preventDefault(), G.click())) }) }, X.remove = function () { r.add(q).remove(), a("." + g).removeData(e).removeClass(g) }, X.position = function (a, c) { function g(a) { u[0].style.width = x[0].style.width = t[0].style.width = a.style.width, C[0].style.height = C[1].style.height = t[0].style.height = v[0].style.height = w[0].style.height = a.style.height } var d = 0, e = 0; z.unbind("resize." + f), r.hide(), K.fixed && !o ? r.css({ position: "fixed" }) : (d = z.scrollTop(), e = z.scrollLeft(), r.css({ position: "absolute" })), K.right !== !1 ? e += Math.max(z.width() - K.w - O - M - Z(K.right, "x"), 0) : K.left !== !1 ? e += Z(K.left, "x") : e += Math.round(Math.max(z.width() - K.w - O - M, 0) / 2), K.bottom !== !1 ? d += Math.max(b.documentElement.clientHeight - K.h - N - L - Z(K.bottom, "y"), 0) : K.top !== !1 ? d += Z(K.top, "y") : d += Math.round(Math.max(b.documentElement.clientHeight - K.h - N - L, 0) / 2), r.show(), a = r.width() === K.w + O && r.height() === K.h + N ? 0 : a || 0, s[0].style.width = s[0].style.height = "9999px", r.dequeue().animate({ width: K.w + O, height: K.h + N, top: d, left: e }, { duration: a, complete: function () { g(this), T = !1, s[0].style.width = K.w + O + M + "px", s[0].style.height = K.h + N + L + "px", c && c(), setTimeout(function () { z.bind("resize." + f, X.position) }, 1) }, step: function () { g(this) } }) }, X.resize = function (a) { if (S) { a = a || {}, a.width && (K.w = Z(a.width, "x") - O - M), a.innerWidth && (K.w = Z(a.innerWidth, "x")), A.css({ width: K.w }), a.height && (K.h = Z(a.height, "y") - N - L), a.innerHeight && (K.h = Z(a.innerHeight, "y")); if (!a.innerHeight && !a.height) { var b = A.wrapInner("<div style='overflow:auto'></div>").children(); K.h = b.height(), b.replaceWith(b.children()) } A.css({ height: K.h }), X.position(K.transition === "none" ? 0 : K.speed) } }, X.prep = function (b) { function h() { K.h = K.h || A.height(), K.h = K.mh && K.mh < K.h ? K.mh : K.h; return K.h } function g() { K.w = K.w || A.width(), K.w = K.mw && K.mw < K.w ? K.mw : K.w; return K.w } if (!!S) { var c, d = K.transition === "none" ? 0 : K.speed; A.remove(), A = Y("LoadedContent").append(b), A.hide().appendTo(B.show()).css({ width: g(), overflow: K.scrolling ? "auto" : "hidden" }).css({ height: h() }).prependTo(t), B.hide(), a(R).css({ "float": "none" }), o && a("select").not(r.find("select")).filter(function () { return this.style.visibility !== "hidden" }).css({ visibility: "hidden" }).one(k, function () { this.style.visibility = "inherit" }), c = function () { function o() { n && r[0].style.removeAttribute("filter") } var b, c, g, h, i = y.length, k, l; !S || (l = function () { clearTimeout(W), C.hide(), ba(j, K.onComplete) }, n && R && A.fadeIn(100), D.html(K.title).add(A).show(), i > 1 ? (typeof K.current == "string" && E.html(K.current.replace("{current}", Q + 1).replace("{total}", i)).show(), G[K.loop || Q < i - 1 ? "show" : "hide"]().html(K.next), H[K.loop || Q ? "show" : "hide"]().html(K.previous), b = Q ? y[Q - 1] : y[i - 1], g = Q < i - 1 ? y[Q + 1] : y[0], K.slideshow && F.show(), K.preloading && (h = a.data(g, e).href || g.href, c = a.data(b, e).href || b.href, h = a.isFunction(h) ? h.call(g) : h, c = a.isFunction(c) ? c.call(b) : c, $(h) && (a("<img/>")[0].src = h), $(c) && (a("<img/>")[0].src = c))) : J.hide(), K.iframe ? (k = a("<iframe/>").addClass(f + "Iframe")[0], K.fastIframe ? l() : a(k).one("load", l), k.name = f + +(new Date), k.src = K.href, K.scrolling || (k.scrolling = "no"), n && (k.frameBorder = 0, k.allowTransparency = "true"), a(k).appendTo(A).one(m, function () { k.src = "//about:blank" })) : l(), K.transition === "fade" ? r.fadeTo(d, 1, o) : o()) }, K.transition === "fade" ? r.fadeTo(d, 0, function () { X.position(0, c) }) : X.position(d, c) } }, X.load = function (b) { var c, d, e = X.prep; T = !0, R = !1, P = y[Q], b || _(), ba(m), ba(i, K.onLoad), K.h = K.height ? Z(K.height, "y") - N - L : K.innerHeight && Z(K.innerHeight, "y"), K.w = K.width ? Z(K.width, "x") - O - M : K.innerWidth && Z(K.innerWidth, "x"), K.mw = K.w, K.mh = K.h, K.maxWidth && (K.mw = Z(K.maxWidth, "x") - O - M, K.mw = K.w && K.w < K.mw ? K.w : K.mw), K.maxHeight && (K.mh = Z(K.maxHeight, "y") - N - L, K.mh = K.h && K.h < K.mh ? K.h : K.mh), c = K.href, W = setTimeout(function () { C.show() }, 100), K.inline ? (Y().hide().insertBefore(a(c)[0]).one(m, function () { a(this).replaceWith(A.children()) }), e(a(c))) : K.iframe ? e(" ") : K.html ? e(K.html) : $(c) ? (a(R = new Image).addClass(f + "Photo").error(function () { K.title = !1, e(Y("Error").text("This image could not be loaded")) }).load(function () { var a; R.onload = null, K.scalePhotos && (d = function () { R.height -= R.height * a, R.width -= R.width * a }, K.mw && R.width > K.mw && (a = (R.width - K.mw) / R.width, d()), K.mh && R.height > K.mh && (a = (R.height - K.mh) / R.height, d())), K.h && (R.style.marginTop = Math.max(K.h - R.height, 0) / 2 + "px"), y[1] && (Q < y.length - 1 || K.loop) && (R.style.cursor = "pointer", R.onclick = function () { X.next() }), n && (R.style.msInterpolationMode = "bicubic"), setTimeout(function () { e(R) }, 1) }), setTimeout(function () { R.src = c }, 1)) : c && B.load(c, K.data, function (b, c, d) { e(c === "error" ? Y("Error").text("Request unsuccessful: " + d.statusText) : a(this).contents()) }) }, X.next = function () { !T && y[1] && (Q < y.length - 1 || K.loop) && (Q = Q < y.length - 1 ? Q + 1 : 0, X.load()) }, X.prev = function () { !T && y[1] && (Q || K.loop) && (Q = Q ? Q - 1 : y.length - 1, X.load()) }, X.close = function () { S && !U && (U = !0, S = !1, ba(k, K.onCleanup), z.unbind("." + f + " ." + p), q.fadeTo(200, 0), r.stop().fadeTo(300, 0, function () { r.add(q).css({ opacity: 1, cursor: "auto" }).hide(), ba(m), A.remove(), setTimeout(function () { U = !1, ba(l, K.onClosed) }, 1) })) }, X.element = function () { return a(P) }, X.settings = d, V = function (a) { a.button !== 0 && typeof a.button != "undefined" || a.ctrlKey || a.shiftKey || a.altKey || (a.preventDefault(), bc(this)) }, a.fn.delegate ? a(b).delegate("." + g, "click", V) : a("." + g).live("click", V), a(X.init) })(jQuery, document, this);





// SlideIO ... jQuery plugin for slide in and out slideshow
// Version 0.3.1
// April 28, 2011
//
// By Rob Watts, http://magicedit.com
// Provided under the MIT license. Feel free to use it however you like.
//
// Full documentation at: http://magicedit.com/SlideIOASimpleInOutS.cl
//
// Example:
// $("ul.slideIO").slideIO();
//
// To override defaults, pass in a defaults object:
// $("ul.slideIO").slideIO({
//    inSpeed: 100,
//    outSpeed: 100,
//    delay: 5000
// });



function swapSlide($slides, options) {
    var count = $slides.length;
    var newIndex = 0; // Index of new slide
    var $currentSlide = $slides.filter(".currentSlide");
    var currentIndex = 0;


    // See if a slide has been selected yet and set the index
    if ($currentSlide.length) {
        currentIndex = $slides.index($currentSlide);

        // Determine if on last slide, and if not, increment
        if (currentIndex < (count - 1))
            newIndex = currentIndex + 1;
        else {
            newIndex = 0;
        }
    }
    else {
        $currentSlide = $slides.eq(0);
    }

    $currentSlide
    .removeClass("currentSlide")
    .animate({
        left: options.left,
        top: options.top,
        opacity: options.outOpacity
    }, options.outSpeed, options.easeOut, function () {
        $slides
	  .eq(newIndex)
	  .addClass("currentSlide")
	  .delay(options.wait)
	  .animate({
	      left: "0",
	      top: "0",
	      opacity: options.inOpacity
	  }, options.inSpeed, options.easeIn);
    });

}


jQuery.fn.slideIO = function (options) {
    var $slides = this.children();
    var slideInterval;
    var settings;

    // Set up defaults
    settings = jQuery.extend({
        inSpeed: 200,                            // Time to slide in (ms)
        outSpeed: 200,                       // Time to slide out (ms)
        delay: 4000,                         // How long to display each slide (ms)
        showFirst: false,                    // Set whether the first slide appears immediately or slides in
        wait: 200,                           // Time to wait before sliding in
        easeIn: "swing",                     // Easing to use when moving the slide in
        easeOut: "swing",                    // Easing to use when moving the slide out
        inOpacity: 1,                        // Opacity of slide when shown
        outOpacity: 1,                       // Opacity of slide when hidden (should be > 0).
        mousePause: true,                    // Pause sliding when mouse is over the slide
        left: $slides.eq(0).css("left"),     // The "left" value when the slide is out
        top: $slides.eq(0).css("top")        // The "top" value when the slide is out
    }, options);

    if (settings.showFirst) {
        // Position the first panel
        $slides
      .first()
      .css({
          left: "0",
          top: "0",
          opacity: settings.inOpacity
      })
      .addClass("currentSlide");
    }

    if (!settings.showFirst)
        swapSlide($slides, settings);

    // Set up auto switching if more than one slide
    if ($slides.length > 1) {
        slideInterval = setInterval(function () {
            swapSlide($slides, settings);
        },
      settings.delay
      );

        if (settings.mousePause) {
            $slides.hover(
		    function () {
		        clearInterval(slideInterval);
		    },
		    function () {
		        slideInterval = setInterval(function () {
		            swapSlide($slides, settings);
		        },
			settings.delay
			);
		    });
        }
    }

};

