/*!
 * PLP
 */

var PHL = {
	QAForm: function(uri) {
		this.openSubWin(uri, 820, 435, 'QAForm', 'status=yes, scrollbars=yes, resizable=yes');
	},
	
	openSubWin: function(uri, w, h, n, f) {
		w = w || 735;
		h = h || 560;
		var windowName = n || 'PLPSubWindow';
		var features = f || 'status=yes, scrollbars=yes, resizable=yes';
		if(/chrome/.test(navigator.userAgent.toLowerCase())) { h = h + 50; }
		features += ', width=' + w + ', height=' + h;
		if(window.screen.width > w)  features += ', left=' + (window.screen.width - w) / 2;
		if(window.screen.height > h) features += ', top=' + (window.screen.height - h) / 4;
		window.open(uri, windowName, features);
	},
	
	globalNavigation: function() {
		var labels = ['shaver', 'sonicare', 'headphone'];
		var allMenu = '.global-nav-menu';
		var allNavAnchor = '.global-navigation li a';
		var menuMouseOutTimer;
		if(!/MSIE (6\.)/.test(navigator.userAgent)){
			$(labels).each(function(){
				var nav = '#' + this + '-trigger';
				var navAnchor = nav + ' a';
				var menu = '#' + this + '-menu';
				$(nav).hover(
					function(){
						clearTimeout(menuMouseOutTimer);
						$(allMenu).hide();
						if($(navAnchor).hasClass('active')) {
							$(menu).show();
							$(allNavAnchor).removeClass('active');
							$(navAnchor).addClass('active');
						} else {
							$(menu).slideDown(200, function(){
								if($(navAnchor).hasClass('active')) {
									$(allMenu).hide();
									$(menu).show();
								} else {
									$(menu).hide();
								}
							});
							$(allNavAnchor).removeClass('active');
							$(navAnchor).addClass('active');
						}
					}, function(){
						$(allMenu).hide();
						$(navAnchor).removeClass('active');
					}
				);
				$(menu).hover(
					function(){
						$(allMenu).hide();
						$(menu).show();
						$(navAnchor).addClass('hover').addClass('active');
					}, function(){
						$(allMenu).hide();
						$(navAnchor).removeClass('hover');
						menuMouseOutTimer = setTimeout(function(){
							$(navAnchor).removeClass('active');
						}, 300);
					}
				);
			});
		} else {
			$(labels).each(function(){
				var nav = '#' + this + '-trigger';
				var menu = '#' + this + '-menu';
				var selector = nav + ',' + menu;
				$(selector).hover(
					function(){
						$(menu).show();
						$(nav + ' a').addClass('hover');
					}, function(){
						$(menu).hide();
						$(nav + ' a').removeClass('hover');
					}
				);
			});
		}
	},
	
	productContentTab: function() {
		var obj = $('.product-content');
		var ids = ['shaver', 'sonicare', 'headphone'];
		$(obj).each(function(){
			var self = this;
			$('.pane', self).hide();
			
			//set random open list
			var num = Math.floor(Math.random()*3);
			var pane = '#' + ids[num];
			var tab = '.' + ids[num] + '-tab a';
			$(pane).show();
			$(tab).addClass('selected');
			
			$('.visual-tabs li', self).each(function(){
				var target = '#' + $(this).attr('class').replace('-tab', '');
				var a = $(this).find('a');
				if($.browser.msie) $(a).focus(function(){this.blur();});
				$(a).click(function(){
					if(!$(this).hasClass('selected')){
						$('.visual-tabs li a', self).removeClass('selected');
						$('.pane', self).hide();
						$(this).addClass('selected');
						$(target).show();
						return false;
					}
				});
			});
		});
	},
	
	snsSectionTab: function() {
		var obj = $('.sns-section');
		$(obj).each(function(){
			var self = this;
			$('.sns-section-pane', self).hide();
			//set default open list
			$('.sns-section-pane:first', self).show();
			$('.sns-section-tabs li:first a', self).addClass('selected');
			$('.sns-section-tabs li', this).each(function(){
				var a = $(this).find('a');
				var href = a.attr('href');
				if($.browser.msie) $(a).focus(function(){this.blur();});
				$(a).click(function(){
					$('.sns-section-tabs li a', self).removeClass('selected');
					$('.sns-section-pane', self).hide();
					$(this).addClass('selected');
					$(href).show();
					return false;
				});
			});
		});
	},
	
	snsSectionReviewTab: function() {
		var obj = $('.sns-section .reviews');
		$(obj).each(function(){
			var self = this;
			$('.product-review', self).hide();
			//set default open list
			$('.product-review:first', self).show();
			$('.product-list li:first a', self).addClass('selected');
			$('.product-list li', this).each(function(){
				var a = $(this).find('a');
				var href = a.attr('href');
				if($.browser.msie) $(a).focus(function(){this.blur();});
				$(a).click(function(){
					$('.product-list li a', self).removeClass('selected');
					$('.product-review', self).hide();
					$(this).addClass('selected');
					$(href).show();
					return false;
				});
			});
		});
	},
	
	floatingBanner: function() {
		if(!/MSIE (6\.|7\.)/.test(navigator.userAgent)) {
			obj = $('#enquete-banner');
			$(obj).css({'position': 'fixed', 'bottom': 0});
			var footerTop = $('.footer').offset().top;
			var windowHeight = $(window).height();
			var p = footerTop - windowHeight;
			var ab = windowHeight - footerTop;
			
			var setScroll = function(){
				$(window).scroll(function(event){
					var y = $(this).scrollTop();
					if(y >= p){
						$(obj).css({'position': 'absolute', 'bottom': ab});
					} else {
						$(obj).css({'position': 'fixed', 'bottom': 0});
					}
				});
			};
			
			setScroll();
			
			$(window).resize(function(event){
				footerTop = $('.footer').offset().top;
				windowHeight = $(window).height();
				p = footerTop - windowHeight;
				ab = windowHeight - footerTop;
				$(obj).css({'position': 'absolute', 'bottom': ab});
				setScroll();
			});
		}
	},
	
	showEnqueteForm: function() {
		var time = 15000;
		if($.cookie('enq')) {
			//$.cookie('enq', null);
			$.cookie('enq', 'yes', { expires: 30 });
		} else {
			setTimeout(function(){
				if($('#TB_window').css('display') != 'block') {
					tb_show(null,"#TB_inline?height=260&width=460&inlineId=enquete-form&modal=true",false);
				}
			}, time);
			$.cookie('enq', 'yes', { expires: 30 });
		}
	}
};

