function isIE6() {
    return $.browser.msie && $.browser.version=="6.0";
}

$(document).ready(function() {
    $("a[rel=new]").click(function(){
        window.open(this.href);
        return false;
    });
    
    if($('#slideshow-intro').length) {
        $('#slideshow-intro').cycle({
            fx: 'fade',
            speed: 1500
        });
    }
    
    if($('#slideshow-home').length) {
        $('#slideshow-home').cycle({
            fx: 'fade',
            speed: 1500
        });
    }
    
    // project slideshow
    if($('#project-slideshow').length) {
        var index = 0, hash = window.location.hash;
        if (hash) {
        	index = /\d+/.exec(hash)[0];
        	index = (parseInt(index) || 1) - 1; // slides are zero-based
        }

        $('#project-slideshow').cycle({
            fx: 'fade',
            next: '#project-slideshow',
            speed: 1500,
            timeout: 0,
            pager: '#pager',
            startingSlide: index,
            after: function(curr,next,opts) {
                var the_index = opts.currSlide + 1;
                window.location.hash = the_index;
            },
            prevNextClick: function(isNext, zeroBasedSlideIndex, slideElement) {
                var the_index = zeroBasedSlideIndex + 1;
                $('.project-description').hide();
                $('#project-description-' + the_index).animate({opacity: 'toggle'}, 1500);
            },
            pagerClick: function(zeroBasedSlideIndex, slideElement) {
                var the_index = zeroBasedSlideIndex + 1;
                $('.project-description').hide();
                $('#project-description-' + the_index).animate({opacity: 'toggle'}, 1500);
            }
        });
    }
    
    // newsletter field
    $('#newsletter-form div').TextfieldPlaceholders();
        
    // accordion animation : only on home page
    if($('#slideshow-home').length) {
        if(isIE6()) {
            $('.acitem').show();
        }
        else {
            function spreadAccordion() {
                items.eq(index).animate({height: 'toggle'}, 1150); 
                index++;
            }
            var speed  = 1155;
            var items  = $('.acitem');
            var length = items.length;
            var index = 0;
            var timer = setInterval(spreadAccordion, speed);
        }
    }
    
    if(!isIE6()) {
        $('ul.menu li.menu-parent > a').click(function() {
            $(this).parent().children('ul').slideToggle();
        });
    }
    
});