
var newsticker = {
	contentSwitchTime: 10000,
	contentItems: 0,
	currentItem: 0,
	running: true,
	contentItemOpen: false,
	contentDisplaySize: 0,
	animationType: "fade",
	init: function(animationt) {
		if(animationt != null){ this.animationType = animationt; }
		if(document.getElementById('news_ticker') != null) {
			newsticker.prepareContent();
			this.progress((this.contentSwitchTime / 1000));
			window.setTimeout("newsticker.switchContent()", this.contentSwitchTime);
		}
	},
	prepareContent: function() {
		// Durchläuft alle News und vergibt deren Style
		jQuery(".news_ticker_item").each(function(){
			if(newsticker.contentItems == 0){
				if(newsticker.animationType == "slide"){
					jQuery(this).css("top", "0px");
					jQuery(this).css("display", "block");
				} else {
					jQuery(this).css("display", "block");
				}
				newsticker.currentItem = 0;
			} else {
				if(newsticker.animationType == "slide"){
					jQuery(this).css("top", "130px");
					jQuery(this).css("display", "block");
				} else {
					jQuery(this).css("display", "none");
				}
			}
			
			newsticker.contentItems++;
		});
		this.contentDisplaySize = jQuery("#news_ticker_content").height();
		jQuery("#news_ticker_aa_num").html(newsticker.contentItems);
	},
	switchContent: function() {
		if(this.running == true){
			if(this.animationType == "slide"){
				this.animateSlide();
			} else {
				this.animateFade();
			}
			this.progress((this.contentSwitchTime / 1000));
			//jQuery("#news_ticker_ca_num").html((newsticker.currentItem + 1));
		}
		
		window.setTimeout("newsticker.switchContent()", this.contentSwitchTime);
	},
	openContent: function() {
		if(this.contentItemOpen == false){
		
			this.running = false;
			this.contentItemOpen = true;
			jQuery("#news_time").fadeOut();
			jQuery("#news_ticker_content div").each(function(){
				if(jQuery(this).attr("id") != "news_ticker_item_" + newsticker.currentItem){
					jQuery(this).css("display", "none");
				}
			});
			jQuery("#news_ticker_item_" + this.currentItem + " .more").css("display", "block").css("opacity", "0");

			jQuery("#news_ticker_content").animate({height: (jQuery("#news_ticker_item_" + newsticker.currentItem).outerHeight()) + "px"}, 300, "linear", function() {
				jQuery("#news_ticker_item_" + newsticker.currentItem + " .more").fadeTo(100, 1);
			});
			
			jQuery("#news_ticker_navigation .news_item_content").html("Artikel schlie&szlig;en");
		} else {
			jQuery("#news_time").fadeIn();
			jQuery("#news_ticker_item_" + newsticker.currentItem + " .more").fadeOut(300, function() {
				jQuery("#news_ticker_content").animate({height: newsticker.contentDisplaySize + "px"}, 300, "linear", function() {
					if(newsticker.animationType == "slide"){
						jQuery("#news_ticker_content div").each(function(){
							if(jQuery(this).attr("id") != "news_ticker_item_" + newsticker.currentItem){
								jQuery(this).css("display", "block");
							}
						});
					}
					jQuery("#news_ticker_navigation .news_item_content").html("diesen Artikel ansehen");
					newsticker.running = true;
					newsticker.contentItemOpen = false;
				});
			});
		}
		
	},
	animateSlide: function() {
		jQuery("#news_ticker_item_" + (this.currentItem)).animate({top: "-130px"}, 1000, "linear", function(){ $(this).css("top", "130px"); });
		
		if((this.currentItem + 1) < this.contentItems) {
			jQuery("#news_ticker_item_" + (this.currentItem + 1)).animate({	top: "0px"}, 1000);
			this.currentItem++;
		} else {
			jQuery("#news_ticker_item_1").animate({	top: "0px"}, 1000);
			this.currentItem = 0;
		}
		
	},
	animateFade: function() {
		jQuery("#news_ticker_item_" + (this.currentItem)).fadeOut(500);
		
		if((this.currentItem + 1) < this.contentItems) {
			jQuery("#news_ticker_item_" + (this.currentItem + 1)).fadeIn(500);
			this.currentItem++;
		} else {
			jQuery("#news_ticker_item_1").fadeIn(500);
			this.currentItem = 0;
		}
	},
	progress: function(current) {
		/*jQuery("#news_time span").html(""+ current + "");
		if(current > 0){
			window.setTimeout("newsticker.progress("+(current - 1)+")", 1000);
		}*/
	}

}

function newsSearchActive(){
	var searchFor = jQuery("#news_overview_searchinput").val();
	if(searchFor.length < 3){ jQuery("#news_found_to_keyword").html(""); return; }

	//jQuery("#news_found_to_keyword").html("lade");
	
	jQuery.ajax({
		type: "get",
		url: "/",
		data: "news=1&count="+searchFor+"&ajax=1&content=true&title=true",
		success: function(xhtml) {
			if(xhtml == 0){ xhtml = "0"; }
			jQuery("#news_found_to_keyword").html(xhtml + " Treffer gefunden.");
		}
	});
}

jQuery(document).ready(function() { newsticker.init("slide"); });

/* ====================================================
   ============== Add searchbar =======================
   ==================================================== */
function addSearchbar()
{
	try {
		window.external.AddSearchProvider("http://beta.marketing-search.de/searchplugin.xml");
	}
	catch(eObj) {
		alert("We're sorry; but we cannot add our search engine to "+
				"your browser.\nWe require Mozilla, Firefox, or IE 7 "+
				"to do this.");
		return true;
	}
	return false;
}


/* ====================================================
   ============== FEATURE TEASER ======================
   ==================================================== */
$(document).ready(function(){ 
	//TeaserInit();
});

function TeaserInit() {
	var cookie = document.cookie;
	var reg = /TeaserSet\=1/;
	if( !cookie.match(/TeaserSet\=1/) )
	{
	document.cookie = "TeaserSet=1";
//	$("body").append("<div id='teaser-layer' style='position: fixed; width: 100%; height: 100%; z-index: 200; background-color: #333; opacity: 0.6; filter: alpha(opacity=60); top: 0px; left: 0px; display: block'></div>");
	//$("body").append("<div id='teaser-content' style='position: fixed; top: 50%; left: 50%; z-index: 201; display: none; width: 500px; height: 600px; margin-top: -300px; margin-left: -250px;'></div>");
	$('#teaser-content').css({
		backgroundColor: "#ffffff",
		border: "2px solid #d0d0d0"
	});
	
	$('#teaser-content').fadeIn(1500);
	$('#teaser-content').load("/templates/marketingsearch/features.html");
	
	}
}
function TeaserClose() {
	
	$("#teaser-content").slideUp();
}


function CreateBookmarkLink() {

	title = "marketing-search.de";
	// Blogger - Replace with <$BlogItemTitle$>
	// MovableType - Replace with <$MTEntryTitle$>

	url = "http://absatzwirtschaft.marketing-search.de";
	// Blogger - Replace with <$BlogItemPermalinkURL$>
	// MovableType - Replace with <$MTEntryPermalink$>
	// WordPress - <?php bloginfo('url'); ?>

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}
