// FROM: /fileadmin/template/js/jquery.tweet.js
(function($) {
 
  $.fn.tweet = function(o){
    var s = {
      username: ["seaofclouds"],              // [string]   required, unless you want to display our tweets. :) it can be an array, just do ["username1","username2","etc"]
      list: null,                              //[string]   optional name of list belonging to username
      avatar_size: null,                      // [integer]  height and width of avatar if displayed (48px max)
      count: 3,                               // [integer]  how many tweets to display?
      intro_text: null,                       // [string]   do you want text BEFORE your your tweets?
      outro_text: null,                       // [string]   do you want text AFTER your tweets?
      join_text:  null,                       // [string]   optional text in between date and tweet, try setting to "auto"
      auto_join_text_default: "i said,",      // [string]   auto text for non verb: "i said" bullocks
      auto_join_text_ed: "i",                 // [string]   auto text for past tense: "i" surfed
      auto_join_text_ing: "i am",             // [string]   auto tense for present tense: "i was" surfing
      auto_join_text_reply: "i replied to",   // [string]   auto tense for replies: "i replied to" @someone "with"
      auto_join_text_url: "i was looking at", // [string]   auto tense for urls: "i was looking at" http:...
      loading_text: null,                     // [string]   optional loading text, displayed while tweets load
      query: null,                            // [string]   optional search query
      refresh_interval: null                  // [integer]  optional number of seconds after which to reload tweets
    };
    
    if(o) $.extend(s, o);
    
    $.fn.extend({
      linkUrl: function() {
        var returning = [];
        var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
        this.each(function() {
          returning.push(this.replace(regexp,"<a target=\"_blank\" href=\"$1\">$1</a>"));
        });
        return $(returning);
      },
      linkUser: function() {
        var returning = [];
        var regexp = /[\@]+([A-Za-z0-9-_]+)/gi;
        this.each(function() {
          returning.push(this.replace(regexp,"<a target=\"_blank\" href=\"http://twitter.com/$1\">@$1</a>"));
        });
        return $(returning);
      },
      linkHash: function() {
        var returning = [];
        var regexp = /(?:^| )[\#]+([A-Za-z0-9-_]+)/gi;
        this.each(function() {
          returning.push(this.replace(regexp, ' <a target=\"_blank\" href="http://search.twitter.com/search?q=&tag=$1&lang=all&from='+s.username.join("%2BOR%2B")+'">#$1</a>'));
        });
        return $(returning);
      },
      capAwesome: function() {
        var returning = [];
        this.each(function() {
          returning.push(this.replace(/\b(awesome)\b/gi, '<span class="awesome">$1</span>'));
        });
        return $(returning);
      },
      capEpic: function() {
        var returning = [];
        this.each(function() {
          returning.push(this.replace(/\b(epic)\b/gi, '<span class="epic">$1</span>'));
        });
        return $(returning);
      },
      makeHeart: function() {
        var returning = [];
        this.each(function() {
          returning.push(this.replace(/(&lt;)+[3]/gi, "<tt class='heart'>&#x2665;</tt>"));
        });
        return $(returning);
      }
    });

    function parse_date(date_str) {
      // The non-search twitter APIs return inconsistently-formatted dates, which Date.parse
      // cannot handle in IE. We therefore perform the following transformation:
      // "Wed Apr 29 08:53:31 +0000 2009" => "Wed, Apr 29 2009 08:53:31 +0000"
      return Date.parse(date_str.replace(/^([a-z]{3})( [a-z]{3} \d\d?)(.*)( \d{4})$/i, '$1,$2$4$3'));
    }

    function relative_time(time_value) {
      var parsed_date = parse_date(time_value);
      var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
      var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
      var r = '';
      if (delta < 60) {
	r = delta + ' seconds ago';
      } else if(delta < 120) {
	r = 'a minute ago';
      } else if(delta < (45*60)) {
	r = (parseInt(delta / 60, 10)).toString() + ' minutes ago';
      } else if(delta < (2*60*60)) {
	r = 'an hour ago';
      } else if(delta < (24*60*60)) {
	r = '' + (parseInt(delta / 3600, 10)).toString() + ' hours ago';
      } else if(delta < (48*60*60)) {
	r = 'a day ago';
      } else {
	r = (parseInt(delta / 86400, 10)).toString() + ' days ago';
      }
      return 'about ' + r;
    }

    function build_url() {
      var proto = ('https:' == document.location.protocol ? 'https:' : 'http:');
      if (s.list) {
        return proto+"//api.twitter.com/1/"+s.username[0]+"/lists/"+s.list+"/statuses.json?per_page="+s.count+"&callback=?";
      } else if (s.query == null && s.username.length == 1) {
        return proto+'//api.twitter.com/1/statuses/user_timeline.json?screen_name='+s.username[0]+'&count='+s.count+'&include_rts=1&callback=?';
      } else {
        var query = (s.query || 'from:'+s.username.join(' OR from:'));
        return proto+'//search.twitter.com/search.json?&q='+encodeURIComponent(query)+'&rpp='+s.count+'&callback=?';
      }
    }

    return this.each(function(i, widget){
      var list = $('<ul class="tweet_list">').appendTo(widget);
      var intro = '<p class="tweet_intro">'+s.intro_text+'</p>';
      var outro = '<p class="tweet_outro">'+s.outro_text+'</p>';
      var loading = $('<p class="loading">'+s.loading_text+'</p>');

      if(typeof(s.username) == "string"){
        s.username = [s.username];
      }

      if (s.loading_text) $(widget).append(loading);
      $(widget).bind("load", function(){
        $.getJSON(build_url(), function(data){
          if (s.loading_text) loading.remove();
          if (s.intro_text) list.before(intro);
          list.empty();
          var tweets = (data.results || data);
          $.each(tweets, function(i,item){
            // auto join text based on verb tense and content
            if (s.join_text == "auto") {
              if (item.text.match(/^(@([A-Za-z0-9-_]+)) .*/i)) {
                var join_text = s.auto_join_text_reply;
              } else if (item.text.match(/(^\w+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+) .*/i)) {
                var join_text = s.auto_join_text_url;
              } else if (item.text.match(/^((\w+ed)|just) .*/im)) {
                var join_text = s.auto_join_text_ed;
              } else if (item.text.match(/^(\w*ing) .*/i)) {
                var join_text = s.auto_join_text_ing;
              } else {
                var join_text = s.auto_join_text_default;
              }
            } else {
              var join_text = s.join_text;
            };
   
            var from_user = item.from_user || item.user.screen_name;
            var profile_image_url = item.profile_image_url || item.user.profile_image_url;
            if (document.location.protocol == 'https:') {
                var regex = /^https?:\/\/[^\.]+(.+)/;
                profile_image_url = profile_image_url.replace(regex, 'https://si0$1');
            }
            var join_template = '<span class="tweet_join"> '+join_text+' </span>';
            var join = ((s.join_text) ? join_template : ' ');
            var avatar_template = '<a target=\"_blank\" class="tweet_avatar" href="http://twitter.com/'+from_user+'"><img src="'+profile_image_url+'" height="'+s.avatar_size+'" width="'+s.avatar_size+'" alt="'+from_user+'\'s avatar" title="'+from_user+'\'s avatar" border="0"/></a>';
            var avatar = (s.avatar_size ? avatar_template : '');
            var date = '<br /><span class="tweet_time">(<a target=\"_blank\" href="http://twitter.com/'+from_user+'/statuses/'+item.id+'" title="view tweet on twitter">'+relative_time(item.created_at)+'</a>)</span>';
            
            //if(item.text.length > 80) item.text = item.text.substr(0, 80)+"...";
            
            var text = '<span class="tweet_text">' +$([item.text]).linkUrl().linkUser().linkHash().makeHeart().capAwesome().capEpic()[0]+ '</span>';
   
            // until we create a template option, arrange the items below to alter a tweet's display.
            list.append('<li>' + avatar + join + text + date + '</li>');
   
            list.children('li:first').addClass('tweet_first');
            list.children('li:odd').addClass('tweet_even');
            list.children('li:even').addClass('tweet_odd');
          });
          if (s.outro_text) list.after(outro);
          $(widget).trigger("loaded").trigger((tweets.length == 0 ? "empty" : "full"));
          if (s.refresh_interval) {
            window.setTimeout(function() { $(widget).trigger("load"); }, 1000 * s.refresh_interval);
          };
        });
      }).trigger("load");
    });
  };
})(jQuery);

// FROM: /fileadmin/template/js/jquery.xmldom.js
/*
 * jQuery xmlDOM Plugin v1.0
 * http://outwestmedia.com/jquery-plugins/xmldom/
 *
 * Released: 2009-04-06
 * Version: 1.0
 *
 * Copyright (c) 2009 Jonathan Sharp, Out West Media LLC.
 * Dual licensed under the MIT and GPL licenses.
 * http://docs.jquery.com/License
 */
(function(a){if(window.DOMParser==undefined&&window.ActiveXObject){DOMParser=function(){};DOMParser.prototype.parseFromString=function(c){var b=new ActiveXObject("Microsoft.XMLDOM");b.async="false";b.loadXML(c);return b}}a.xmlDOM=function(b,h){try{var d=(new DOMParser()).parseFromString(b,"text/xml");if(a.isXMLDoc(d)){var c=a("parsererror",d);if(c.length==1){throw ("Error: "+a(d).text())}}else{throw ("Unable to parse XML")}}catch(f){var g=(f.name==undefined?f:f.name+": "+f.message);if(a.isFunction(h)){h(g)}else{a(document).trigger("xmlParseError",[g])}return a([])}return a(d)}})(jQuery);




// FROM: /fileadmin/template/js/jquery.jfeed.js
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('3.X=a(h){h=3.J({v:D,C:D,u:D},h);k(h.v){$.W({t:\'V\',v:h.v,C:h.C,U:\'4\',u:a(4){d f=j B(4);k(3.T(h.u))h.u(f)}})}};a B(4){k(4)2.K(4)};B.r={t:\'\',l:\'\',c:\'\',b:\'\',g:\'\',K:a(4){k(3(\'8\',4).y==1){2.t=\'x\';d s=j z(4)}H k(3(\'f\',4).y==1){2.t=\'S\';d s=j A(4)}k(s)3.J(2,s)}};a o(){};o.r={c:\'\',b:\'\',g:\'\',i:\'\',n:\'\'};a A(4){2.q(4)};A.r={q:a(4){d 8=3(\'f\',4).9(0);2.l=\'1.0\';2.c=3(8).5(\'c:e\').6();2.b=3(8).5(\'b:e\').p(\'I\');2.g=3(8).5(\'R:e\').6();2.w=3(8).p(\'4:Q\');2.i=3(8).5(\'i:e\').6();2.m=j G();d f=2;3(\'P\',4).F(a(){d 7=j o();7.c=3(2).5(\'c\').9(0).6();7.b=3(2).5(\'b\').9(0).p(\'I\');7.g=3(2).5(\'O\').9(0).6();7.i=3(2).5(\'i\').9(0).6();7.n=3(2).5(\'n\').9(0).6();f.m.E(7)})}};a z(4){2.q(4)};z.r={q:a(4){k(3(\'x\',4).y==0)2.l=\'1.0\';H 2.l=3(\'x\',4).9(0).p(\'l\');d 8=3(\'8\',4).9(0);2.c=3(8).5(\'c:e\').6();2.b=3(8).5(\'b:e\').6();2.g=3(8).5(\'g:e\').6();2.w=3(8).5(\'w:e\').6();2.i=3(8).5(\'N:e\').6();2.m=j G();d f=2;3(\'7\',4).F(a(){d 7=j o();7.c=3(2).5(\'c\').9(0).6();7.b=3(2).5(\'b\').9(0).6();7.g=3(2).5(\'g\').9(0).6();7.i=3(2).5(\'M\').9(0).6();7.n=3(2).5(\'L\').9(0).6();f.m.E(7)})}};',60,60,'||this|jQuery|xml|find|text|item|channel|eq|function|link|title|var|first|feed|description|options|updated|new|if|version|items|id|JFeedItem|attr|_parse|prototype|feedClass|type|success|url|language|rss|length|JRss|JAtom|JFeed|data|null|push|each|Array|else|href|extend|parse|guid|pubDate|lastBuildDate|content|entry|lang|subtitle|atom|isFunction|dataType|GET|ajax|getFeed'.split('|')))





