document.getElementsByTagName('html')[0].className += ' js';

//global vars
var media;

(function($){
    //open external links in a new window
    var hostname = window.location.hostname;
    hostname = hostname.replace("www.", "").toLowerCase();
    
    $('a').each(function(){
        if (this.href.indexOf("http://") != -1 && this.href.indexOf(hostname) == -1) {
            this.target = "_blank";
            this.className += " external";
        }
    });
    
    // media
    $('a.video').media();
    
    $('a.audio').click(function(){
        media = this.href;
        var newWin = window.open('http://' + document.domain + '/wp-content/themes/coralie/popup.html', 'audio-player', 'width=400,height=20,scrollbars=no,toolbar=no,resizable=no,menubar=no');
        return false;
    });
    
    // slideshow general config
    $('.slideshow').cycle({
        timeout: 5000
    });
    
    //clear form inputs
    $('#connect :text').focus(function(){
        if (this.value == this.defaultValue) {
            this.value = '';
        }
    });
    
    $('#connect :text').blur(function(){
        if (this.value === '') {
            this.value = this.defaultValue;
        }
    });
    
    // gallery
    $('#carousel a').each(function(){
        var $this = $(this), $container = $('#fullPic'), $img = $container.children(), tmpImg = new Image();
        tmpImg.src = $this.attr('href');
        
        $this.hover(function(){
            $('#carousel a').css({
                opacity: 0.4
            });
            $this.css({
                opacity: 1
            });
            if ($img.attr('src') !== tmpImg.src) {
                $container.attr({
                    'href': $this.attr('href'),
                    'title': $this.attr('title')
                }).html(tmpImg);
            }
            $container.stop().animate({
                height: tmpImg.height + 'px'
            }, 1500);
        }, function(){
        });
    });
    $('#carousel a').css({
        opacity: 0.4
    });
    $('#carousel li:first-child a').css({
        opacity: 1
    });
    
    // carousel
    $('#carousel').jcarousel({
        scroll: 2,
        animation: 800
    });
})(jQuery);
