$(function() {
	// (index.php) Hide teaser details
	// ---------------------------------
	$('div#teaserSearchDetails').hide();

	// (index.php) Looped tabs animation on right side ("Aktuelle Codebeispiele", Xing, LinkedIn, Twitter, Facebook)
	// ---------------------------------
    $.fn.wait = function(time, type) {
        time = time || 100;
        type = type || "fx";
        return this.queue(type, function() {
			var self = this;
			setTimeout(function() {
				$(self).dequeue();
			}, time);
		});
	};
	function runIt() {
		$("div.tabsRightSideIndex div.samplesCodeIndex").wait(5500).animate({'width': '63px', 'backgroundPosition': '-43px 24px'}, 400, 'jswing')
		.wait(900).animate({'width': '42px', 'backgroundPosition': '11px 24px'}, 450, 'easeInCirc');
		$("div.tabsRightSideIndex div.externalsIndex div.xing").wait(5600).animate({'right': '18px', 'width': '90px', 'backgroundPosition': '29px 6px', 'borderRadius': '170px 0 170px 15px'}, 400, 'jswing')
		.wait(900).animate({'right': '0', 'width': '42px', 'backgroundPosition': '5px 6px'}, 449, 'easeInCirc')
		.animate({'borderRadius': '5px'}, 1, 'jswing');
		$("div.tabsRightSideIndex div.externalsIndex div.linkedin").wait(5700).animate({'right': '18px', 'width': '90px', 'backgroundPosition': '29px 6px', 'borderRadius': '170px 0 170px 15px'}, 400, 'jswing')
		.wait(900).animate({'right': '0', 'width': '42px', 'backgroundPosition': '5px 6px'}, 349, 'easeInCirc')
		.animate({'borderRadius': '5px'}, 1, 'jswing');
		$("div.tabsRightSideIndex div.externalsIndex div.twitter").wait(5800).animate({'right': '18px', 'width': '90px', 'backgroundPosition': '29px 6px', 'borderRadius': '170px 0 170px 15px'}, 400, 'jswing')
		.wait(900).animate({'right': '0', 'width': '42px', 'backgroundPosition': '5px 6px'}, 249, 'easeInCirc')
		.animate({'borderRadius': '5px'}, 1, 'jswing');
		$("div.tabsRightSideIndex div.externalsIndex div.facebook").wait(5900).animate({'right': '18px', 'width': '90px', 'backgroundPosition': '29px 6px', 'borderRadius': '170px 0 170px 15px'}, 400, 'jswing')
		.wait(900).animate({'right': '0', 'width': '42px', 'backgroundPosition': '5px 6px'}, 149, 'easeInCirc')
		.animate({'borderRadius': '5px'}, 1, 'jswing');
	}
	runIt();

	// (index.php) Scrolling teaser moduls left side ("Diese Tage..." + "Weitere Tutorials")
	// + Vertical scrolling of tabs on right side ("Aktuelle Codebeispiele", Xing, LinkedIn, Twitter, Facebook)
	// ---------------------------------
	var offset = $('div#modulsTeaser, div.tabsRightSideIndex, div.tabsRightSide').offset('div#modulsTeaser, div.tabsRightSideIndex, div.tabsRightSide');
	var topPaddingTeaser = 15;
	var topPaddingTabsRightSide = 100;
	$(window).scroll(function() {
		if ($(window).scrollTop() > offset.top) {
			$('div#modulsTeaser').stop().animate({marginTop: $(window).scrollTop() - offset.top + topPaddingTeaser});
			$('div.tabsRightSideIndex, div.tabsRightSide').stop().animate({marginTop: $(window).scrollTop() - offset.top + topPaddingTabsRightSide});
			} else {
				$('div#modulsTeaser, div.tabsRightSideIndex, div.tabsRightSide').stop().animate({marginTop: 0});
		};
	});

 	// (index.php) Teaser details
	// ---------------------------------
	$('div.teaserHeadlines a.teaserClaim, div.teaserDetailsButton a').click(function() {
		$('div#teaserSearchDetails').slideDown('slower');
		$('div.teaserHeadlines div').toggleClass('active');
		// Write link target to variable
		var target = $(this).attr('href');
		// Animated scrolling (body --> for earlier versions of Safari)
		$('html,body').animate({scrollTop: $(target).offset().top}, 700, 'jswing');
		return false;
	});
	$('div.teaserHeadlines a.teaserClaim').click(function() {
		$('div.teaserDetailsButton div.expand').removeClass('active');
		$('div.teaserDetailsButton div.collapse').addClass('active');
	});
	$('div.teaserDetailsButton a').click(function() {
		$('div.teaserHeadlines div, div.teaserDetailsButton div').toggleClass('active');
	});
	$('div.teaserDetailsButton div.expand a').click(function() {
		$('div#teaserSearchDetails').slideDown('slower');
	});
	$('div.teaserDetailsButton div.collapse a').click(function() {
		$('div#teaserSearchDetails').slideUp('slower');
	});

	// (index.php) News
	// ---------------------------------
	$('div.articleHeader').click(function(){
		$(this).toggleClass('active').next().slideToggle('slow');
	});

 	// Tabs animation on right side ("Aktuelle Codebeispiele", Xing, LinkedIn, Twitter, Facebook)
	// ---------------------------------
	$('div.tabsRightSide div.samplesCode').hover(function(){
		$(this).animate({'width': '63px', 'backgroundPosition': '-43px 24px'}, 250, 'jswing');
	});
	$('div.tabsRightSide div.samplesCode').mouseout(function(){
		$(this).animate({'width': '42px', 'backgroundPosition': '11px 24px'}, 150, 'easeInCirc');
	});
	$('div.tabsRightSide div.externals div').hover(function(){
		$(this).animate({'right': '18px', 'width': '90px', 'backgroundPosition': '29px 6px', 'borderRadius': '170px 0 170px 15px'}, 240, 'jswing');
	});
	$('div.tabsRightSide div.externals div').mouseout(function(){
		$(this).animate({'right': '0', 'width': '42px', 'backgroundPosition': '5px 6px'}, 110, 'jswing')
		.animate({'borderRadius': '5px'}, 1, 'jswing');
	});

 	// Box code-samples
	// ---------------------------------
  	// Fading in hidden box
	$('a.boxSamples').click(function() {
		$('div#sampleCodeBox').fadeIn('slow');
		// Write link target to variable
		var target = $(this).attr('href');
		// Animated scrolling (body --> for earlier versions of Safari)
		$('html,body').animate({scrollTop: $(target).offset().top}, 1000, 'easeOutCirc');
		return false;
	});

  	// Content in box (CSS + HTML + JavaScript + jQuery)
	$('div.tab a').each(function(){
  		var url = $(this).attr('href');
  		$(this).attr('title',url).attr('href','#');
	});
	$('div.tab a').click(function(){
  		var quelle = $(this).attr('title') + ' div';
  		$('div#content').load(quelle);
	});

 	// Tab selection in box
	$('div.tab a.selectCss').click(function(){
		$('div.tab a').removeClass('active');
		$(this).addClass('active');
	});
	$('div.tab a.selectHtml').click(function(){
		$('div.tab a').removeClass('active');
		$(this).addClass('active');
	});
	$('div.tab a.selectScript').click(function(){
		$('div.tab a').removeClass('active');
		$(this).addClass('active');
	});

 	// Closing the box
	$('div.close a').click(function() {
		$('#sampleCodeBox').fadeOut('normal');
	})
});

