var $j = jQuery.noConflict();

jQuery(document).ready(function($) {
	
	$('body')
		.removeClass('javascript-disabled')
		.addClass('javascript-enabled');

	
		if($j('#mycurl-wrapper').length){
			$j('body').css('background', '#000');
		}

// menuHeight ------------------------------------------------------------*/
 
 if($j('#menu-main').length){
 	
	$j('body').addClass('menu-height-1');
	$j('#menu-main-container').height(33);
	
 }

if($j('#menu-main ul').length){
 	
	$j('body').addClass('menu-height-2');
	$j('#menu-main-container').height(66);
	
 }
 
 if($j('#menu-main ul ul').length){
 	
	$j('body').addClass('menu-height-3');
	$j('#menu-main-container').height(99);
	
 }
	
// virtueMart Tidy Up ------------------------------------------------------------*/
/*
$j('h3:contains("Checkout")').css('display', 'none');
$j('h4:contains("Please select a Payment Method!")').css('display', 'none');

// Security Message

$j('label:contains("Please enter your credit card details:")')
	.css('font-weight', 'bold')
	.after('<div class="security-message"><p style="padding: 20px 0 0 0;">This is a secure transaction with Australian safest online system <a href="http://www.eway.com.au" target="_blank">Eway - Online payments made easy!</a></p></div>');

 disable thumbnail to flypage 

	$j('.product-image').click(function(event){
		event.preventDefault();		
	});

if ($j('.shop_error').length > 0) {
	alert('There was an error with the Credit Card details you entered. You have not been charged. Please check your details and proceed again.');
	document.location.href = 'index.php?page=checkout.index&option=com_virtuemart&Itemid=51&redirected=1&Itemid=51';
} else {
// final confirmation auto proceed
if ($j('#sibbling-display-none').length > 0){
	
	$j('form').css('display', 'none');
	
	$j('input.inputbox').attr('checked', true);
	
}

if ($j('input[value="Confirm Order"]').length > 0) {
	
	$j('input[value="Confirm Order"]').trigger('click');

}
}
*/
/* update form maximum 1 */

  var action = window.location;
  $j("#update-form form").attr("action", action);
	
	
		$j('#update-form input.inputbox').each(function(){
			
				$j(this).after('<a class="delete-item" href="#">Delete this item</a>');
				
		});
	
		$j('.delete-item').click(function(event){
     		
			$j(this)
					.siblings('input.inputbox')
					.val(0)
					.siblings('input[title="Update Quantity In Cart"]')
					.css('background', 'yellow')
					.stop()
					.trigger('click');
					
     event.preventDefault();
});

	
	
		$j('input[alt="Delete Product From Cart"]').live('click', function() {
    	
			this.blur();  	
			return false;
		
		});


if ($j('#update-form input.inputbox').length){
	
	
	$j('#update-form input.inputbox').each(function(){
	
		if ( $j(this).val() > 1 )
			{
								
				$j(this)
					.val(1)
					.siblings('input[title="Update Quantity In Cart"]')
					.trigger('click');
				
			}
		
	});
	
	


}

/*
if($j('label:contains("Please enter your credit card details:")').length){
	
	$j('th:contains("Delete")').html('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
	$j('a.delete-item').html('');
	$j('form[onsubmit="return checkCouponField(this);"]').closest('td').hide();
}
*/

// youTubePreview ------------------------------------------------------------*/
	
	//wrap youtube with slide-wrapper
/*	
	if($j('.you-tube').length){
		
		$j('#content-container')
			.append('<div class="white-background"></div>')
			.find('.white-background')
			.css({
				'background' : '#fff',
				'display' : 'none'
			});
		
		$j('.you-tube')
			.wrap('<div class="slide-wrapper" />')
			.wrap('<div class="slide-wrapper-inner" />')
			.parent('.slide-wrapper-inner')
			.append('<a class="you-tube-close" title="Close" href="#">Close</a>')
			.before('<a class="pop-out preview" href="#">Preview</a>');
	}
	
	//close all previews before toggling
	
	$j('.slide, .you-tube-close').click(function(){
		$j('.slide-wrapper-inner, .white-background').css('display', 'none');

	
	});
*/
	//modal functionality

	$j(".pop-out").each(
	
		function() {
							
			var popOut = $j(this);
			
			popOut.click(function(){
				
				$j('.white-background')
					.css({
						'z-index' : 2,
						'display' : 'block',
						'opacity' : 0.5
					});
				
				
				$j(this).siblings('.slide-wrapper-inner')
					.css({
						'display': 'block',
						'z-index' : 5
 										
				}); 
							
			});
			
	
			//Add to cart custom
			
			$j('.addtocart_button').click(function(){
				
				//$('#vmLogResult').prepend('<h1>Your video course has been added to your cart</h1>');
				//alert('addtocart_button');

			
			});
			
			
		}
	
	);

		
		//////////////////////////////////////////// media gallery

		if($j('#dario-media-gallery').length){
				
			//media gallery 
			
			mediaGallery(
				
				'#dario-media-gallery', //selector
				'img', //element to target
				'400px', //element height
				'300px', //div width
				'400px'	//div height
			
			);
	
		}
		
		function mediaGallery( selector, element, elementHeight, divWidth, divHeight)
		{
						
			$j(selector).after(	
				
				'<div class="scroll-bar-wrap">' +
				'<div class="scroll-bar"></div>' +
				'</div>')
				.addClass('scroll-content')
				.wrap('<div class="scroll-pane">');
							
			$j(selector + ' ' + element).each(function(){
				
				var item = $j(this);
				var divStyle = 	'width: ' + divWidth + ';' +
								'height: ' + divHeight + ';' +
								'border: 1px solid green;' +
								'float: left;' +
								'overflow: hidden';

				$j(this)
					.wrap('<div class="scroll-content-item"><a rel="mediagallery" href="' + $j(this).attr('src') + '" />') 
					.css('height', elementHeight);

				
			});		
			
			var scrollContentItemWidth = 0;
			
			$j('.scroll-content-item').each(function(){
				
				var item = $(this);
				scrollContentItemWidth += ($j(this).width()); //add margin here
			
			});
			
			$j('.scroll-content').css('width', scrollContentItemWidth);
			
			
			
						
		}
			
		$j(function() {
		//scrollpane parts
		var scrollPane = $('.scroll-pane');
		var scrollContent = $('.scroll-content');
		
		//build slider
		
		var scrollbar = $j(".scroll-bar").slider({
		
		slide:function(e, ui){
				if( scrollContent.width() > scrollPane.width() ){ scrollContent.css('margin-left', Math.round( ui.value / 100 * ( scrollPane.width() - scrollContent.width() )) + 'px'); }
				else { scrollContent.css('margin-left', 0); }
			}
				
		});
		
		//append icon to handle
		var handleHelper = scrollbar.find('.ui-slider-handle')
		.mousedown(function(){
			//scrollbar.width( handleHelper.width() );
		})
		.mouseup(function(){
			//scrollbar.width( '50%' );
		})
		.append('<span class="ui-icon ui-icon-grip-dotted-vertical"></span>')
		.wrap('<div class="ui-handle-helper-parent"></div>').parent();
		
		//change overflow to hidden now that slider handles the scrolling
		scrollPane.css('overflow','hidden');
		
		//size scrollbar and handle proportionally to scroll distance
		function sizeScrollbar(){
			var remainder = scrollContent.width() - scrollPane.width();
			var proportion = remainder / scrollContent.width();
			var handleSize = scrollPane.width() - (proportion * scrollPane.width());
			
		}
		
		//reset slider value based on scroll content position
		function resetValue(){
			var remainder = scrollPane.width() - scrollContent.width();
			var leftVal = scrollContent.css('margin-left') == 'auto' ? 0 : parseInt(scrollContent.css('margin-left'));
			var percentage = Math.round(leftVal / remainder * 100);
			scrollbar.slider("value", percentage);
		}
		//if the slider is 100% and window gets larger, reveal content
		function reflowContent(){
				var showing = scrollContent.width() + parseInt( scrollContent.css('margin-left') );
				var gap = scrollPane.width() - showing;
				if(gap > 0){
					scrollContent.css('margin-left', parseInt( scrollContent.css('margin-left') ) + gap);
				}
		}
		
		//change handle position on window resize
		$j(window)
		.resize(function(){
				resetValue();
				sizeScrollbar();
				reflowContent();
		});
		//init scrollbar size
		setTimeout(sizeScrollbar,10);//safari wants a timeout
	});
			
			
			//$("a[rel='mediagallery']").colorbox();
		$j('a[rel="mediagallery"]').lightBox({
				//overlayBgColor: '#FFF',
				//overlayOpacity: 0.6,
				//imageLoading: 'http://example.com/images/loading.gif',
				imageBtnClose: 'http://www.wijiti.local/dario/images/lightbox-btn-close.gif'
				//imageBtnPrev: 'http://example.com/images/prev.gif',
				//imageBtnNext: 'http://example.com/images/next.gif',
				//containerResizeSpeed: 350,
				//txtImage: 'Imagem',
				//txtOf: 'de'
		});
		
	
		
		$j('#dario-media-gallery div').stop().hover(
			function(){
		
				$j(this).siblings().queue("fx", []).fadeTo( 300, 0.8, function(){
	
				});

			
			},
			
			function(){
			
				$j('#dario-media-gallery div').fadeTo( 300, 1);
			
			});
			
			
			
			if($j('#mycurl-wrapper').length){
				
				$j('#cboxOverlay').css('background', '#000');
			}
		
		
		//$('.scroll-pane').siblings('.scroll-bar-wrap').hide();
		
		$j('#lightbox-secNav-btnClose img')
			.hide();
		
// ***************************************************** tabs *************/
	
	
		$j('#tabs').tabs();


// ***************************************************** colorbox *************/
		$('#map-modal').lightBox();

		
		
		if($j('.checkout_link').length && !($j('.continue_link').length))
		{
			$j('.checkout_link').before('<a hfef="#" class="continue_link four" onClick="history.go(-1)">Continue Shopping</a>');

		}
			
		
		// in ur salon 
		
		$j('.in-ur-salon').closest('body').addClass('in-ur-salon');


// Dario Cycle ------------------------------------------------------------*/		
	
	
	$('.dario-slideshow').cycle({
		fx: 'fade', 
		timeout: 3000
	});

	
// Pop up intro ------------------------------------------------------------*/		



if ( $("p:contains('Emails have been sent')").exists() ) {
	
	//alert('display none');
	
	$('.shop_info').hide();
}























/*	
if ( $('.dci-dstory').length || $('.dci-institute').length || ($('.dci-online').length && $('.addtocart_button').length)  )        {
		$j('#content-container')
			.append('<div class="white-background"></div>')
			.find('.white-background')
			.css({
				'background' : '#fff',
				'display' : 'none'
			});

                                $j('.white-background')
                                        .css({
                                                'z-index' : 2,
                                                'display' : 'block',
                                                'opacity' : 0.5
                                        });


                                $j('.promo-pop-up-wrapper')
                                        .css({
                                                'display': 'block',
                                                'z-index' : 5
                });
	
	$('.promo-pop-up-wrapper')
	.css('display', 'block')
	.find('.promo-pop-up')
	.append('<a class="promo-pop-up-close" href="#"></a>')
	.find('.promo-pop-up-close')
	.click(function(){
		$(this)
			.closest('.promo-pop-up-wrapper')
			.css('display', 'none');
		$j(".white-background").css("display", "none");
		return false;
	});
	
}
*/
});
	

