document.documentElement.className = "js";

$(document).ready(function () {
    if (document.getElementById('slideshow')) {
        $('#slideshow').slideshow();
    }
    //if (document.getElementById('features')) {
    //var fs = new features();
    var fs2 = new features2();
    //}
    if (document.getElementById('journeyTicker')) {
        var jt = new journeyTicker();
    }
    if (document.getElementById('fProgram')) {
        var fp = new fProgram();
    }
    if (document.getElementById('mainMenu')) {
        var mm = new mainMenu();
    }
    if (document.getElementById('dayPicker')) {
        var dp = new dayPicker();
    }
    if (document.getElementById('featuredArtist')) {
        $('#featuredArtist').slideshow({
            images: 'ul.images li',
            content: 'div.fArtistText li',
            leftButtonClass: 'fArtistLeft',
            rightButtonClass: 'fArtistRight',
            bulletsId: 'fArtistBullets',
            bulletsAppend: 'div.fArtistThumbs',
            animSpeed: 800,
            delay: 7000
        });
    }
    if (document.getElementById('ccStories')) {
        $('#ccStories').slideshow({
            images: 'ul.ccStoriesThumbs li',
            content: 'ul.ccStoriesText li',
            leftButtonClass: 'ccStoriesLeft',
            rightButtonClass: 'ccStoriesRight',
            bulletsId: 'ccStoriesBullets',
            animSpeed: 1000,
            delay: 7000
        });
    }
    if (document.getElementById('bannerShow')) {
        $('#bannerShow').slideshow({
            images: 'div.bannerShowImages li',
            content: 'div.bannerShowContent ul.text li',
            leftButtonClass: 'bannerShowLeft',
            rightButtonClass: 'bannerShowRight',
            bulletsId: 'bannerShowBullets',
            bulletsAppend: 'div.bannerShowControls'
        });
    }

    // signout button.
    signOut();

    changeRadioLink();

    // Perform modal setup.
    modals();

    // placeholder inputs
    $('input.placeholder,textarea.placeholder').placeholder();
    $('input.placeholderPassword').placeholderPassword();

    // Character Count Textarea
    $('textarea.charCount').each(function (i) {
        charCount(this, i);
    });
    if ($('textarea.prayers').length) {
        $('textarea.prayers').textLimit({
            limit: 350,
            remaining: $('p.charsRemaining span.charsRemaining')[0],
            allowOver: false
        });
    }
    if ($('textarea.comment').length) {
        $('textarea.comment').textLimit({
            limit: 250,
            remaining: $('span.commentCharsRemaining span.charsRemaining')[0],
            allowOver: false
        });
    }

    // Add Overlay Div
    if (!document.getElementById('overlay')) {
        $('body').append('<div id="overlay"></div>');
    }

    // Set Audio Popups
    setAudioPopups();

    var hash = window.location.hash;
    if (hash == '#login') {
        $('.signIn').click();
    } else if (hash == '#join') {
        $('.openModal').click();
    }
});

function setAudioPopups() {
    var a = jQuery('a.audiopopup');
    a.click(function (e) {
        e.preventDefault();
        var win = window.open(this.href, 'title', 'height = 300, width = 500', status = 1, scrollbars = 1);
        win.focus();
    });
}

window.onload = function () {
    if (document.getElementById('sisterSite')) {
        var ss = new sisterSite();
    }
    if (document.getElementById('actionNav')) {
        var an = new actionNav();
    }
}

function signOut() {
    $('.signOut').click(function (e) {
        var btnSignOut = $('a[id*="btnSignOut"]')[0];
        if (btnSignOut) {
            var href = btnSignOut.href.replace(window.location, "");
            if (href.length > 1) {
                eval(unescape(btnSignOut.href.replace(/^javascript:/i, "")));
            }
            else {
                btnSignOut.onclick();
            }
            return false;
        }
    });
}

function changeRadioLink() {
    $('.onair a').click(function (e) {
        var href = $(this).attr('href');
        openPlayerWindow(href);
        return false;
    });
}