// External links: Open in new window
// ---------------------------------
function makePopup() {
  newWindow = window.open(this.href);
  newWindow.focus();
  return false;
}

function newWindow() {
	var externalLinkText = 'extern';
	var textNewWindow = 'er Link';
	if (!document.getElementsByTagName) { return } ;
	var links = document.getElementsByTagName('a');
	for (i = 0; i < links.length; i++) {
		textAlt = links[i].getAttribute('class');
		if (textAlt && (textAlt.indexOf(externalLinkText) != -1)) {
			textAppendix = textAlt.substring((textAlt.indexOf(externalLinkText)) + externalLinkText.length, textAlt.length);
			links[i].setAttribute('class', externalLinkText + '' + textNewWindow + textAppendix);
		links[i].onclick = links[i].onkeypress = makePopup;}
	}
}

var counter = 0;
myFunction = window.onload;
window.onload = function() {
	if (counter == 0) {
		if (typeof myFunction == 'function') myFunction();
	newWindow(); counter++;}
};

// Popups: "Programmierung + Webdesign"
// ---------------------------------
function refPopup(pop) {
	popup = window.open(pop,'refPopup','width=729px, height=633px, top=10px, left=10px').focus();
};

// Popups: "3D/ Animation"
// ---------------------------------
function refPopup3dTyp1(pop3d) {
	popup3d = window.open(pop3d, 'ref3dPopup1', 'width=789px, height=341px, top=10px, left=10px').focus();
};
function refPopup3dTyp2(pop3d2) {
	popup3d2 = window.open(pop3d2, 'ref3dPopup2', 'width=729px, height=573px, top=10px, left=10px').focus();
;}
function refPopup3dTyp3(pop3d3) {
	popup3d3 = window.open(pop3d3, 'ref3dPopup3', 'width=232px, height=598px, top=10px, left=10px').focus();
};
function refPopup3dTyp4(pop3d4) {
	popup3d4 = window.open(pop3d4, 'ref3dPopup4', 'width=729px, height=555px, top=10px, left=10px').focus();
};
function refPopup3dTyp5(pop3d5) {
	popup3d5 = window.open(pop3d5, 'ref3dPopup5', 'width=729px, height=556px, top=10px, left=10px').focus();
};
function refPopup3dTyp6(pop3d6) {
	popup3d6 = window.open(pop3d6, 'ref3dPopup6', 'width=729px, height=515px, top=10px, left=10px').focus();
};
function refPopup3dTyp7(pop3d7) {
	popup3d7 = window.open(pop3d7, 'ref3dPopup7', 'width=519px, height=415px, top=10px, left=10px').focus();
};

// Popups: "Printwerbung"
// ---------------------------------
function refPopupPrintTyp1(popPrint) {
	popupPrint = window.open(popPrint, 'refPrintPopup1', 'width=729px, height=541px, top=10px, left=10px').focus();
};
function refPopupPrintTyp2(popPrint2) {
	popupPrint2 = window.open(popPrint2, 'refPrintPopup2', 'width=729px, height=495px, top=10px, left=10px').focus();
};

// Popup: "Flyer"
// ---------------------------------
function refPopupFlyerTyp1(popFlyer){
	popupFlyer = window.open(popFlyer, 'refFlyerPopup1', 'width=729px, height=528px, top=10px, left=10px').focus();
};