/*********************************************************
 * Author: Marko Roeper <marko.roeper@googlemail.de>     *
 * All Rights Reserved                                   *
 * Latest update: 2010-02-19 12:23                       *
 *********************************************************/

$jQ.fn.reorder = function() {
 
  // random array sort from
  // http://javascript.about.com/library/blsort2.htm
  function randOrd() { return(Math.round(Math.random())-0.5); }
 
  return($jQ(this).each(function() {
    var $this = $jQ(this);
    var $children = $this.children();
    var childCount = $children.length;
 
    if (childCount > 1) {
      $children.remove();
 
      var indices = new Array();
      for (i=0;i<childCount;i++) { indices[indices.length] = i; }
      indices = indices.sort(randOrd);
      $jQ.each(indices,function(j,k) { $this.append($children.eq(k)); });
 
    }
  }));
}

$jQ(document).ready(function()
{
	// ... Ausführung sobald der HTML DOM geladen ist
});

$jQ(window).load(function()
{
	$jQ('#main').css('float','left');
	$jQ('#vcard_form').submit(function()
	{
		$jQ.post(
			'http://hertin.mr-seo.de/fileadmin/libs/sendcard.php',
			{email:$jQ('#vcard_email').val()},
			function(data){
				$jQ('#vcard_form').html('<br /><br />vCard versendet.');
			}
		);

		return false;
	});
	
	if($jQ('.scrollable').children().length>0) {
		$jQ('.scrollable').bind("contextmenu", function(e) {
                e.preventDefault();
        });
		var speed = 3000;
		if($jQ('.scrollable').parent().hasClass('portrait')) speed = 10000;
	
		if($jQ('.scrollable .items a').length>0) $jQ('.scrollable .items a').insertAfter($jQ('.scrollable .items .csc-textpic'));
		else if($jQ('.scrollable .items img').length>0) $jQ('.scrollable .items img').insertAfter($jQ('.scrollable .items .csc-textpic'));
		$jQ('.scrollable .items .csc-textpic').remove();
		$jQ('.scrollable .items .csc-textpic-clear').remove();
		$jQ('.scrollable .items').reorder();
		$jQ('.scrollable').scrollable(
		{
			size: 3,
			loop: true,
			next: '.scrollnext',
			prev: '.scrollprev'
		}).circular().autoscroll(
		{
			autoplay: true,
			steps: 1,
			interval: speed
		});
	}

	// ... Ausführung sobald ALLES geladen ist (inkl.externer Dateien)
	// vergrößerbare Bilder fuer die Lightbox einrichten
/*
	if($jQ('.gallery').children().length>0) {
		$jQ('.gallery dt a img').each(function()
		{
			var title = $jQ.trim($jQ(this).attr('title'));
			if(title!='')
			{
				if($jQ.trim($jQ(this).parent().attr('title'))!='')
				{
					$jQ(this).parent().attr('title', $jQ(this).parent().attr('title')+' | '+title);
				}
				else
				{
					$jQ(this).parent().attr('title', title);
				}
			}
		});
		$jQ('.gallery dt a').each(function()
		{
			var href = $jQ(this).attr('href');
			href_left = href.indexOf('file=')+5;
			href_right = href.indexOf('&width=');
			href = href.substring(href_left, href_right).replace(/\%2F/g,'/');
			$jQ(this).attr('href', href);
		});
		$jQ('.gallery dt a').removeAttr('onclick');
	
		$jQ(".gallery dt a").overlay({ 
	    	target: '#gallery', 
	    	expose: '#000'
		}).gallery({ 
		    speed: 500,
	    	opacity: 0.7,
	    	template: '<strong>$jQ{title}</strong> <span>Bild $jQ{index} von $jQ{total}</span>'
		});
	}
*/
	
});

