/**
 * ADACJP JavaScript core
 *
 * @author  Andreas Lechner <a.lechner@edelweiss72.de>
 *
 * Conventions:
 * Variables in camelCase
 * Classes in PascalCase
 * Function/Methods in camelCase
 */


// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
/*indow.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console) {
    arguments.callee = arguments.callee.caller;
    var newarr = [].slice.call(arguments);
    (typeof console.log === 'object' ? log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr));
  }
};*/

// make it safe to use console.log always
/*(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());*/




/**
 * @Namespace ADACJP
 */
ADACJP = {};


// showBox, Ändert auch class
ADACJP.showBox = function (divname,nr,count) {
    for(i=1;i<=count;i++) {
        divHide=divname+'_'+i;
        setClass=divname+'_switch_'+i;
        $('#'+divHide).hide();
        document.getElementById(setClass).className='';
    }

    divShow=divname+'_'+nr;
    setClassActive=divname+'_switch_'+nr;
    $('#'+divShow).show();
    ;
    document.getElementById(setClassActive).className='active';
}

function write_movie_generic(url,width,height) {

    elementNode = document.getElementById("movie");
    elementNode.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" title="" width="'+width+'" height="'+height+'" align="center"><param name="movie" value="'+url+'" /><param name="quality" value="high"><param name="bgcolor" value="#DEDBD4"><param name="wmode" value="transparent"><param name="menu" value="false"><param name="play" value="true"><embed src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" bgcolor="#DEDBD4" menu="false" play="true" wmode="transparent" width="'+width+'" height="'+height+'" align="center"></object>';

}

//wird für popup-Modul in easyred benötigt
function openPopup(URL,popname,W,H,scroll,rezisable,X,Y) {
    var URL,popname,W,H,scroll,rezisable,X,Y;
    if (!popname) {
        popname='popup';
    }
    if (!W) {
        W=520;
    }
    if (!H) {
        H=460;
    }
    if (!scroll) {
        scroll=0;
    }
    if (!rezisable) {
        rezisable=0;
    }
    if (!X) {
        X=screen.width/2-(W/2);
    }
    if (!Y) {
        Y=screen.height/2-(H/2)-20;
    }
    properties = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scroll+",resizable="+rezisable+",";
    properties += "width="+W+",height="+H+",left="+X+",top="+Y;
    popwin=window.open(URL,popname,properties);
    popwin.focus();
}

var S = {}

S.testCookies = function(anker){
    var _$root = $(anker);

    this.setCookie = function(callback){
        $.post("/___easyred/easyred_project/templates/inc_functions/functions_setcookietest.php", {}, function(data){
            if(typeof callback == 'function'){
                callback();
            }
        });
    }

    this.getReq = function(){
        $.post("/___easyred/easyred_project/templates/inc_functions/functions_cookietest.php", {
            test : "test"
        }, function(data){
            if(data == 0){
                writeHint();
            };
        });
    }

    var writeHint = function(){
        var container = $("<div></div>").appendTo(_$root);
        var image = $("<span>&nbsp;</span>").appendTo(container);
        var text = $("<p id='cookieHint'>In deinen Browsereinstellungen sind Cookies deaktiviert. Damit du dich am jungen Portal anmelden kannst, muss dein Browser Cookies akzeptieren.</p>").appendTo(container);

        image.bind("mouseenter", function(){
            text.fadeIn(250);
        }).bind("mouseleave",function(){
            text.fadeOut(250);
        })

        container.css({
            position: "absolute",
            top: "-1px",
            left: "-240px",
            width: "auto"
        });
        image.css({
            backgroundImage: "url(/_common/img/sprites/sprite_icons.png)",
            display: "block",
            width : "15px",
            height: "15px",
            position: "absolute",
            backgroundPosition: "0px -1900px",
            top: "1px",
            left: "284px"
        })
        text.css({
            padding: "10px 13px 10px 13px",
            width: "260px",
            position: "absolute",
            border: "1px solid #9C9899",
            top: "10px",
            left: "90px",
            backgroundColor: "#fff",
            display: "none"
        })
    }

}

S.zoomImageCoda = function(slider){
    var root = $(slider).parent().parent();
    var zoomImages = $(slider).find(".jsZoom");
    var zoomController = zoomImages.parent().children("img:not(.jsZoom)");
    zoomController.css("cursor","pointer");

    $.each(zoomController, function(i){
        $(this).click(function(){
            sperre = false;
            var imageWrap = $("<div></div>").appendTo(root);
            var close = $("<div></div>").appendTo(imageWrap);
            var image = $(zoomImages.eq(i).clone(true)).appendTo(imageWrap);

            if(image.width() > 900){
                image.width("900px");
            }

            imageWrap.css({
                position: "absolute",
                top: "-5%",
                left: "-5%",
                zIndex: 2
            });

            close.css({
                fontSize: "10px",
                position: "absolute",
                right: "0px",
                top: "0px",
                zIndex: 2,
                cursor: "pointer",
                backgroundColor: "#dedbd4"
            });

            close.text("Schließen");

            image.mouseover(function(){
                sperre = true;
            }).mouseout( function(){
                sperre = false;
            });
            image.fadeIn(750, function(){
                $("body").bind("click", function(){
                    if(!sperre){
                        close.fadeOut(750);
                        image.fadeOut(750, function(){
                            imageWrap.remove();
                        })
                    }
                });
            });
        })
    });
}

S.tabSwitch = function(self, tab, anker){
    var tab = $(tab).eq(0);
    var anker = '#'+anker;
    var $this = $(self).find("a").eq(0);

    $this.click( function(){
        tab.click();
        location.href = anker;
    });

}
