﻿try {
var pageTracker = _gat._getTracker("UA-15364108-1");
pageTracker._trackPageview();
} catch(err) {}

var tempvalue = '.txtvar';
var hotbutton = '';
$(document).ready(function () {
    $(document).mouseup(function () { hotbutton = ''; });
    settxtvalue();
    setchangestylebuttons();
    setexpandedbutton();
    sethideimagesbutton();
});

//---------------------
//set txt value methods
//---------------------
function settxtvalue() {
    var txtbox = $('.txturl input:text');
    if (txtbox != null) {
        var label = 'enter a url or search term here...';
        if (txtbox.val() == label || txtbox.val() == '') { addvalue(label, txtbox); };
        txtbox.focus(function () { if (txtbox.val() == label) { remvalue(txtbox); } });
        txtbox.blur(function () { if (txtbox.val() == '') { addvalue(label, txtbox); }; });
    }
}
function addvalue(label, ctrl) {
    ctrl.val(label);
    if (!ctrl.hasClass('txtlabel'))
        ctrl.addClass('txtlabel');
}
function remvalue(ctrl) {
    ctrl.val('');
    if (ctrl.hasClass('txtlabel'))
        ctrl.removeClass('txtlabel');
}

//------------------------
//configure toggle buttons
//------------------------
function setchangestylebuttons() {
    $('.btnstyleleft').click(function () { setexpandcssclass(this, 'btnstyleleftdown', 'btnstyleleft'); changestyle(false); });
    $('.btnstyleleft').mousedown(function () { hotbutton = 'btnstyleleft'; setexpandcssclass(this, 'btnstyleleft', 'btnstyleleftdown'); });
    $('.btnstyleleft').mouseleave(function () { setexpandcssclass(this, 'btnstyleleftdown', 'btnstyleleft'); });
    $('.btnstyleleft').mouseenter(function () { if (hotbutton == 'btnstyleleft') setexpandcssclass(this, 'btnstyleleft', 'btnstyleleftdown'); });
    $('.btnstyleright').click(function () { setexpandcssclass(this, 'btnstylerightdown', 'btnstyleright'); changestyle(true); });
    $('.btnstyleright').mousedown(function () { hotbutton = 'btnstyleright'; setexpandcssclass(this, 'btnstyleright', 'btnstylerightdown'); });
    $('.btnstyleright').mouseleave(function () { setexpandcssclass(this, 'btnstylerightdown', 'btnstyleright'); });
    $('.btnstyleright').mouseenter(function () { if (hotbutton == 'btnstyleright') setexpandcssclass(this, 'btnstyleright', 'btnstylerightdown'); });
}

function setexpandedbutton() {
    $('.btnexpandchecked, .btnexpandunchecked').click(function () { toggleitemvisibility('hidden', 'visible'); setexpandcssclass(this, 'btnexpandcheckeddown', 'btnexpandunchecked', 'btnexpanduncheckeddown', 'btnexpandchecked'); });
    $('.btnexpandchecked, .btnexpandunchecked').mousedown(function () { hotbutton = 'btnexpand'; setexpandcssclass(this, 'btnexpandchecked', 'btnexpandcheckeddown', 'btnexpandunchecked', 'btnexpanduncheckeddown'); });
    $('.btnexpandchecked, .btnexpandunchecked').mouseleave(function () { setexpandcssclass(this, 'btnexpandcheckeddown', 'btnexpandchecked', 'btnexpanduncheckeddown', 'btnexpandunchecked'); });
    $('.btnexpandchecked').mouseenter(function () { if (hotbutton == 'btnexpand') setexpandcssclass(this, 'btnexpandchecked', 'btnexpandcheckeddown', 'btnexpandunchecked', 'btnexpanduncheckeddown'); });
}

function changestyle(moveright) {
    var li = $('ul.themes li');
    var currentselection = li.filter('[title|=this]');
    currentselection.removeAttr('title');
    var currentindex = li.index(currentselection);
    var newindex = 0;
    if (moveright)
        newindex = (currentindex + 2 > li.length) ? 0 : currentindex + 1;
    else
        newindex = (currentindex == 0) ? li.length - 1 : currentindex - 1;
    $(li[newindex]).attr('title', 'this');
    $(tempvalue).val(newindex);
    var stylesheet = $('link.customstylesheet');
    var newstylesheethref = stylesheet.attr('href').substr(0, 18) + (newindex) + '/style.css';
    stylesheet.attr('href', newstylesheethref);
}

function toggleitemvisibility(state1, state2) {
    var visible = $('.' + state1);
    var hidden = $('.' + state2);
    visible.each(function (i) {
        $(visible[i]).attr('class', $(visible[i]).attr('class').replace(state1, state2));
    });
    hidden.each(function (i) {
        $(hidden[i]).attr('class', $(hidden[i]).attr('class').replace(state2, state1));
    });
}

function sethideimagesbutton() {
    $('.btnhideimageschecked, .btnhideimagesunchecked').click(function () { toggleitemvisibility('imagehidden', 'imagevisible'); setexpandcssclass(this, 'btnhideimagescheckeddown', 'btnhideimagesunchecked', 'btnhideimagesuncheckeddown', 'btnhideimageschecked'); });
    $('.btnhideimageschecked, .btnhideimagesunchecked').mousedown(function () { hotbutton = 'btnhideimages'; setexpandcssclass(this, 'btnhideimageschecked', 'btnhideimagescheckeddown', 'btnhideimagesunchecked', 'btnhideimagesuncheckeddown'); });
    $('.btnhideimageschecked, .btnhideimagesunchecked').mouseleave(function () { setexpandcssclass(this, 'btnhideimagescheckeddown', 'btnhideimageschecked', 'btnhideimagesuncheckeddown', 'btnhideimagesunchecked'); });
    $('.btnhideimageschecked').mouseenter(function () { if (hotbutton == 'btnhideimages') setexpandcssclass(this, 'btnhideimageschecked', 'btnhideimagescheckeddown', 'btnhideimagesunchecked', 'btnhideimagesuncheckeddown'); });
}

//------------------------
//set 2/4 way image toggle
//------------------------
function setexpandcssclass(classname, case1, case2) {
    setexpandcssclass(classname, case1, case2, case2, case1);
}
function setexpandcssclass(classname, case1, case2, case3, case4) {
    $(tempvalue).val($(classname).hasClass(case1) ? case2 : case4);
    $(classname).hasClass(case1) ? $(classname).attr("class", $(classname).attr("class").replace(case1, case2)) : $(classname).attr("class", $(classname).attr("class").replace(case3, case4));
}
