/* 
 * GLOBAL TOOLS AND UTILITIES
 * Place all custom scripts here.
 *
*/

(function($) {
	
	// Home Page Banner Slider
	if($('#wp_slider')[0]){
		$('#wp_slider').anythingSlider({
			delay           : 6000,
			width           : 962,   // Override the default CSS width
			height			: 330,   // Override the default CSS height
			pauseOnHover        : false, 
			hashTags            : false, 
			// easing          : 'easeInOutBack',  // slider effects
			autoPlayLocked  : true,  // If true, user changing slides will not stop the slideshow
			resumeDelay     : 6000, // Resume slideshow after user interaction, only if autoplayLocked is true (in milliseconds).
			onSlideComplete : function(slider){
				// event after slide load complete
				// $('.anythingSlider .arrow, .start-stop').remove();
				$('.start-stop').remove();
			},
			stopAtEnd : false,  // true if slider will stop at the end of the slide, false if slider is continuous
			onShowStop : function(e, slider){
				setTimeout(function(){
					if (slider.currentPage === slider.pages) { slider.gotoPage(1); }
				}, 6000);
			}
		});
	}
	
	
	// ** Breadcrumbs
	// Blog Detail
	if($('#catblogoutput .title')[0]){
		$('.breadcrumbs').html('<a href="/">Home</a><a href="/news">News</a><a href="'+document.location.pathname+'" class="current" >'+$('#catblogoutput .title a').html()+'</a>');
	}
	// System Messages
	if($('.system-error-message')[0]){
		$('.breadcrumbs').html('<a href="/">Home</a><a href="javascript:void(0)">'+$('.system-error-message h1').text()+'</a>');
	}
	// Ecommerce - Product
	if($('.catalog_breadcrumbs')[0]){
		$('.breadcrumbs').html('<a href="/">Home</a>'+$('.catalog_breadcrumbs').html().replace(':',''));
		if($('.productLarge')[0]){
			$('.breadcrumbs').append('<a href="'+document.location.pathname+'">'+$('.productLarge p.title').html()+'</a>');
		}
	}
	// Shopping Cart
	if($('#catCartDetails .shopping-cart')[0] || $('#catCartDetails .cartLink')[0]){
		$('.breadcrumbs').html('<a href="/">Home</a><a href="/OrderRetrievev2.aspx">Shopping Cart </a>');
	}
	// Checkout
	if($('#catCartDetails .shop-checkout')[0] ){
		$('.breadcrumbs').html('<a href="/">Home</a><a href="/OrderRetrievev2.aspx">Shopping Cart </a><a href="javascript:void(0)">Check Out</a>');
	}
	// Receipt
	if($('#catCartDetails .shop-receipt')[0] ){
		$('.breadcrumbs').html('<a href="/">Home</a><a href="/OrderRetrievev2.aspx">Shopping Cart </a><a href="javascript:void(0)">Check Out</a><a href="javascript:void(0)">Receipt</a>');
	}
		
		
	
	// Blog - Recent Post
	if($('#catblogoutput .news-box')[0]){
		$('.breadcrumbs').html('<a href="/">Home</a><a href="/news" class="current">News</a>');
		$('.news-article').addClass('textarea').removeClass('news-article');
		$('.textarea .right-area ').remove();
	}
	
	
	// ** Link Specials Hover
	$('.link-specials').hover(function(){
		$('.corkboard .specials').css('background','url("../images/img-specials-shadow3.png") repeat scroll 0 0 transparent');
	},function(){
		$('.corkboard .specials').css('background','url("../images/img-specials-shadow2.png") repeat scroll 0 0 transparent');
	});
	
	
	// ** Sign up for our special colorbox
	$(".link-specials").colorbox({width:"446px", height: '435px', inline:true, href:"#link_specials_content", opacity: 0.9});
	// ** Contact Us colorbox
	$(".contact_pop_btn").colorbox({width:"446px", height: '435px', inline:true, href:"#contact_form_content", opacity: 0.9});
	
	
	// Breadcrumbs last link - remove arrow
	$('.breadcrumbs a:last').addClass('current');
	
	
	// ** Overall Ecommerce Layout
	// Catalog Table
	if($('.catalogueItemNotFound')[0]){
		$('table.catalogueTable').remove();
	}
	// Product Table
	if($('.productItemNotFound')[0]){
		$('table.productTable').remove();
	}
	
	// Catalog view Link
	if($('.catalogueTable')[0]){
		$('.catalogueTable .product-box').each(function(){
			var aLn1 = $(this).find('.bottom a:first').attr('href');
			$(this).find('.bottom a:last').attr('href',aLn1);
		});
	}
	
	// shopping cart value
	$('.scart_link_value').html($('#catCartSummary .cartSummaryItem').html().split(' ')[0].replace('Shopping','0'));
	
	// ecommerce catalog menu set selected
	if ($('.productLarge')[0]) {
		var urlProd = document.location.pathname;
		$('#nav_1235366 li').each(function(){
				var menuHref = $(this).find('a:first').attr('href');
				if(urlProd.indexOf(menuHref, 0) != -1){
					$(this).addClass('selected');
					if($(this).parents('li').length != 0){
						$(this).parents('li').addClass('selected');
					}
				}
		});
	}
	
	// ** shopping cart
	if($('#catCartDetails .shopping-cart')[0]){
		var IntervalId = 0;
		IntervalId = setInterval ( function(){
			$('.shopcartHid').addClass('s_edited');	
			
			var prDlength = $('.shopcartHid .p_name .productitemcell').length-1;
			var tableCodeShopCart = "";
			if($('.item-row').length <= prDlength){
				for(var i = 0; i <= prDlength; i++){
					tableCodeShopCart += 	'<div class="item-row">'+
											'<div class="col-1 left">'+
											'<div class="img-holder"><img src="/Utilities/ShowThumbnail.aspx?USM=1&amp;W=87&amp;H=84&amp;R=1&amp;Img='+$('.shopcartHid .p_image .productitemcell:eq('+i+') img').attr('src')+'" alt=""></div>'+
											'</div>'+
											'<div class="col-2 left">'+
											'<p class="title">'+$('.shopcartHid .p_name .productitemcell:eq('+i+')').html()+'</p>'+
											'</div>'+
											$('.shopcartHid .p_quantity .productitemcell:eq('+i+')').html()+
											'</div>'+
											'<div class="clr"></div>'+
											'<span class="removeLinkCart">'+$('.shopcartHid .p_removelink .productitemcell:eq('+i+')').html()+'</span>'+
											'</div>';
					// alert(tableCodeShopCart[i]);
					// 
				}	
				$('.shopcart_cont').html(tableCodeShopCart);
				
				// google map get direction
				$(".map_distance_btn").colorbox({width:"650px", height: '250px', iframe:true, opacity: 0.9});
				
				var aHref = $('#catshopbuy').attr('href')+'&cartsubtotal='+$('.hidsubTotal').text()+'&carttax='+$('.hidtax').text()+'&cartamount='+$('.hidamount').text();
				$('#catshopbuy').attr('href',aHref);
			}
		}, 1000 );	
	}
	
	// ecommerce catalog menu-main prevent click
	$('.not-clkle > a').click(function(e){
		 e.preventDefault();
	});
	
	// google map get direction
	$(".map_distance_btn").colorbox({width:"650px", height: '250px', iframe:true, opacity: 0.9});
	
	
	// logo animation
	$('#footer .col-1 .row .site-by .splash a').hover(function(){
		$(this).find('img:first').fadeOut(300);
	},function(){
		$(this).find('img:first').fadeIn(300);
	});
	
	
})(jQuery); 


