$(document).ready(function(){ 
	
	//correct position of sublist in navigation "ford"
	var ford_list = $('#car_32 ul');
	ford_list.css('top', ((ford_list.height()-25) * -1)+'px'  );
	
	var mazda_list = $('#car_33 ul');
	mazda_list.css('top', ((mazda_list.height()-25) * -1)+'px'  );

	var volvo_list = $('#car_34 ul');
	volvo_list.css('top', ((volvo_list.height()-25) * -1)+'px'  );
	
	var nf_list = $('#car_3 ul');
	nf_list.css('top', ((nf_list.height()-25) * -1)+'px'  );
	
	var gw_list = $('#car_12 ul');
	gw_list.css('top', ((gw_list.height()-25) * -1)+'px'  );
	
	//reset search input on focus
	$('#q')
		.click(function(){
			if( $(this).val() == 'Suche' ){
				$(this).val('');
			}
		})
		.blur(function(){
			if( $(this).val() == '' ){
				$(this).val('Suche');
			}
		});
	
	//animate teaser and show description
	$('#teaser a').hover(
		function(){
			if( $(this).is(':animated') ){
				$(this).stop().animate({top:0},200);
			}else{
				$(this).animate({top:0},200);
			}
			$( '#'+$(this).attr('rel') ).css('visibility','visible');

		},
		function(){
			
			if( $(this).is(':animated') ){
				$(this).stop().animate({top:'43px'},200);
			}else{
				$(this).animate({top:'43px'},200);
			}
			$( '#'+$(this).attr('rel') ).css('visibility','hidden');
			
		}
	);
	
	//start teaser if more than two children
	var num_of_teaser = parseInt($('#teaser_wrapper_inner a').length);
	var teaser;
	
	if( num_of_teaser > 2 ){
		teaser = window.setInterval('rotate()', 5000);
	}
	
	//stop teaser animation on mouseover
	$('#teaser_wrapper_inner a')
		.mouseover(function(){
			window.clearInterval(teaser);
		})
		.mouseleave(function(){
			if( num_of_teaser > 2 ){
				teaser = window.setInterval('rotate()', 5000);
			}
		});
	
	//gallery
	$('a[onclick^="openPic"]')
		.removeAttr('onclick')
//		.attr('href', function(){
//			return this.href +'';
//		})
		.attr('rel','gallery')
		.colorbox({opacity:.8,current:"Bild {current} von {total}"});

	//popup
	$('a[onclick^="vHWin=window.open"]')
		.removeAttr('onclick')
//		vHWin=window.open('http://schmidt.dev/video.html','FEopenLink','width=600,height=400');vHWin.focus();return false;
//			.attr('href', function(){
//				return this.href +'';
//			})
		.colorbox({width:"615", height:"420", opacity:.8});
	
	//open footer links
	$('#ftr-schmidt a').colorbox({width:"90%", height:"90%", iframe:true, opacity:.8});
	$('#ftr-volvo a').colorbox({width:"90%", height:"90%", iframe:true, opacity:.8});
	$('#ftr-mazda a').colorbox({width:"90%", height:"90%", iframe:true, opacity:.8});
	$('#car_33 a').colorbox({width:"90%", height:"90%", iframe:true, opacity:.8});
	$('#car_34 a').colorbox({width:"90%", height:"90%", iframe:true, opacity:.8});
	$('.colorbox_iframe').colorbox({width:"90%", height:"90%", iframe:true, opacity:.8});
	
	//external links
	//$('a.external').colorbox({width:"90%", height:"90%", iframe:true, opacity:.8});
	//$('a[target="_blank"]').colorbox({width:"90%", height:"90%", iframe:true, opacity:.8});
	
	$('a').click(function(e){
		if( !$(this).hasClass('no-colorbox') && ($(this).hasClass('external') || $(this).attr('target') == "_blank" )){
			$(this).colorbox({width:"90%", height:"90%", iframe:true, opacity:.8});
		}
	});
	
	
	//no ie6 support
	if ( $.browser.msie && parseInt($.browser.version) < 7 ) {
		var html = "<div id='ie6'><div style='border: 1px solid #F7941D; background: #FEEFDA; text-align: center; clear: both; height: 75px; position: relative;'>" +
				"<div style='width: 640px; margin: 0 auto; text-align: left; padding: 0; overflow: hidden; color: black;'>" +
				"<div style='width: 75px; float: left;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-warning.jpg' alt='Warning!'/></div>" +
				"<div style='width: 275px; float: left; font-family: Arial, sans-serif;'>" +
				"<div style='font-size: 14px; font-weight: bold; margin-top: 12px;'>Sie verwenden einen veralteten Browser</div><div style='font-size: 12px; margin-top: 6px; line-height: 12px;'>Um diese Website zu betrachten, müssen Sie Ihren Browser aktualisieren.</div></div>" +
				"<div style='width: 75px; float: left;'><a href='http://www.firefox.com' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-firefox.jpg' style='border: none;' alt='Get Firefox 3.5'/></a></div>" +
				"<div style='width: 75px; float: left;'><a href='http://www.browserforthebetter.com/download.html' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-ie8.jpg' style='border: none;' alt='Get Internet Explorer 8'/></a></div>" +
				"<div style='width: 73px; float: left;'><a href='http://www.apple.com/safari/download/' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-safari.jpg' style='border: none;' alt='Get Safari 4'/></a></div>" +
				"<div style='float: left;'><a href='http://www.google.com/chrome' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-chrome.jpg' style='border: none;' alt='Get Google Chrome'/></a></div></div></div></div>";

		$("body").append(html);
	}
	
	//show places beyond footer links
	$('#footer a').hover(function(){
		if($.browser.msie){
			$(this).next().show();
		}else{
			$(this).next().fadeIn();
		}
	},
	function(){
		if($.browser.msie){
			$(this).next().hide();
		}else{
			$(this).next().fadeOut();
		}
	})
	
});

//teaser rotation
function rotate(){
	var w_element 	= parseInt($('#teaser_wrapper_inner a').outerWidth() + 3);
	var elements 	= parseInt($('#teaser_wrapper_inner a').length);

	var position =  $('#teaser_wrapper_inner').position()
	
	if( position.left <= (w_element * (elements-1)) * -1 ){
		var leftPos = '0';
		var duration = elements * 500;
	}else{
		var leftPos = '-='+ (w_element*1) +'px';
		var duration = 1000;
	}

	$('#teaser_wrapper_inner').animate({left:leftPos}, duration);
	$('#teaser_text_wrapper_inner').animate({left:leftPos}, duration);
	
}

//reposition navi
$(window).scroll(function () { 
    var offset 	= $(document).scrollTop();
    
    if(offset > 30){
    	$('#col-1-inner').animate({top:offset+30+'px'}, {duration:600, queue: false});
    }else{
    	$('#col-1-inner').animate({top:'30px'}, {duration:600, queue: false});
    }
});

