jQuery(document).ready(function($){

var base = $('head base').attr('href');

//bookmark
function bookmark(url, title) {
	if (window.sidebar) { // firefox
	window.sidebar.addPanel(title, url, "");
	} else if(window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if(document.all) {// ie
		window.external.AddFavorite(url, title);
	}
}

//载入用户信息
	$.ajax({
		url: login_session_url,
		dataType: 'json',
		success: function(data) {
		
			if(data.account.id){
				$('#session_container .account-class-1').html(''
				+ '<a href="' + login_static_account + '" class="">' + data.account.email + '</a>'
				);
				$('#session_container .account-class-2').html(''
				+ ' <a href="' + login_static_logout + '" class="">' + login_static_text_logout + '</a>'
				);
				$('#session_container .session_container-col-1 .account-class-1 a').css("float","right");
			}
			if(data.cart.products){
				$('#session_container .amount, .account_account_page .amount').html(data.cart.total.amount+' Items,');
				$('#session_container .total, .account_account_page .total').html('Total: <span class="special_price">' + data.cart.totals[data.cart.totals.length-1].text + '</span>');
				$('.button_tiny_checkout').css("display","inline-block");
			}
		}
	});
	

	
	//搜索blur
	$('#filter_keyword').css('color','grey').focus(function(){
		$(this).val('');
		$(this).css('color','black');
	}).blur(function(){
		if($(this).val() == ''){
			$(this).val('Keyword').css('color','grey');
		}
		
	});



	
	$.tabs = function(selector, start) {
		$(selector).each(function(i, element) {
			$($(element).children('a').attr('href')).css('display', 'none');

			$(element).click(function() {
				$(selector).each(function(i, element) {
					if(this!==element) return;
					$(element).removeClass('selected');
					$($(element).children('a').attr('href')).css('display', 'none');
				});

				$(this).addClass('selected');

				$($(this).children('a').attr('href')).css('display', 'block');
				return false;
			});
		});
		if (!start) {
			start = $(selector + ':first').children('a').attr('href');
		}
		$(selector).find('a[href=\'' + start + '\']').trigger('click');
	};
	
	
	
	
	
	
//判断当前页面


	var pathname = document.location.pathname;
	var search = document.location.search;
	if(pathname.indexOf("special") != -1){
		$('#tab_special').addClass('selected');
	}
	else if(pathname.indexOf("weddingguide") != -1){
		$('#tab_wedding_guide').addClass('selected');
	}
	else if(search.indexOf("information/contact") != -1){
		$('#tab_contact').addClass('selected');
	}
	else if(search.indexOf("account/login") != -1){
		$('#tab_login').addClass('selected');
	}
	else if(search.indexOf("checkout/cart") != -1){
		$('#tab_cart').addClass('selected');
	}
	else{
		$('#tab_home').addClass('selected');
	}

	
	
	
//搜索回车
	$('#filter_keyword').keydown(function(e) {
		if (e.keyCode == 13) {
			moduleSearch();
		}
	});
	$('.search_submit').click(function(){
		moduleSearch();
	});

	function moduleSearch() {
		url = base + 'index.php?route=product/search';
		
		var filter_keyword = $('#filter_keyword').attr('value')
		
		if (filter_keyword) {
			url += '&keyword=' + encodeURIComponent(filter_keyword);
		}
		
		var filter_category_id = $('#filter_category_id').attr('value');
		
		if (filter_category_id) {
			url += '&category_id=' + filter_category_id;
		}
		
		location = url;
	}



//待补充
	$('.switcher').bind('click', function() {
		$(this).find('.option').slideToggle('fast');
	});
	$('.switcher').bind('mouseleave', function() {
		$(this).find('.option').slideUp('fast');
	}); 

	
//border-radius
if ( $.browser.msie ) {
	if( $.browser.version < 9){
		//$('#header .top_nav a').corner("round top 8px");
		//$('#header .header_bar').corner("round tl 8px");
		//$('.box .box-title').corner("round top 8px");
		//$('#content .top .center').corner("round top 8px");
		
		$(".button span").wrap('<span />');
		$('.button span span').textShadow({
			x:      0, 
			y:      -4, 
			radius: 2,
			color:  "#888"
		});
	};
}

	$('.hover-box-container').children().each(function(i,j){
		$(j).hoverIntent({
			over: function(){
				$(this).addClass('hover-box-active');
			},
			timeout: 0,
			out: function(){
				$(this).removeClass('hover-box-active');
			}
		});
	});
	

});