function ecommerceProductDetail(){
	// large image resize
/* 	var imgSrc = jQuery('.prod_lrg_img img').attr('src');
	jQuery('.product .img-holder').html('<img src="/Utilities/ShowThumbnail.aspx?USM=1&amp;W=257&amp;H=247&amp;R=1&amp;Img='+imgSrc+'" alt="#">');
*/ 
	
	// product tabbing
	var n = jQuery(".selTab").queue("fx");
	jQuery('.tabs a').click(function(){
		var aHref = jQuery(this).attr('rel');
		jQuery('.selTab').hide();
		jQuery('#'+aHref).show().addClass('selTab');
	});
	
	// shopping cart value
	jQuery('.scart_link_value').html(jQuery('#catCartSummary .cartSummaryItem').html().split(' ')[0].replace('Shopping','0'));
}


( function($) {

	$.fn.Center = function() {
        
		return this.each( function() {
					
			var _parent = $(this).parent();
			var _self = $(this);
			
			if ( _parent.innerHeight() === _self.innerHeight() )
				return;
    
			var elWidth = _self.width();
			var elHeight = _self.height();
			var elParentWidth = _parent.width();
			var elParentHeight = _parent.height();

			var offsetW = (elParentWidth - elWidth) / 2;
			var offsetH = (elParentHeight - elHeight) / 2;
       			
			if ( _parent.css("overflow") !== "hidden" ) {
				_parent.css("overflow", "hidden");
			} 					
			_self.css( "margin-top", offsetH + "px" );
			_self.css( "margin-left", offsetW + "px" );
				
			if ( _self.css( "display" ) === "inline" ) {
				_self.css( "display", "inline-block" );
			}
		});
	};

})(jQuery);

$(document).ready( function() {

    //$(".ecom #display-area .content .product-box .body .img-holder img").css("width", "100px");
    $(".ecom #display-area .content .product-box .body .img-holder img").Center();

});

Oshoplang = { 

InvalidShip: 'ERROR: Please choose a valid delivery option.',

};
