/*
#---------------------------------------------------------------------------
# Copyright   : rexx systems GmbH, 20097 Hamburg, Heidenkampsweg 101
#               Veränderung oder Nutzung der Scripte/Anwendung ist nur mit
#               schriftlicher Genehmigung der rexx systems GmbH gestattet.
#---------------------------------------------------------------------------
*/

articleJs = (function() {

    return {
        /* Array mit articlePicture-Objekten fuer alle Bilder des Artikels */
        pictures: [],

        /* Seiten-Initialisierung, gerufen wenn $(document).ready() */
        init: function() {
        },

        /* 
         * tauscht das Thumbnail mit einem kleinen Vorschaubild
         * gerufen bei onClick auf ein kleines Vorschaubild
         *
         * @param int pos Position des geklickten Vorschaubildes, beginnt bei 1,
         *                das Thumbnail hat Position 0
         */
        thumbUp: function(pos) {
            var pic   = this.getPicture(pos)
            var thumb = this.getPicture(0);

            var oPic = $('#previewPicture' + pos)[0];
            var oPicLink = $('#pictureLink')[0];
            var oThumb = $('#artikelBild')[0];
            oThumb.src    = pic.thumbUrl;
            oThumb.width  = pic.thumbWidth;
            oThumb.height = pic.thumbHeight;
            oThumb.alt    = pic.text;
            oThumb.title  = pic.text;
            $('#pictureText')[0].innerHTML = pic.text;
            oPicLink.href = pic.fullUrl;
            oPicLink.title = pic.text;

            oPic.src    = thumb.prevUrl;
            oPic.width  = thumb.prevWidth;
            oPic.height = thumb.prevHeight;
            oPic.alt    = thumb.text;
            oPic.title  = thumb.text;
            $('#imageText' + pos)[0].innerHTML = thumb.text;

            thumb.position = pic.position;
            pic.position = 0;
        },

        /*
         * liefert das articlePicture-Objekt fuer eine Bild-Position
         * 
         * @param int pos Bild-Position
         * @return object articlePicture
         */
        getPicture: function(pos) {
            for (var idx=0; idx<this.pictures.length; idx++) {
                if (this.pictures[idx].position == pos) {
                    return this.pictures[idx];
                }
            }
            return this.pictures[0];
        },
        
        getLayerContent: function(kennung, size) {

	       $.ajax({
    	      type: 'GET',
    		  url: '../inc/functions/xml_http_requests.php',
    		  data: {
                 f : 'cust_get_layer_content',
                 p0: kennung,
                 sid: mySession
               },

               success: function(phpData) {

                  if($.browser.version < 7 && $.browser.msie){
                     $("#articleLayer").show();
                     $("#articleLayerContent").html(phpData);
                     
                  } else {
               
        	         $('#rexxJqmClose').show();
        	
                    j$('.jqmWindow').jqm({overlay: 0}).jqDrag('.jqmDrag').jqmShow();
        	        j$('.jqmWindow').css('opacity', 1);

    		         $('#rexxJqmClose').click( function (){ j$('.jqmWindow').jqmHide(); } );
                     $('.jqmWindowContent').html(phpData); 
                     
                     if(size){
                        $("#contentLayer").css({"height" : size});
                        
                     }
                     
                     if($.browser.version == 7 && $.browser.msie){
                        $("#contentLayer").css({"width" : size-40});
                        $(".jqmContent").css({"width" : size});
                        $(".jqmWindow").css({"width" : size});
                     }
               
                  } 	

               }
    	   });
        
        },
        
        closeArticleLayer: function() {
              $("#articleLayer").hide();     
        }
    };
})();


/*
 * Seiten-Initialisierung aufrufen
 */
$(document).ready(function(){
	articleJs.init();
});


/*
 * articlePicture Objekt, wird fuer alle Bilder via php instanziert
 * und in articleJs.pictures abgelegt
 *
 * @param ...
 */
function articlePicture(position, text, thumbUrl, thumbWidth, thumbHeight, prevUrl, prevWidth, prevHeight, fullUrl) {
    this.position    = position;
    this.text        = text;
    this.thumbUrl    = thumbUrl;
    this.thumbWidth  = thumbWidth;
    this.thumbHeight = thumbHeight;
    this.prevUrl     = prevUrl;
    this.prevWidth   = prevWidth;
    this.prevHeight  = prevHeight;
    this.fullUrl     = fullUrl;
}

