function openWindow(url,width,height) {day = new Date();id = day.getTime();window.open(url, id, "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left="+((screen.width - width)/2)+",top="+((screen.height - height)/2));return false;}
function externalLinks() {if (!document.getElementsByTagName) return;var anchors = document.getElementsByTagName("a");for (var i=0; i<anchors.length; i++) {var anchor = anchors[i];if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")anchor.target = "_blank";}}

$(document).ready(function() {
	browserDetection();
	fixIE6alphaTransparency();
	externalLinks();
});

function cncSlideshow(base, group, selector, timeGap) {
    if (($(base).length > 0) && ($(base + ' ' + group).children(selector).length > 1)) {
        $(base).data('flag', 0);
        setInterval("cascadeFadeInOut('" + base + "', '" + group + "', '" + selector + "')", timeGap);
    }
}

// See: http://jonraasch.com/blog/a-simple-jquery-slideshow
function cascadeFadeInOut(base, group, selector) {
    var numChildren = $(base).children(group).length;
    var selected = $(base).children(group).eq(parseInt($(base).data('flag')) % numChildren);
    $(base).data('flag', parseInt($(base).data('flag')) + 1);

    var $active = selected.children(selector + '.active');
    if ( $active.length == 0 ) $active = selected.children(selector + ':last');
    var $next =  $active.next().length ? $active.next() : selected.children(selector + ':first');
    $active.addClass('last-active');
    $next.css({
        opacity: 0.0
    })
    .addClass('active')
    .animate({
        opacity: 1.0
    }, 1000, function() {
        $active.removeClass('active last-active');
    });
}

$(document).ready(function(){
    cncSlideshow('#media-text', '.slides', '.oneslide', 9000);
    setTimeout("cncSlideshow('#media-1', '.slides', '.oneslide', 9000)", 3000);
    setTimeout("cncSlideshow('#media-2', '.slides', '.oneslide', 9000)", 6000);
    cncSlideshow('#media-secondary', '.slides', '.oneslide', 5000);
});