function features2() {
    $('.homeFeatured .col').each(function () {
        var $features = $(this).find('.features>li');
        var timer;
        var current = 0;
        var isAnimating = false;
        var queue = -1;
        var clicked = false;
        var hover = false;

        var $bullets = '<span class="featureBulletsSpan">';
        $features.each(function (i) {
            if (i == 0) {
                $bullets += '<span class="active"></span>';
            }
            else {
                $bullets += '<span></span>';
            }
        });
        $bullets += '</span>';
        //$('#featureBullets').append($bullets);
        $(this).find('.featureBullets').append($bullets);
        //$bullets = $('#featureBulletsSpan span');
        $bullets = $(this).find('.featureBulletsSpan span');

        $features.eq(current).show();

        function fadeTo(num) {
            queue = -1;
            clearTimeout(timer);
            if (num >= $features.length) { num = 0; }
            if (num < 0) { num = $images.length - 1; }
            if (!isAnimating) {
                if (num != current) {
                    isAnimating = true;
                    $bullets.eq(current).removeClass('active');
                    $bullets.eq(num).addClass('active');
                    $features.eq(current).fadeOut(1000);
                    $features.eq(num).fadeIn(1000, function () {
                        current = num;
                        isAnimating = false;
                        if (queue > -1) {
                            fadeTo(queue);
                        }
                        else if (!clicked && !hover) {
                            startRotate(6000);
                        }
                    });
                }
                else {
                    queue = -1;
                }
            }
            else {
                queue = num;
            }
        }
        function startRotate(delay) {
            clearTimeout(timer);
            timer = setTimeout(function () { fadeTo(current + 1); }, delay);
        }

        $bullets.each(function (i) {
            $(this).click(function () {
                clicked = true;
                fadeTo(i);
            });
        });
        $features.hover(function () {
            hover = true;
            clearTimeout(timer);
        }, function () {
            hover = false;
            if (!clicked) {
                startRotate(4000);
            }
        });

        startRotate(6000);
    });
}

function journeyTicker() {
	var $wrap = $('#journeyTicker');
	var $ticker = $wrap.find('div.ticker');
	var halfWidth = $ticker.width();
	var current = 0;
	var timer;
	
	$wrap.append('<div class="tickerOverlay"></div>');
	$ticker.append($ticker[0].innerHTML).css({top:0,left:0,width:halfWidth*2});
	
	function tick() {
		$ticker.animate({left:-halfWidth},halfWidth*50,'linear',function() {
			$ticker.css({left:0});
			tick();
		});
	}
	
	tick();
}

function sisterSite() {
	var $ss = $('#sisterSite');
	var $dd = $ss.find('div.dropdown');
	
	var height = $dd.height() + 15;
	$dd.css({top:-height,visibility:'visible'});
	
	$ss.hover(function() {
		$ss.addClass('sisterSiteHover');
		$dd.stop().animate({top:0},500,'easeInOutSine');
	}, function() {
		$ss.removeClass('sisterSiteHover');
		$dd.stop().animate({top:-height},500,'easeInOutSine');
	});
}
function actionNav() {
	$('#actionNav>li').each(function() {
		var $an = $(this);
		var $dd = $an.find('div.dropdown');
		if($dd.length > 0) {
			var height = $dd.height() + 70;
			$dd.css({visibility:'visible'});
			
			$an.hover(function() {
				$an.stop().animate({height:height},500,'easeInOutSine');
			}, function() {
				$an.stop().animate({height:46},500,'easeInOutSine');
			});
		}
	});
}

function fProgram() {
	var $fp = $('#fProgram');
	var $li = $fp.find('li');
	if($li.length < 5) {
		return;
	}
	$fp.append('<span id="fProgramUp"></span><span id="fProgramDown"></span>');
	
	var current = 0;
	var $ul = $fp.find('ul');
	var $up = $('#fProgramUp');
	var $down = $('#fProgramDown');
	var stateChange = 0;
	
	function moveCurrent() {
		state();
		$ul.animate({top:-current*62},500,'easeInOutSine');
	}
	function state() {
		if(current === 0) {
			$up.css('cursor','default').animate({opacity:.50},300,'swing');
		}
		else if(stateChange === 0) {
			$up.css('cursor','pointer').animate({opacity:1},300,'swing');
		}
		if(current === $li.length-1) {
			$down.css('cursor','default').animate({opacity:.50},300,'swing');
		}
		else if(stateChange === $li.length-1) {
			$down.css('cursor','pointer').animate({opacity:1},300,'swing')
		}
		stateChange = current;
	}
	
	function addCurrent() {
		var num = current + 1;
		if(num >= $li.length) {
			return;
		}
		current = num;
		moveCurrent();
	}
	function subtractCurrent() {
		var num = current - 1;
		if(num < 0) {
			return;
		}
		current = num;
		moveCurrent();
	}
	
	$up.click(function() {
		subtractCurrent();
	});
	$down.click(function() {
		addCurrent();
	});
	$fp.mousewheel(function(e, delta) {
		e.preventDefault();
		if(delta < 0) {
			addCurrent();
		}
		else {
			subtractCurrent();
		}
	});
	
	state();
}