// http://havelog.ayumusato.com/develop/javascript/entry-86.html
function jsPlaceholder() {
	$('.js-placeholder').each(function ( ){
	    (function ( elm ) {
	        var defaultColor    = '#999';
	        $.data(elm, 'placeholder-string', $(elm).attr('title'));
	        $.data(elm, 'placeholder-color', $(elm).css('color'));
	        switch ( $(elm).val() ) {
	            case '' :
	                $(elm).val($.data(elm, 'placeholder-string'));
	            case $.data(elm, 'placeholder-string') :
	                $(elm).css('color', defaultColor);
	            break;
	        }
	        $(elm).focus(function ( )
	        {
	            if ( $(this).val() == $.data(this, 'placeholder-string') ) {
	                $(this).val('');
	                $(this).css('color', $.data(this, 'placeholder-color'));
	            }
	        });
	        $(elm).blur(function ( )
	        {
	            if ( $(this).val() == '' ) {
	                $(this).val($.data(this, 'placeholder-string'));
	                $(this).css('color', defaultColor);
	            }
	        });
	        $(elm).parents().filter('form').submit(function ( )
	        {
	            if ( $(elm).val() == $.data(elm, 'placeholder-string') ) {
	                $(elm).val('');
	            }
	            return true;
	        });
	    })( this )
	});
}

var startSuggest = function(){new Suggest.Local("search-field", "search-suggest", suggestList, {dispMax:35});};



