// <![CDATA[
/*
(c)copyright 2008 Medial - Gesellschaft für digitale Medien mbH
Letzter Bearbeitungstand: 21.04.2008
Author: Torsten Jaeschke
*/
// --------------------------------------------------------------------------------------------------------
/*
function awardJS()
Award-Objekt
*/
function awardJS() {
    this.id=0;
    this.awards = [];
    this.mouseInLeft = "";
    this.mouseInRight = "";
    this.mouseOutLeft = "";
    this.mouseOutRight = "";
    this.init = function(url, awId){
            var aw = this;
            this.id = awId;
            $.get(url, function(xml){ 
                aw.loadAwards(xml); 
            });
            $("#sl"+awId).click(function(){ $(this).unbind("click");aw.slideLeft();  });
            $("#sr"+awId).click(function(){ $(this).unbind("click");aw.slideRight(); });
            $("#sl"+awId).bind('mouseenter',function(e) {
                aw.mouseOutLeft = $(this).attr("src");
                $(this).attr("src",aw.mouseInLeft);
            });
            $("#sl"+awId).bind('mouseleave',function(e) {
                $(this).attr("src",aw.mouseOutLeft);
            });            
            $("#sr"+awId).bind('mouseenter',function(e) {
                aw.mouseOutRight = $(this).attr("src");
                $(this).attr("src",aw.mouseInRight);
            });
            $("#sr"+awId).bind('mouseleave',function(e) {        
                $(this).attr("src",aw.mouseOutRight);
            });            
            
        };
    this.loadAwards = function(xml) {
            var awAr = this.awards;
            $("award",xml).each(function(){
                awAr.push(this);
            });
            this.showAwards();
        };
    this.showAwards=function() {
            var info = this.awards;
            var areaId = "#imgArea"+this.id;
            var awId = this.id;
            $(areaId).text("");
            $.each(info, function(i) {
                var inline = "";
                var imgId = $("awardID",this).text()+awId;
                var image = "<img class='awardicon' id='"+imgId+"' src='"+$("awardPath",this).text()+"'>";
                $(areaId).append(image);
                var uHref = $("awardHREF",this).text();
                if(i == 1) {
                    setFishEye(imgId, uHref);
                }
            });
        };
    this.slideRight=function() {
            var aw = this;
            var awAr = this.awards;
            var areaId = "#imgArea"+this.id;
            var awId = this.id;
            var fishEyeElemId = "#"+$("awardID",awAr[1]).text()+awId;
            var firstElem = awAr.shift();
            var elemId = "#"+$("awardID",firstElem).text()+awId;
            awAr.push(firstElem);
            var blubb = $(areaId + " > .awardicon");
            var appendent = $(blubb[0]).clone();
            var image = "<img class='awardicon' id='"+elemId+"' src='"+$("awardPath",firstElem).text()+"'>";
            $(fishEyeElemId).removeClass("fisheye").unbind("click").animate({width:"20px", height:"20px",marginTop:"19px", marginLeft:"15px",marginBottom:"19px", marginRight:"12px"}, "slow", function() {
                $(areaId).append(appendent).attr("style", "right:0;").animate( { right:"44px"}, "normal", function(){
                    $(blubb[0]).remove();
                    $(areaId).removeAttr("style");
                    var fe = $(areaId + " > .awardicon");
                    setFishEye($(fe[1]).attr("id"), $("awardHREF",awAr[1]).text());
                    $("#sr"+awId).click(function(){ $(this).unbind("click");aw.slideRight(); });
                });
            });
        };
    this.slideLeft=function() {
            var aw = this;
            var awAr = this.awards;
            var awId = this.id;
            var areaId = "#imgArea"+this.id;
            var fishEyeElemId = "#"+$("awardID",awAr[1]).text()+awId;
            var firstElem = awAr.pop();
            var elemId = "#"+$("awardID",firstElem).text()+awId;
            awAr.unshift(firstElem);
            var blubb = $(areaId + " > .awardicon");
            var remElem = $(blubb[$(blubb).length-1]);
            var prependent = $(blubb[$(blubb).length-1]).clone();
            var image = "<img class='awardicon' id='"+elemId+"' src='"+$("awardPath",firstElem).text()+"'>";
            $(fishEyeElemId).removeClass("fisheye").unbind("click").animate({width:"20px", height:"20px",marginTop:"19px", marginLeft:"15px",marginBottom:"19px", marginRight:"12px"}, "slow", function() {
                $(areaId).prepend(prependent).attr("style", "left:-44px;").animate( { left:"0px"}, "normal", function(){
                    $(remElem).remove();
                    $(areaId).removeAttr("style");
                    var fe = $(areaId + " > .awardicon");
                    setFishEye($(fe[1]).attr("id"), $("awardHREF",awAr[1]).text());
                    $("#sl"+awId).click(function(){ $(this).unbind("click");aw.slideLeft(); });
                });
            });
        };
        
    function setFishEye(imgId, uHref) {
        $("#"+imgId).addClass("fisheye").animate( { width:"55px", height:"55px",marginTop:"5px", marginLeft:"0",marginBottom:"2px", marginRight:"0"}, "slow");
        if(uHref != "") {
            $("#"+imgId).click(function(){
                location.href = uHref;
                //fenster = window.open(uHref, "Awardpopup", "width=600,height=400,status=yes,scrollbars=yes,resizable=yes");            
                //fenster.focus();                    
            });
        }
    }
}
// ]]>