function mainMenu() {
	$('ul.mainMenu').find('li.open, li.closed').each(function() {
		var $li = $(this);
		$li.append('<span class="hotspot"></span>');
		/*var $hs = $li.find('span.hotspot');
		$hs.click(function() {
			if($li.hasClass('open')) {
				$li.removeClass('open');
				$li.addClass('closed');
			}
			else {
				$li.addClass('open');
				$li.removeClass('closed');
			}
		});*/
	});
}

function charCount(elem, iteration) {
	var $this = $(elem);
	$this.after('<div class="charCountLabel" style="width:'+$this.width()+'px"><span id="charCount'+iteration+'">500</span> Characters Remaining</div>');
	$this.textLimit({
		limit:500,
		remaining:document.getElementById('charCount'+iteration),
		allowOver:true
	});
}

function dayPicker() {
	var pos = $('#dayPicker li.active').position();
	var left = pos.left - 70;
	if(left < 0) { left = 0; }
	if(left > 358) { left = 358; }
	$('#dayPickerLabel').css('left',left);
}

function modals() {
    $('div.modal').each(function () {
        var $this = $(this);
        var attached = false;
        $this.find('a.closeVideoModal').click(function (e) {
            closeVideoModal();
            attached = true;
        });
        if (!attached) {
            $this.find('a.closeModal').click(function (e) {
                closeModal($this, e);
            });
        }
    });
    // Hook up 'open' functionality to modal links.
    $('a[href*="#"]').not('.customModalLink').each(function () {
        var $this = $(this);
        var rel = '';
        var href = $(this).attr('href');
        var modalId = href.substring(1 + href.indexOf('#')).trim();

        // Check to see if a video code is specified.
        if (modalId.match(/(^\d+$)/)) {
            rel = modalId;
            modalId = (document.getElementById('modalVideoPlayer')) ? 'modalVideoPlayer' : 'modalVideo';
        }

        // Attach click event if modal is available.
        if (document.getElementById(modalId)) {
            $(this).click(function (e) {
                e.preventDefault();
                if (rel && rel != '')
                    openVideoModal(rel);
                else
                    openModalById(modalId);
            });
        }
    });
}
function closeModal(modal, e) {
    if (e) {
        e.preventDefault();
    }
    //if ($.browser.msie && $.browser.version < 9) {
        modal.hide();
        hideOverlay();
    /*}
    else {
        modal.fadeOut(function () {
            hideOverlay();
        });
    }*/
}
function hideOverlay() {
    var areModalsOpen = false;
    $('div.modal').each(function () {
        if ($(this).css('display') == 'block') {
            $(this).css('z-index', '501');
            areModalsOpen = true;
        }
    });
    if (!areModalsOpen) {
        $('#overlay').fadeOut(function () {
            //   $(this).css('opacity', '.50');
        });
    }
    /*else if (areModalsOpen) {
        var numOfModals = $('div.modal').length;
        for (var i = 0; i < numOfModals; i++) {
            if ($('div.modal').eq(numOfModals - i).css('display') == 'block') {
                $('div.modal').eq(numOfModals - i).css('z-index', '510');
                break;
            }
        }
    }*/
}
function closeModalById(id) {
    var modal = $('#' + id);
    if (modal.length > 0) {
        closeModal(modal);
    }
}
function openModal(modal) {
    $('#overlay').show();
    $('#overlay').css({ display: 'block', opacity: .50 });

    // Push any currently open modals back.
    $('div.modal').each(function () {
        if ($(this) != modal && $(this).css('display') == 'block') {
            $(this).css('z-index', '449');
        }
    });

    // reset z-index
    modal.css('z-index', '510');

    // Set modal position to center of window.
    modal.show();

    // adjust size and position
    var mtop = ($(window).height() - modal.height()) / 2 + $(window).scrollTop();
    if (mtop < 0) { mtop = 0; }
    modal.css({ top: mtop });

    modal.trigger('modalOpen', null);

    /*var height = modal.show().height();
    var winHeight = $(window).height();
    var scrollTop = $(window).scrollTop();
    var top = (winHeight - height) / 2;
    if (top < 0) { top = 0; }
    top = top + scrollTop;
    modal.css('top', top);*/

}
function openModalById(id) {
    var modal = $('#' + id);
    if (modal.length > 0) {
        openModal(modal);
    }
}
function openVideoModal(rel) {
    var ifrm = '<iframe src="http://player.vimeo.com/video/' + rel + '?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="697" height="392" frameborder="0"></iframe>';
    var modalId = (document.getElementById('modalVideoPlayer')) ? 'modalVideoPlayer' : 'modalVideo';
    $('#' + modalId + ' div').html(ifrm);
    openModalById(modalId);
}
function closeVideoModal() {
    var modalId = (document.getElementById('modalVideoPlayer')) ? 'modalVideoPlayer' : 'modalVideo';
    closeModalById(modalId);
    $('#' + modalId + ' div').html('');
}