// FROM: /fileadmin/template/js/function.js
$(document).ready(function(){
	
	//$(".locationlist").append('<p class="loader">Laden...</p>');
	
	var heights = {};
	var jumpto=0;

	//Alle FAQs durchgehen, und die †berschriften verlinken
	$("div.faq").each(function(){
		//  console.log( $(this).parent() );
		$(this).addClass("nonactive");
		$(this).children("h4").html('<a href="javascript:;">'+$(this).children("h4").html()+'</a>');
		//Der Text wird versteckt
		heights[$(this).parent().attr("id")] = $(this).height();
		if('#' + $(this).parent().attr('id') == window.location.hash) {
			// zum anchor springen ... weiter unten
			jumpto=$(this).parent();
		} else {
			h4 = $(this).find('h4');
			$(this).height(h4.height() + parseInt(h4.css('padding-bottom')) + parseInt(h4.css('padding-top')));
		}
		//$(this).children("div.text").hide();
	});

	// zum anchor springen
	if(jumpto) {
		jQuery(window).scrollTop(jumpto.offset().top);
	}

	$("div.faq h4 a").click(function(){
		//if ( window.location.hash != '#debug' ) {
		//expandToFrom(heights[$(this).parent().parent().parent().attr("id")], $(this).parent().parent(), 22, "div.faq");
		//} else {
		expandToFrom(heights[$(this).parent().parent().parent().attr("id")], $(this).parent().parent(), 22, "div.faq");
		//}
	});
	

	//FŸr jedes App-Element
	$("div.appteaser").each(function(){

		//Aktuelle Hšhe speichern, und die hšhe auf 80px setzten, damit es abeschnitten wird...
		heights[$(this).parent().attr("id")] = $(this).height();
		$(this).height(80);
		$(this).addClass("nonactive");

		//var firstText = $(this).find("div.csc-textpic-text").children(":first-child").text();
		//var firstText1 = $(this).find("div.csc-textpic-text").children(":first-child").text();
		//var firstText = $(this).find("div.csc-textpic-text p.bodytext").text();
		//var firstText1 = $(this).find("div.csc-textpic-text p.bodytext").text();

		//$(this).find("div.csc-textpic-text").children(":last-child").append(' <a class="less" href="javascript:;">Less</a>');
		$(this).find("h3").html('<a href="javascript:;">'+$(this).find("h3").text()+'</a>');

		if ($(this).find("div.csc-textpic-text span.more").length == 0 ) {
			var m=lang_more;
			if(undefined === m) m = 'more';

			// $(this).find("div.csc-textpic-text").children(":first-child").html(firstText.substr(0, 85)+"<span class='more'>... <a href=\"javascript:;\">"+lang_more+"</a><br /><br /><br /><br /><br /><br /></span><b class='space' style='font-size:0.1px;'>&#32;</b>"+firstText1.substr(85));
			//$(this).find("div.csc-textpic-text p.bodytext").html(firstText.substr(0, 85)+"<span class='more'>... <a href=\"javascript:;\">"+lang_more+"</a><br /><br /><br /><br /><br /><br /></span><b class='space' style='font-size:0.1px;'>&#32;</b>"+firstText1.substr(85));
			var editobj =  $(this).find("div.csc-textpic-text p.bodytext").eq(0);
			editobj.html( editobj.html().substr(0,85) + "<span class='more'>... <a href=\"javascript:;\">"+m+"</a><br /><br /><br /><br /><br /><br /></span>" + editobj.html().substr(85));
		}
	});

	var timeoutId = setTimeout( function() {
		
		/*$("#footercolumns").append('<li><h4>Join us on <br /><strong>Facebook</strong></h4><iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fredbull&amp;width=219&amp;colorscheme=dark&amp;connections=6&amp;stream=false&amp;header=true&amp;height=267" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:219px; height:267px;" allowTransparency="true"></iframe></li>');*/
		
		var timeoutId = setTimeout( function() {
		
		/* HIGHLIGHT FADE ANIMATION */
		/*$('#leftnavi li a').each(function(){
			$(this).html('<span class="anim">'+$(this).html()+'</span>');
		});
		
		$('span.anim').mouseover(function() {
			$(this).highlightFade({
				speed:500,
				color:'rgb(255,255,255)'
			});
		});*/
		/*$("#twitterwall").tweet({
            username: "redbullmobile",
            join_text: "auto",
            avatar_size: 42,
            count: 3,
            auto_join_text_default: "",
            auto_join_text_ed: "",
            auto_join_text_ing: "",
            auto_join_text_reply: "",
            auto_join_text_url: "",
            loading_text: "loading tweets..."
        });*/
		
		
			var timeoutId = setTimeout( function() {		

				/*$.ajax({  
						type: 'GET',  
						url: '/ext/za/storelist.xml',  
						success: function(xml_list, text, html) {  
							
							$(".locationlist p.loader").remove();
							if(typeof(xml_list)=='object') {
								xml_list=html.responseText;
							}
							xml_list = '<?xml version="1.0" encoding="utf-8"?>'+xml_list;
							
							//$(".locationlist").html("");
							
							$.xmlDOM(xml_list).find('marker').each(function() {  
								
								name = $(this).attr("name");
								add = $(this).attr("add");
								
								add = add.replace("<br>", "");
								add = add.replace("<br />", "");
								add = add.replace("<br/>", "");
								add = add.replace('&amp;', '');
								add = add.replace('&lt;br&gt;', '');
								add = add.replace('&amp;&lt;br&gt;', '');
								
								if(add.length > (75-name.length)) {
									add = add.substr(0, 75-name.length);
									add += "...";
								}
								$(".locationlist").append('<li>'+add+'</li>');
								$(".locationlist li:last-child").html('<a href="/index.php?id=46&shopname='+escape(name)+'"><strong>'+name+'</strong> '+$(".locationlist li:last-child").text()+'</a>');
								
								counter = 0;
								$(".locationlist li").each(function(){
									if(counter >= 6)
										$(this).addClass("hidden");
									counter++;
								});
								
							});
							
							$(".locationlist").append('<li><a href="/index.php?id=46"><strong>... show all</strong></a></li>');
							//rotateShopList(7);
						}
					});*/
        
			        
				}, 2000);		
		
		}, 3000);

	}, 2000);		

	var timeoutId = setTimeout( function() {		

		//Fancybox
		/*$(document).ready(function(){
			$('a[href="#videocontainer"]').fancybox({
				titleShow: false, 
				opacity: true
			});
		});*/

        
        //Jetzt fangen wir noch ab, wenn wir auf einen link klicken
        $("div.appteaser h3 a, div.appteaser a.less").click(function(){
		  if ( window.location.hash == '#debug' ) {
			console.log($(this).parent().parent().parent());
			console.log($(this).parent().parent());
		  }

          expandToFrom(heights[$(this).parent().parent().parent().attr("id")], $(this).parent().parent(), 80, "div.appteaser");
        });
        
		$("a.trigger").click(function(){
        	expandToFrom(heights[$(this).parent().parent().attr("id")], $(this).parent(), 80, "div.appteaser");
        });
        
        $("div.appteaser span.more a").click(function(){
        	expandToFrom(heights[$(this).parent().parent().parent().parent().parent().attr("id")], $(this).parent().parent().parent().parent(), 80, "div.appteaser");
        });

	}, 20);


	function rotateShopList(count) {	
		var timeoutId = setTimeout( function() {
		$(".locationlist li:first-child").animate({height: 0}, 600, function(){
			$(this).addClass("hidden");
			$(".locationlist li.hidden:nth-child("+count+")").css("height", "auto");
				$(".locationlist li.hidden:nth-child("+count+")").removeClass("hidden");
				$(".locationlist li:last-child").before($(this));
				
			});
			rotateShopList(count); 
		}, 7000);
	}

	function expandToFrom(curHeight, who, basicHeight, identifier) {
		var h4 = null;
		//Wenn wir gerade nicht ausgeklappt sind
		if(who.hasClass("nonactive")) {
			//wir klappen einmal alle zu
			$(identifier).each(function(){
				$(this).addClass("nonactive");
				$(this).find("span.more").show();
				h4 = $(this).find('h4');
				if ( h4.length ) {
					basicHeight = (h4.height() + parseInt(h4.css('padding-bottom')) + parseInt(h4.css('padding-top'))); // + parseInt(h4.css('padding-bottom')) + parseInt(css('padding-top')) ) ;
				}
				$(this).animate({height: basicHeight}, 300, function(){
					$(who).find("span.more").hide();
				});
			});
			//Dann klappen wir dieses element aus
			$(who).animate({height: curHeight}, 300);
			//$(who).height(curHeight);
			$(who).removeClass("nonactive");
		}
		//Wenn wir gerade ausgeklappt sind, mŸssen wir nur uns wieder einklappen
		else {
			//wir klappen einmal alle zu
			$(identifier).each(function(){
				$(this).addClass("nonactive");
				h4 = $(this).find('h4');
				if ( h4.length ) {
					basicHeight = (h4.height() + parseInt(h4.css('padding-bottom')) + parseInt(h4.css('padding-top')));	
				}
				$(this).animate({height: basicHeight}, 300, function(){
					$(this).find("span.more").show();
				});
			}); 
		}
	}

});


