

jQuery(function() 
{
	$("a.poppy").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'frameWidth': 850,
		'frameHeight':550
	}); 
});

(function($) {

  $.fn.expander = function(options) {

    var opts = $.extend({}, $.fn.expander.defaults, options);
    var delayedCollapse;
    return this.each(function() {
      var $this = $(this);
      var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
     	var cleanedTag, startTags, endTags;	
     	var allText = $this.html();
     	var startText = allText.slice(0, o.slicePoint).replace(/\w+$/,'');
     	startTags = startText.match(/<\w[^>]*>/g);
   	  if (startTags) {startText = allText.slice(0,o.slicePoint + startTags.join('').length).replace(/\w+$/,'');}
   	  
     	if (startText.lastIndexOf('<') > startText.lastIndexOf('>') ) {
     	  startText = startText.slice(0,startText.lastIndexOf('<'));
     	}
     	var endText = allText.slice(startText.length);    	  
     	// create necessary expand/collapse elements if they don't already exist
   	  if (!$('span.details', this).length) {
        // end script if text length isn't long enough.
       	if ( endText.replace(/\s+$/,'').split(' ').length < o.widow ) { return; }
       	// otherwise, continue...    
       	if (endText.indexOf('</') > -1) {
         	endTags = endText.match(/<(\/)?[^>]*>/g);
          for (var i=0; i < endTags.length; i++) {

            if (endTags[i].indexOf('</') > -1) {
              var startTag, startTagExists = false;
              for (var j=0; j < i; j++) {
                startTag = endTags[j].slice(0, endTags[j].indexOf(' ')).replace(/(\w)$/,'$1>');
                if (startTag == rSlash(endTags[i])) {
                  startTagExists = true;
                }
              }              
              if (!startTagExists) {
                startText = startText + endTags[i];
                var matched = false;
                for (var s=startTags.length - 1; s >= 0; s--) {
                  if (startTags[s].slice(0, startTags[s].indexOf(' ')).replace(/(\w)$/,'$1>') == rSlash(endTags[i]) 
                  && matched == false) {
                    cleanedTag = cleanedTag ? startTags[s] + cleanedTag : startTags[s];
                    matched = true;
                  }
                };
              }
            }
          }

          endText = cleanedTag && cleanedTag + endText || endText;
        }
     	  $this.html([
     		startText,
     		'<span class="read-more">',
     		o.expandPrefix,
       		'<a href="#">',
       		  o.expandText,
       		'</a>',
        '</span>',
     		'<span class="details">',
     		  endText,
     		'</span>'
     		].join('')
     	  );
      }
      var $thisDetails = $('span.details', this),
        $readMore = $('span.read-more', this);
   	  $thisDetails.hide();
 	    $readMore.find('a').click(function() {
 	      $readMore.hide();

 	      if (o.expandEffect === 'show' && !o.expandSpeed) {
          o.beforeExpand($this);
 	        $thisDetails.show();
          o.afterExpand($this);
          delayCollapse(o, $thisDetails);
 	      } else {
          o.beforeExpand($this);
 	        $thisDetails[o.expandEffect](o.expandSpeed, function() {
            $thisDetails.css({zoom: ''});
            o.afterExpand($this);
            delayCollapse(o, $thisDetails);
 	        });
 	      }
        return false;
 	    });
      if (o.userCollapse) {
        $this
        .find('span.details').append('<span class="re-collapse">' + o.userCollapsePrefix + '<a href="#">' + o.userCollapseText + '</a></span>');
        $this.find('span.re-collapse a').click(function() {

          clearTimeout(delayedCollapse);
          var $detailsCollapsed = $(this).parents('span.details');
          reCollapse($detailsCollapsed);
          o.onCollapse($this, true);
          return false;
        });
      }
    });
    function reCollapse(el) {
       el.hide()
        .prev('span.read-more').show();
    }
    function delayCollapse(option, $collapseEl) {
      if (option.collapseTimer) {
        delayedCollapse = setTimeout(function() {  
          reCollapse($collapseEl);
          option.onCollapse($collapseEl.parent(), false);
          },
          option.collapseTimer
        );
      }
    }
    function rSlash(rString) {
      return rString.replace(/\//,'');
    }    
  };
    // plugin defaults
  $.fn.expander.defaults = {
    slicePoint:       100,  
    widow:            4,  
    expandText:       'read more', 
    expandPrefix:     '&hellip; ',
    collapseTimer:    0, 
    expandEffect:     'fadeIn',
    expandSpeed:      '',   
    userCollapse:     true, 
    userCollapseText: '[collapse expanded text]',  
    userCollapsePrefix: ' ',
    beforeExpand: function($thisEl) {},
    afterExpand: function($thisEl) {},
    onCollapse: function($thisEl, byUser) {}
  };
})(jQuery);

function newPnInf(DOM)
{
	open_window(DOM + '/index.php?p=misc&do=pnpop','pn',500,300,0);
}

function open_window(meineSeite,meinName,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
	Fenster = window.open(meineSeite,meinName,settings);
}

function elemX (element) {
	var x = 0;
	while (element) {
		x += element.offsetLeft;
		element = element.offsetParent;
	}
	return x;
}

function elemY (element) {
	var y = 0;
	while (element) {
		y += element.offsetTop;
		element = element.offsetParent;
	}
	return y;
}

function getWidth (element) {
	return element.offsetWidth;
}

function getHeight (element) {
	return element.offsetHeight;
}

function elemObj(elementId) {
	if (document.all)
		return document.all[elementId];
	else if (document.getElementById)
		return document.getElementById(elementId);
	else
		return null;
}

function switch_img(DATA,ID){
	document.getElementById('img').innerHTML = '<a href="javascript:ImgBrowser(' + ID + ');"><img src="' + DATA + '" alt="" border="0" /></a>';
}

function switch_img_popup(DATA){
	//alert(DATA);
	document.getElementById('img').innerHTML = '<img src="' + DATA + '" alt="" border="0" />';
}

function ImgBrowser(ID,DOM){
	window.open(DOM + 'index.php?p=misc&do=shopimgages&prodid=' + ID, ID, 'width=700,height=600,top=0,left=0');
}

function mergeProduct(ID,RED,CID,DOM){
	window.open(DOM + 'index.php?redir=1&p=misc&do=mergeproduct&prodid=' + ID + '&red=' + RED + '&cid=' + CID, 'merge_win', 'scrollbars=1,width=950,height=750,top=0,left=0');
}


function paymentInf(ID,DOM){
	window.open(DOM + 'index.php?p=misc&do=payment_info&id=' + ID,'paymentinf','width=800,height=550,top=0,left=0,scrollbars=1');
}


function check_search_field(){
	if(document.getElementById('s_x').value != '' && document.getElementById('s_x').value.length < 2){
		document.getElementById('small_search_hidden_div').style.display='';
		return false;
	} else {
		document.getElementById('small_search_hidden_div').style.display='none';
	}	
}

function openAdmin(DOM){
	open_window(DOM + 'admin/index.php','Admin',980,780,1);
}

function getActiveText(msg){
	selectedText = (document.all) ? document.selection.createRange().text : window.getSelection();if (msg.createTextRange) msg.caretPos = document.selection.createRange().duplicate();return true;
}

function unametofield(theuser) {
	opener.document.f.tofromname.value = '' + theuser + '';
	window.close();
}

function add_code(NewCode){
    document.f.text.value += NewCode;
    document.f.text.focus();
}


