


// round bottom corners 
// DD_roundies.addRule('.rounded_button', '0 0 7px 7px', true);
DD_roundies.addRule('.round_border_all', '7px 7px 7px 7px', true);
DD_roundies.addRule('.rote_flagge', '0 7px 7px 0', true);
DD_roundies.addRule('.graue_flagge', '0 7px 7px 0', true);
DD_roundies.addRule('.silber_flagge', '0 7px 7px 0', true);

// jQuery konfilkt mit mootools

var $j = jQuery.noConflict();

// image preloader
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

// sync height and add classes

$j(document).ready(function(){


	// nav_shinybuttons.css
	$j("#modelle ul li:last").attr("style","background-image:none;");
	
	/* this is the .hlist navigation part */
	$j(".hlist ul li:last").attr("style","background-image:none;");
	/* ie7 filter glitch */
	// $j(".divtabswrap > div").style.removeAttribute('filter');
	document.body.style.filter = '';

	
	// Langmenu hover
    $j("#lng_en").hover(
      function () {
        $j(this).attr("src","fileadmin/template/images/flag_en_ro.gif");
      }, 
      function () {
        $j(this).attr("src","fileadmin/template/images/flag_en.gif");
      }
    );
    $j("#lng_de").hover(
      function () {
        $j(this).attr("src","fileadmin/template/images/flag_de_ro.gif");
      }, 
      function () {
        $j(this).attr("src","fileadmin/template/images/flag_de.gif");
      }
    ); 



	// hide header if empty
	if ( $j('#header').children().size() < 1 ) { 
		$j('#header').hide();
	}
	if ( $j('#col3_nav').children().size() < 1 ) { 
		$j('#col3_nav').hide();
	}

	// change blm domain
	
	// var $j = jQuery.noConflict();
	var blmdomain = "http://web307.itsbserver.org/";
	var oldhref = $j("a.blmlink");
	for (var i = 0; i < $j("a.blmlink").size(); i++) {
		var thehref = $j(oldhref[i]).attr('href');
		//  console.log(thehref);
		$j("a.blmlink").eq(i).attr('href', blmdomain+thehref);
		// console.log(orighref);        
	} 

		// col3_nav hover
    $j("#col3_nav ul li.col3_nav_no").hover(
      function () {
        $j(this).attr("style",'background-image:url("fileadmin/template/images/bg_nav_col3_cur_200.gif"); color:white;');
        $j(this).find("a").attr("style",'color:white;');
      }, 
      function () {
        $j(this).attr("style","background-image:none;");
		$j(this).find("a").attr("style",'color:#424242;');
      }
    );


	// modell_detail hover
	
	// IMG Preloader
	$j.preloadImages(
		"fileadmin/template/images/tabs/bildertab_ho.png",
		"fileadmin/template/images/tabs/downloadstab_ho.png",
		"fileadmin/template/images/tabs/filmetab_ho.png",
		"fileadmin/template/images/tabs/infotab_ho.png",
		"fileadmin/template/images/tabs/preisetab_ho.png",
		"fileadmin/template/images/tabs/technischestab_ho.png"
	); 


	// if tabs are on the page
	if($j(".tabNavigation a.selected").size() == 1) {
		// modell_detail script
		var tabContainers = $j('div#tabs_1 .divtabswrap > div');
		tabContainers.hide('slow').filter(':first').show();
		

		$j(window).bind('hashchange', function () {
			var hash = window.location.hash || '#infotab';
			
			// zuerst entfernen bei hashchange
			tabContainers.hide('slow');
			tabContainers.filter(hash).show('slow');
			 var unsel = $j(".tabNavigation a.selected img").attr("src");
			 var unsel = unsel.replace("_ho.png","_.png");
			 $j(".tabNavigation a.selected img").attr("src",unsel);
			 //console.log(unsel);
			$j('.tabNavigation a').removeClass('selected');

			// dann einfügen bei hashchange
			$j('a[hash=' + hash + ']').addClass('selected'); 

			 var sel = $j('.selected img').attr("src");
			 //console.log(sel); 
			 var sel = sel.replace("_.png","_ho.png");
			 //console.log(sel); 
			 $j('.selected img').attr("src", sel);
			 
		});
		$j(window).trigger( "hashchange" );
	}
	
	// hover tabs 
//	 $j(".ultabswrap a").not(".selected").find("img").hover(
	 $j(".ultabswrap a").find("img").hover(
		  function(){
			  if ($j(this).parent().hasClass("selected")) {
			  } else {
				  this.src = this.src.replace("_.png","_ho.png");
				  //this.prev().css('background-repeat', 'repeat-y');
			  }
//			  alert("2");
//			  this.src = this.src.replace("_.png","_ho.png");
		  },
		  function(){
			  if ($j(this).parent().hasClass("selected")) {
			  } else {
				  this.src = this.src.replace("_ho.png","_.png");
			  }
	 });
	 $j(".ultabswrap a").click(
		  function(){
			  $j(".ultabswrap .selected").find("img").src = $j(".ultabswrap .selected").find("img").src.replace("_ho.png","_.png");
			  $j(".ultabswrap a").removeClass("selected");
			  $j(this).addClass("selected");
			  //$j(this).find("img").src = $j(this).find("img").src.replace("_.png","_ho.png");
	 });
	 
	 $j("UL.tabNavigation LI:last").css({'background-position':'1000px 1000px'});

	
  // begin magicline script 
  if($j(".current_page_item_two").size() == 1) {
  // begin magicline script 


    var $jel, leftPos, newWidth,
        $jmainNav2 = $j("#example-two");
    

    $jmainNav2.append("<li id='magic-line-two'></li>");
    
    var $jmagicLineTwo = $j("#magic-line-two");
    
    $jmagicLineTwo
        .width($j(".current_page_item_two").width())
        .height($jmainNav2.height())
        .css("left", $j(".current_page_item_two a").position().left)
        .data("origLeft", $j(".current_page_item_two a").position().left)
        .data("origWidth", $jmagicLineTwo.width())
        //.data("origColor", $j(".current_page_item_two a").attr("rel"));
        //.data("origColor", $j(".current_page_item_two a").attr("rel"));
                
    $j("#example-two li").find("a").hover(function() {
        $jel = $j(this);
        leftPos = $jel.position().left;
        newWidth = $jel.parent().width();
        $jmagicLineTwo.stop().animate({
            left: leftPos,
            width: newWidth
            //backgroundColor: $jel.attr("rel")
        })

    }, function() {
        $jmagicLineTwo.stop().animate({
            left: $jmagicLineTwo.data("origLeft"),
            width: $jmagicLineTwo.data("origWidth")
            // backgroundColor: $jmagicLineTwo.data("origColor")
        })
    });


	} else {

	var $jel, leftPos, newWidth,
			$jmainNav2 = $j("#example-two");
		

		$jmainNav2.append("<li id='magic-line-two'></li>");
		
		var $jmagicLineTwo = $j("#magic-line-two");
		
		$jmagicLineTwo
			.width($j(".current_page_item_two").width())
			.height($jmainNav2.height())
			.css({
				left: "0",
				width: "0"
			});

		$j("#example-two li").find("a").hover(function() {
			$jel = $j(this);
			leftPos = $jel.position().left;
			newWidth = $jel.parent().width();
			$jmagicLineTwo.stop().animate({
				left: leftPos,
				width: newWidth
			})

		}, function() {
			$jmagicLineTwo.stop().animate({
				left:"0",
				width:"0"
			});    
		});
		  
	}
	
	// heeeeeeeeeeere we go. news ticker
	$j("#chained").scrollable(
		{	
			circular: true, 
			mousewheel: false
		}).autoscroll({
			interval: 2000
		});	
	
	// news in navigation
	$j("ul.modelle_with_logo li:last").css({'background-position':'1000px 1000px'});
	
	// news single clearing after every 3rd img
	$j(".news-single-img>div:nth-child(3n+1)").css({'clear':'left'});
	
	// news single img 3rd img without margin
	$j(".news-single-img>div:nth-child(3n+3)").css({'margin-right':'0'});

		
	// preistabelle
	$j("table.preistabelle th:first").addClass("first");
	$j("table.preistabelle th:last").addClass("last");
	$j("table.preistabelle tr td:first").addClass("image");
	$j("table.preistabelle tr td:first").addClass("firstcol");
	$j("table.preistabelle tr td:last-child").addClass("lastcol");
	$j("table.preistabelle tr td:nth-child(3)").addClass("lightsilver");


//iframe direkt laden
$j(function () {
	$j("#frameafter").load($j("iframe").attr("src"));
	$j(".tx-sriframe-pi1 iframe").hide();
});
});






