/**
 js file of hugoboss.com blog
 @projectDescription HugoBoss javascript library
 @author Werbewelt (biki)
 @version 1.0
 @namespace HugoBoss
 */
/**
 * @classDescription HugoBoss.hugoBlog hugoBlog javascript base
 */
HugoBoss.hugoBlog = {

	/**
	 * initialize
	 */
	init : function() {

		HugoBoss.hugoBlog.events.init();
		HugoBoss.hugoBlog.utils.init();
		HugoBoss.hugoBlog.utils.setTweetButton();
	},
	/**
	 * helper
	 */
	utils : {

		/**
		 * initialize
		 */
		init : function() {

			var teaser_amount = $('#secondary').find('.teaser_box').size();
			for(var i = 1; i <= teaser_amount; i++) {
				var myclass = $('#teaser_00' + i).attr('class');
				var zufall = Math.floor(Math.random() / (1 / 2) + 1);

				switch (zufall) {
					case 1:
						$('#teaser_00' + i).append('<img class="overteaser1" src="/blog/wp-content/themes/boss/images/' + myclass + '-rot.png" />');
						break;
					case 2:
						$('#teaser_00' + i).append('<img class="overteaser1" src="/blog/wp-content/themes/boss/images/' + myclass + '-schwarz.png" />');
						break;
				}

				$('#teaser_00' + i + ' .overteaser1').css('display', 'none');
			}
		},
		showAll : function() {
			$('#showAll_Blog').remove();
			where = document.URL.split("/");

			var where_country = where[3];
			var where_language = where[4];

			$('#categories-3 ul li:last').after('<li id="showAll_Blog" class="cat-item cat-item-999"><a title="HUGO Blog Startpage" href="/' + where_country + '/' + where_language + '/blog/">SHOW ALL</a></li>');

			$('#knrauthorlistwidget-3 ul li:last').after('<li id="showAll_Blog" class="cat-item cat-item-999"><a title="HUGO Blog Startpage" href="/' + where_country + '/' + where_language + '/blog/">SHOW ALL</a></li>');

			var author = $('#knrauthorlistwidget-3 ul li:eq(0)').children('a').text();
			$('#knrauthorlistwidget-3 ul li:eq(0)').children('a').html(author + ' <img id="author_stars" src="/blog/wp-content/themes/boss/images/3stars.png" />');

			var showall_link = $('#knrauthorlistwidget-3 ul li:last').find('a').attr('href');
			var trim_pos = showall_link.indexOf('category');
			showall_link = showall_link.substr(trim_pos);
		},
		setTweetButton : function() {
			$('.twitter-share-button').css('height', '24px');
		}
	},
	events : {
		init : function() {

			/**
			 * teaser left sidebar
			 */
			for(var i = 1; i <= 4; i++) {

				$('#teaser_00' + i).mouseenter(function() {
					$(this).children('.overteaser1').css('display', 'block');
				});

				$('#teaser_00' + i).mouseleave(function() {
					$(this).children('.overteaser1').css('display', 'none');
				});
			}

			/**
			 * foursqare teaser left sidebar
			 */
			$('#foursquare_teaser_box').mouseenter(function() {
				$('#foursquare_teaser_box a img').attr('src', '/blog/wp-content/themes/boss/images/foursquare-teaser_on.jpg');
			});

			$('#foursquare_teaser_box').mouseleave(function() {
				$('#foursquare_teaser_box a img').attr('src', '/blog/wp-content/themes/boss/images/foursquare-teaser_off.jpg');
			});
			/**
			 * teaser bottom
			 */
			$('.footer_mv_lifestyle_container').mouseenter(function() {
				$(this).children('.footer_pic_overlay').fadeOut(150);
				//.css('display', 'none');
				$(this).find('.footer_mv_lifestyle_link').css({
					color : '#cc0000'
				});
			});

			$('.footer_mv_lifestyle_container').mouseleave(function() {
				$(this).children('.footer_pic_overlay').fadeIn(150);
				//.css('display', 'block');
				$(this).find('.footer_mv_lifestyle_link').css({
					color : '#000000'
				});
			});
			/**
			 * Google Maps Locations
			 */
			$('#locations div a').bind('click', function() {
				var href = $(this).attr('href');
				var pos = href.indexOf('#');
				var id = href.substring(pos + 1);
				HugoBoss.flash.scrollToPosition(190, 100);
				HugoBoss.hugoBlog.gMaps.info.show(true, id);
				HugoBoss.hugoBlog.gMaps.pan.pause(true, HugoBoss.hugoBlog.gMaps.pan.hover);
				setTimeout(function() {
					HugoBoss.hugoBlog.gMaps.pan.pause(false, HugoBoss.hugoBlog.gMaps.pan.hover);
				}, 4000);
				return false;
			});

			$('#map').bind('mouseenter', function() {
				HugoBoss.hugoBlog.gMaps.pan.pause(true, true);
			});

			$('#map').bind('mouseleave', function() {
				HugoBoss.hugoBlog.gMaps.pan.pause(false, false);
			});
			/**
			 * Fashion Show Timer
			 */
			$('#fashionshowTimer a').bind('click', function(ev) {
				window.location = path + 'blog/category/fashion-show/';
				return false;
			});
		}
	},
	/**
	 * google maps teaser
	 */
	gMaps : {
		init : function() {
			//STARTPUNKT: http://maps.google.com/maps/api/geocode/xml?address=New+York,+NY&sensor=false
			var latlng;
			var href = window.location.href;
			if(href.indexOf('foursquare_fashionshow_2012.html#') !== -1) {
				var pos = href.indexOf('#');
				var id = href.substring(pos + 1);
				var marker = HugoBoss.hugoBlog.gMaps.markers.arr[id];
				latlng = new google.maps.LatLng(marker.lat, marker.lang);
				setTimeout(function() {
					HugoBoss.hugoBlog.gMaps.info.show(true, id);
				}, 100);
			} else {
				latlng = new google.maps.LatLng(52.5251900, 13.4037000);
			}
			var options = {
				backgroundColor : '#ffffff',
				zoom : 16,
				center : latlng,
				mapTypeId : google.maps.MapTypeId.ROADMAP,
				mapTypeControl : false,
				navigationControl : false,
				streetViewControl : false
			};
			HugoBoss.hugoBlog.gMaps.map = new google.maps.Map(document.getElementById('map'), options);

			/*
			 if (href.indexOf('fashionshow_deals_SS_2012.html') === -1) {
			 var ZoomPanControl = new missouristate.web.ZoomPanControl(HugoBoss.hugoBlog.gMaps.map);
			 ZoomPanControl.index = -1;
			 HugoBoss.hugoBlog.gMaps.map.controls[google.maps.ControlPosition.TOP_RIGHT].push(ZoomPanControl);
			 }
			 */
			HugoBoss.hugoBlog.gMaps.events();
		},
		events : function() {
			google.maps.event.addListenerOnce(HugoBoss.hugoBlog.gMaps.map, 'idle', function() {
				HugoBoss.hugoBlog.gMaps.loaded();
			});
		},
		loaded : function() {
			HugoBoss.hugoBlog.gMaps.markers.init();
			var href = window.location.href;
			if(href.indexOf('foursquare_fashionshow_2012.html#') === -1) {
				HugoBoss.hugoBlog.gMaps.pan.play();
			}
		},
		markers : {
			init : function() {
				HugoBoss.hugoBlog.gMaps.markers.set();
			},
			arr : [{//0
				title : 'Bravo Bar',
				tag : 'bar',
				lat : 52.5271211,
				lang : 13.3879152,
				text : 'A new place for creative minds! Check in at Bravo Bar and we are offering you a drink for 5 &euro; and a fashionable HUGO bracelet for FREE!',
				link : 'https://de.foursquare.com/v/bravo-bar/4eda9377b6344371f71d14fb',
				type : 2
			}, {//1
				title : 'Oukan71',
				tag : 'restaurant, boutique',
				lat : 52.5113000,
				lang : 13.3877500,
				text : 'A concept store with a touch of japanese avant-garde. Experience fashion and great food in a dreamlike location. Check in with us to get macaroons for 2,50 &euro; or a Matcha Latte for 3,20 &euro; for FREE!',
				link : 'https://de.foursquare.com/v/oukan-71/4ef339016c253bf124b475ea',
				type : 2
			}, {//2
				title : 'TRANSIT',
				tag : 'restaurant',
				lat : 52.5286464,
				lang : 13.4022633,
				text : 'A new Asian restaurant - not far from the HUGO Concept Store – which quickly became THE meeting place for the young urban crowd. Check in with us to get appetizers for 3 &euro; for free!',
				link : 'https://de.foursquare.com/v/transit-mitte/4ae1976ef964a5205a8621e3',
				type : 2
			}, {//3
				title : 'Do You Read Me?!',
				tag : 'store',
				lat : 52.5271297,
				lang : 13.3978092,
				text : 'Our favorite magazine shop in Berlin! Unlock the HUGO BOSS special to get a bag with a surprise magazine and a special HUGO bracelet for FREE!',
				link : 'https://de.foursquare.com/v/do-you-read-me/4adcda91f964a5209b4b21e3',
				type : 2
			}, {//4
				title : 'FIN – Fashion Week Closing Party by DERZEIT Sa. 21.1.2012, 23:00 – open endK-TV',
				tag : 'closing party, club',
				lat : 52.5332202,
				lang : 13.3800204,
				text : 'Celebrate the end of Berlin Fashion Week at the FIN Closing Party at the KTV Club. Check in on January 21st, 2012, to score a place on the guest list!',
				link : 'https://de.foursquare.com/v/fin/4f0ce4a90cd60a7d1ee39c17',
				type : 2
			}, {//5
				title : 'Brut',
				tag : 'caf&eacute, bar',
				lat : 52.5288200,
				lang : 13.4075600,
				text : 'Our favorite snack bar in Berlin. Stop by for a quick meal and an aperitif before a night out! Check in, unlock our special and enjoy an aperitif  for 5 &euro; & get a fashionable HUGO bracelet for free!',
				link : 'https://de.foursquare.com/v/brut/4d7aa2127ea26ea8b38fc78f',
				type : 2
			}, {//6
				title : 'NoMoreSleep Coffee',
				tag : 'caf&eacute',
				lat : 52.5276913,
				lang : 13.4043102,
				text : 'HUGO BOSS and „No more sleep“ make sure you get your daily dose of caffeine during Fashion Week! Check in with us to receive a coffee for 2,20 &euro; & a special HUGO bracelet for free! ',
				link : 'https://de.foursquare.com/v/nomoresleep/4d8326a55e70224b3e68f108',
				type : 2
			}, {//7
				title : 'Lokal',
				tag : 'restaurant, caf&eacute;',
				lat : 52.5289301,
				lang : 13.4010756,
				text : '&bdquo;Das Lokal&ldquo; offers delicious German food in a cozy atmosphere. Check in with HUGO BOSS to get the dessert of the day (for 6 &euro;) & an exclusive HUGO bracelet for free!',
				link : 'https://de.foursquare.com/v/lokal/4e7cb60fb80309e0eaa95e08',
				type : 2
			}, {//8
				title : 'HUGO Store',
				tag : 'store',
				lat : 52.5251900,
				lang : 13.4037000,
				text : 'During Fashion Week the HUGO Concept Store is abuzz with fashion addicts! Check in to get a HUGO Tracks Compilation CD and a fashionable HUGO bracelet for free!',
				link : 'https://de.foursquare.com/venue/529588',
				type : 1
			}],
			set : function() {

				var locations = HugoBoss.hugoBlog.gMaps.markers.arr;
				for(var i = 0; i < locations.length; i++) {

					var location = locations[i];

					var image = new google.maps.MarkerImage('/blog/wp-content/themes/boss/images/marker' + location.type + '.png', new google.maps.Size(27, 45));

					var myLatLng = new google.maps.LatLng(location.lat, location.lang);
					var marker = new google.maps.Marker({
						position : myLatLng,
						map : HugoBoss.hugoBlog.gMaps.map,
						icon : image,
						zIndex : i
					});
					google.maps.event.addListener(marker, 'click', HugoBoss.hugoBlog.gMaps.info.show);
				}

				HugoBoss.hugoBlog.gMaps.info.init();
			}
		},
		info : {
			init : function() {
			},
			show : function(ext, pos) {
				HugoBoss.hugoBlog.gMaps.info.remove();
				var id;
				if(ext === true) {
					id = pos;
				} else {
					id = this.zIndex;
				}
				var marker = HugoBoss.hugoBlog.gMaps.markers.arr[id];
				var position = new google.maps.LatLng(marker.lat, marker.lang);
				var content = '<div id="infoBoxContent" class="color' + marker.type + '"><a href="' + marker.link + '" target="_blank">'
				content += '<strong>' + marker.title + '</strong> ';
				content += '<br /><em>' + marker.tag + '</em>';
				content += '<p>' + marker.text + '<span>See the venue on Foursquare</span></p></div></a>'

				HugoBoss.hugoBlog.gMaps.infobox = new InfoBox({
					latlng : position,
					map : HugoBoss.hugoBlog.gMaps.map,
					content : content
				});
				HugoBoss.hugoBlog.gMaps.map.setZoom(16);
				HugoBoss.hugoBlog.gMaps.map.setCenter(position);

				$('#locations div a').removeClass('active');
				$('#locations div a[href=#' + id + ']').addClass('active');

			},
			remove : function() {
				if(HugoBoss.hugoBlog.gMaps.infobox) {
					HugoBoss.hugoBlog.gMaps.infobox.setMap(null);
				}
			}
		},
		pan : {
			play : function() {
				setTimeout(function() {
					if(HugoBoss.hugoBlog.gMaps.pan.stop === false && HugoBoss.hugoBlog.gMaps.pan.hover === false) {
						if($('#locations div a.active').length !== 0) {
							var href = $('#locations div a.active').attr('href');
							var pos = href.indexOf('#');
							if(parseInt(href.substring(pos + 1)) === 9) {
								HugoBoss.hugoBlog.gMaps.pan.pos = 0;
							} else {
								HugoBoss.hugoBlog.gMaps.pan.pos = parseInt(href.substring(pos + 1)) + 1;
							}
						} else if(HugoBoss.hugoBlog.gMaps.pan.pos === undefined) {
							HugoBoss.hugoBlog.gMaps.pan.pos = 0;
						} else {
							HugoBoss.hugoBlog.gMaps.pan.pos += 1;
						}
						HugoBoss.hugoBlog.gMaps.info.remove();
						var id = HugoBoss.hugoBlog.gMaps.pan.pos;
						HugoBoss.hugoBlog.gMaps.info.show(true, id);
					}
					HugoBoss.hugoBlog.gMaps.pan.play();
				}, 4000);
			},
			pause : function(stop, hover) {
				HugoBoss.hugoBlog.gMaps.pan.stop = stop;
				HugoBoss.hugoBlog.gMaps.pan.hover = hover;
			},
			stop : false,
			hover : false
		}
	},
	countdown : function(time) {
		var endDate = new Date(2012, 0, 19, 13, 30, 0);
		var endTime = endDate.getTime();
		var time2Go = Math.floor(endTime - time);

		var seconds2go = parseInt(time2Go / 1000);
		var minutes2go = parseInt(seconds2go / 60);
		seconds2go = seconds2go - (minutes2go * 60);
		var hours2go = parseInt(minutes2go / 60);
		minutes2go = minutes2go - (hours2go * 60);
		var days2go = parseInt(hours2go / 24);
		hours2go = hours2go - (days2go * 24);

		if($('#videoplayerJS').length === 0) {
			if(days2go === 0 && hours2go === 0 && minutes2go == 2 && seconds2go === 0) {
				window.location.reload();
			}
		}

		if(days2go <= 0 && hours2go <= 0 && minutes2go <= 0 && seconds2go <= 0) {
			//$('.timer').html('WATCH THE HUGO FASHION SHOW NOW!');
		} else {

			var timer = '';
			if(days2go === 1) {
				timer += '1 DAY - ';
			} else if(days2go === 0) {
				timer += '';
			} else {
				timer = days2go;
				timer += ' DAYS - ';
			}
			if(hours2go === 1) {
				timer += '1 HOUR - ';
			} else if(hours2go === 0) {
				timer += '';
			} else {
				timer += hours2go;
				timer += ' HOURS - ';
			}
			if(minutes2go === 1) {
				timer += '1 MINUTE - ';
			} else if(minutes2go === 0) {
				timer += '';
			} else {
				timer += minutes2go;
				timer += ' MINUTES - ';
			}
			if(seconds2go === 1) {
				timer += '1 SECOND - '
			} else if(seconds2go === 0) {
				timer += '';
			} else {
				timer += seconds2go;
				timer += ' SECONDS - '
			}
			timer = timer.substring(0, timer.lastIndexOf('-'));
			timer += 'REMAINING'
			$('.timer').html(timer);
		}

		var timeout = setTimeout(function() {
			HugoBoss.hugoBlog.countdown(time + 1000);
		}, 1000);
	}
};

/**
 * dom ready event to initialize all
 */
$(document).ready(function() {

	HugoBoss.hugoBlog.init();

	if($('#mainTeaserMap').length !== 0) {
		HugoBoss.hugoBlog.gMaps.init();
	}
	if($('#categories-3').length !== 0) {
		HugoBoss.hugoBlog.utils.showAll();
	}
	if($('#countdown').length !== 0) {
		HugoBoss.hugoBlog.countdown(currentTime * 1000);
	}
});