jQuery.extend( jQuery.easing,
{
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

(function($) {

$.fn.placeholder = function(defaultValue) {
	return this.each(function() {
		var val = this.defaultValue;
		if(defaultValue) { val = defaultValue; }
		if(this.value != val) {
		  $(this).removeClass('placeholder').addClass('userinput');
		}
		$(this).focus(function() {
			if(val == this.value) {
				this.value = "";
			}
			$(this).removeClass('placeholder').addClass('userinput');
		});
		$(this).blur(function() {
			if(this.value.replace(/\s/g,"").length < 1) {
				this.value = val;
				$(this).addClass('placeholder').removeClass('userinput');
			}
		});
	});
};

$.fn.placeholderPassword = function() {
	return this.each(function() {
		var ph = $(this);
		var pass = ph.next('input.passwordInput');
		ph.focus(function() {
			ph.hide();
			pass.show().focus();
		});
		pass.blur(function() {
			if(pass.val().replace(/\s/g,"").length < 1) {
				pass.hide();
				ph.show();
			}
		});
	});
};

$.fn.slideshow = function(options) {
	var opts = $.extend({}, $.fn.slideshow.defaults, options);
	
	return this.each(function() {
		var $home = $(this);
		var $images = $home.find(opts.images);
		if($images.length < 2) {
			return;
		}
		var $content = $home.find(opts.content);
		var current = 0;
		var timer;
		var isAnimating = -1;
		var queue = -1;
		var clicked = false;
		var hover = false;
		var switchDirection = false;
        var ie8orLess = $.browser.version < 9 && $.browser.msie;
		
		var width = $images.width();
		
		var $bullets = '<span class="'+opts.leftButtonClass+'"></span><span id="'+opts.bulletsId+'">';
		$images.each(function(i) {
			if(i == 0) {
				$bullets += '<span class="active"></span>';
			}
			else {
				$bullets += '<span></span>';
			}
		});
		$bullets += '</span><span class="'+opts.rightButtonClass+'"></span>';
		if(opts.bulletsAppend) {
			$home.find(opts.bulletsAppend).append($bullets);
		}
		else {
			$home.append($bullets);
		}
		$bullets = $('#'+opts.bulletsId+' span');
		
		function slideTo(num) {
			queue = -1;
			clearTimeout(timer);
			if(num >= $images.length) { num = 0; switchDirection = true; }
			if(num < 0) { num = $images.length - 1; switchDirection = true; }
			if(isAnimating == -1) {
				if(num != current) {
					isAnimating = num;
					$bullets.eq(current).removeClass('active');
					$bullets.eq(num).addClass('active');
					if((num > current && !switchDirection) || (num < current && switchDirection)) {
						switchDirection = false;
						slideDirection(num,-width,width);
					}
					else {
						switchDirection = false;
						slideDirection(num,width,-width);
					}
				}
				else {
					queue = -1;
				}
			}
			else {
				queue = num;
			}
		}
		function slideDirection(num,to,from) {
			$images.eq(current).animate({left:to},opts.animSpeed,opts.ease, function() {
				$(this).hide();
			});
			$images.eq(num).css({display:'block',left:from}).animate({left:0},opts.animSpeed,opts.ease,function() {
				current = num;
				isAnimating = -1;
				if(queue > -1) {
					slideTo(queue);
				}
				else if(!clicked && !hover) {
					startRotate(opts.delay);
				}
			});
            if(!ie8orLess){
			    $content.eq(current).fadeOut(opts.animSpeed - 200);
			    $content.eq(num).fadeIn(opts.animSpeed - 200);
		    }
            else {
                $content.eq(current).hide();
                $content.eq(num).show();
            }
        }
		function startRotate(delay) {
			clearTimeout(timer);
			timer = setTimeout(function() { slideTo(current + 1); },delay);
		}
		
		$bullets.each(function(i) {
			$(this).click(function() {
				clicked = true;
				slideTo(i);
			});
		});
		$home.find('span.'+opts.leftButtonClass).show().click(function() {
			clicked = true;
			if(isAnimating > -1) {
				slideTo(isAnimating - 1);
			}
			else {
				slideTo(current - 1);
			}
		});
		$home.find('span.'+opts.rightButtonClass).show().click(function() {
			clicked = true;
			if(isAnimating > -1) {
				slideTo(isAnimating + 1);
			}
			else {
				slideTo(current + 1);
			}
		});
		$home.hover(function() {
			hover = true;
			clearTimeout(timer);
		},function() {
			hover = false;
			if(!clicked) {
				startRotate(opts.delay - 2000);
			}
		});
		startRotate(opts.delay);
	});
};
$.fn.slideshow.defaults = {
	images: "ul.slideImages li",
	content: "ul.slideContent>li",
	leftButtonClass: "slideLeftButton",
	rightButtonClass: "slideRightButton",
	bulletsId: "slideBullets",
	bulletsAppend: null,
	animSpeed: 1200,
	delay: 6000,
	ease: 'easeInOutQuart'
};

$.fn.textLimit = function(options) {
    var opts = $.extend({}, $.fn.textLimit.defaults, options);

    return this.each(function() {
        
        var $this = $(this);
        if(!opts.allowOver) {
            $this.keydown(function(e) {
                if(this.value.length >= opts.limit) {
                    if(document.selection && document.selection.createRange().text.length > 0) {
                        return;
                    }
                    else if(this.selectionEnd - this.selectionStart > 0) {
                        return;
                    }
                    var key = e.which;
                    if(key > 46 || key == 13 || key == 32) {
                        e.preventDefault();
                    }
                }
            });
        }
        $this.bind('keyup onchange', function() {
            var val = clean(this.value);
            if(!opts.allowOver && val.length > opts.limit) {
                val = val.substr(0, opts.limit);
            }
            if(this.value != val) {
                this.value = val;
                this.scrollTop = this.scrollHeight;
            }
            setCount(val.length);
            setRemaining(val.length);
        });
		if(!$this.hasClass('placeholder')) {
			setTimeout(function() {
					setCount($this.val().length);
					setRemaining($this.val().length);
				}, 10);
		}
        
    });
    
    function setCount(length) {
        if(opts.count) {
            opts.count.innerHTML = length;
            adjustStyle(opts.count, length);
        }
    }
    function setRemaining(length) {
        if(opts.remaining) {
            opts.remaining.innerHTML = opts.limit - length;
            adjustStyle(opts.remaining, length);
        }
    }
    function adjustStyle(object, length) {
        if(length > opts.limit) {
            $(object).addClass(opts.overClass);
        }
        else {
            $(object).removeClass(opts.overClass);
        }
    }
    function clean(value) {
        return value.replace(opts.regex, '');
    }
};
$.fn.textLimit.defaults = {
    limit: 200,
    regex: /<[^ ]\/?[^>]+>/gi,
    allowOver: false,
    count: null,
    remaining: null,
    overClass: 'error'
};

/*! Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * Version: 3.0.2
 * 
 * Requires: 1.2.2+
 */

var types = ['DOMMouseScroll', 'mousewheel'];

$.event.special.mousewheel = {
	setup: function() {
		if ( this.addEventListener )
			for ( var i=types.length; i; )
				this.addEventListener( types[--i], handler, false );
		else
			this.onmousewheel = handler;
	},
	
	teardown: function() {
		if ( this.removeEventListener )
			for ( var i=types.length; i; )
				this.removeEventListener( types[--i], handler, false );
		else
			this.onmousewheel = null;
	}
};
$.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});
function handler(event) {
	var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
	
	event = $.event.fix(event || window.event);
	event.type = "mousewheel";
	
	if ( event.wheelDelta ) delta = event.wheelDelta/120;
	if ( event.detail     ) delta = -event.detail/3;
	
	// Add events and delta to the front of the arguments
	args.unshift(event, delta);

	return $.event.handle.apply(this, args);
}

})(jQuery);


function openPlayerWindow(href)
{
    window.open(href,'Radio_Player','width=450,height=245');
}
