﻿var BaseUI =
{
	Initialize: function(){
		jQuery('div.share button').click(function(e)
		{
			e.preventDefault()
		})
		
		jQuery('div.share button').hover(function(){
			jQuery(this).siblings('div.share-widget').show()
			console.log('hoverin')
		}, function(){
			jQuery(this).siblings('div.share-widget').hide()
		})
		
		if (jQuery('div.slideshow-customize').length) {
			jQuery('div.slideshow-customize').cycle(
			{
				timeout: 6000,
				speed: 1000,
				prev: ".customize-prev",
				next: ".customize-next"
			})
		}
		
		jQuery('div.share-widget').hover(function(){
			jQuery(this).show()
		}, function() {
			jQuery(this).hide()
		})
	},
    AddOption: function(sel, text, value, tag)
    { 
        var theOption = document.createElement('option')

        theOption.text  = text
        theOption.value = value
        theOption.Tag   = tag

        sel.options.add(theOption, -1)
    },
    GetSelectedOption: function(sel)
    {
        if (sel.selectedIndex >= 0)
        {
            return sel.options[sel.selectedIndex]
        }
        
        return null
    },
    RemoveAllOptions: function(sel)
    {
        while (sel.options.length > 0)
        {
            sel.remove(sel.options[0])
        }
    },
    PopulateSelect: function(anArray, aSelect)
    {
        BaseUI.RemoveAllOptions(aSelect)
        
        for (var i = 0; i < anArray.length; i++)
        {
            var theItem = anArray[i]
            
            if (typeof theItem == 'string')
            {
                BaseUI.AddOption(aSelect, theItem, theItem, theItem)
            }
            else
            {
                BaseUI.AddOption(aSelect, theItem.T, theItem.V, theItem)
            }
        }
    },
    SelectOptionByValue: function(aSelect, aValue)
    {
        for (var i = 0; i < aSelect.options.length; i++)
        {
            var theOption = aSelect.options[i]
            
            if (theOption.value == aValue)
            {
                theOption.selected = true
            }
        }
    },
    AddMask: function(el, msk, styleclass, maskstyleclass)
    {
        el.Mask           = msk
        el.StyleClass     = styleclass
        el.MaskStyleClass = maskstyleclass

        if (el.value == '') 
        {
            el.value = el.Mask
            BaseUI.SetClass(el, el.MaskStyleClass)
        }
        else
        {
            BaseUI.SetClass(el, el.StyleClass)
        }
        
        jQuery(el).focus(function()
        {
            if (this.value == this.Mask)
            {
                this.value = ''
                BaseUI.SetClass(this, this.StyleClass)
            }
        })
        jQuery(el).blur(function()
        {
            if (this.value.trim() == '')
            {
                this.value = this.Mask
                BaseUI.SetClass(this, this.MaskStyleClass)
            }
        })
    },
    SetClass: function(el, className)
    {
        if (el)
        {
            try
            {
                if ((jQuery.browser.msie) && (jQuery.browser.version < 8))
                {
                    el.className = className
                }
                else
                {
                    el.setAttribute("class", className)
                }
            }
            catch (e) {}
        }
    }
}

jQuery(document).ready(BaseUI.Initialize)
