﻿/* Author:

*/

function openFullScreenWindow(url, windowName) {
    var browserName = navigator.appName;
    var operatingSystem = navigator.platform;
    var version = parseFloat(navigator.appVersion);

    // Netscape check version 4.0+ on Mac
    if (browserName.indexOf("Netscape") != -1 && version >= 4.0 && operatingSystem.indexOf("Mac") != -1) {
        window.open(url, windowName, 'titlebar=no,top=0,left=0,width=' + window.screen.availWidth + ',height=' + window.screen.availWidth + ',screenX=0,screenY=0,top=0,left=0');

        // MSIE Mac check
    } else if (browserName.indexOf("Microsoft Internet Explorer") != -1 && operatingSystem.indexOf("Mac") != -1) {
        window.open(url, windowName, 'titlebar=no,top=0,left=0,width=' + window.screen.availWidth + ',height=' + window.screen.availWidth + ',screenX=0,screenY=0,top=0,left=0');

        // Netscape Mac check
    } else if (browserName.indexOf("Netscape") != -1 && operatingSystem.indexOf("Mac") != -1) {
        window.open(url, windowName, 'width=' + screen.width + ',height=' + screen.height + ',top=0,left=0');

        // MSIE Windows
    } else if (browserName.indexOf("Microsoft Internet Explorer") != -1 && operatingSystem.indexOf("Win") != -1) {
        window.open(url, windowName, 'titlebar=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,top=0,left=0,width=' + window.screen.availWidth + ',height=' + window.screen.availHeight + ',screenX=0,screenY=0,top=0,left=0');

        // Netscape Windows
    } else if (browserName.indexOf("Netscape") != -1 && operatingSystem.indexOf("Win") != -1) {
        window.open(url, windowName, 'width=' + screen.width + ',height=' + screen.height + ',top=0,left=0');

        // Default
    } else {
        window.open(url, windowName);
    }

    return false;
}

function saveBookmark(href, title) {
    if (document.all) {
        window.external.AddFavorite(href, title);
    } else if (window.sidebar) {
        window.sidebar.addPanel(title, href, '');
    } else {
        if (navigator.userAgent.indexOf("Mac OS X") != -1) {
            alert('Press ⌘+D to bookmark this page');
        } else {
            alert('Press Control+D to bookmark this page');
        }
    }
    return false;
}

function mediaMindTracker(activityId) {
    var ebRand = Math.random() + '';
    ebRand = ebRand * 1000000;
    var fileref = document.createElement('script')
    fileref.setAttribute("type", "text/javascript")
    fileref.setAttribute("src", 'http://bs.serving-sys.com/BurstingPipe/ActivityServer.bs?cn=as&ActivityID=' + activityId + '&rnd=' + ebRand);
    document.getElementsByTagName('head')[0].appendChild(fileref);
}
function Carousel($carousel) {
    this.init($carousel);
}
Carousel.prototype = {
    init: function($carousel) {
        var engine = this;
        this.$carousel = $carousel;
        this.$prevButton = this.$carousel.children(".prevButton");
        this.$nextButton = this.$carousel.children(".nextButton");
        this.$scrollContainer = this.$carousel.children(".scrollContainer");
        this.$scrollList = this.$scrollContainer.children("ul");
        this.scrollItemWidth = this.$scrollList.children("li").eq(0).width();
        this.currentOffset = Math.floor(this.$scrollList.position().left / this.scrollItemWidth);

        this.$prevButton.click(function(e) {
            // alert('this.$prevButton.click()');
            e.stopPropagation();
            e.preventDefault();
            engine.scrollPrevious();
        });

        this.$nextButton.click(function(e) {
            // alert('this.$nextButton.click()');
            e.stopPropagation();
            e.preventDefault();
            engine.scrollNext();
        });
    },

    scrollPrevious: function() {
        // alert('scrollPrevious()');
        this.$scrollList.animate({ left: 0 }, 500);
    },

    scrollNext: function() {
        // alert('scrollNext()');
        this.$scrollList.animate({ left: (this.$scrollContainer.width() - (this.$scrollList.width() + 20)) }, 500);
    }
}

$().ready(function($) {
    var $carousel = $(".carouselContainer");
    if ($carousel.length > 0) {
        window.carousel = new Carousel($carousel);
    }
    $stafTextArea = $(".rightContent .infoFields textarea");
    if ($stafTextArea.length == 1) {
        var stafDefaultText = $stafTextArea.text();
        $stafTextArea.focus(function() {
            if ($stafTextArea[0].value == stafDefaultText) {
                $stafTextArea[0].value = "";
            }
        })
        .blur(function() {
            if ($stafTextArea[0].value == "") {
                $stafTextArea[0].value = stafDefaultText;
            }
        });
    }
});
