$(document).ready(function(){

	// Valori default pe input-uri
	try {
		$('INPUT[type=text], INPUT[type=password]')
			.focus(function(){
				var $this = $(this);
				if ( $this.attr('value') == $this.attr('title') ) {
					$this.attr('value', '');
					$this.removeClass('default-value');
				}
			})
			.blur(function(){
				var $this = $(this);
				if ( $this.attr('value') == '' || $this.attr('value') == $this.attr('title') ) {
					$this.attr('value', $this.attr('title'));
					$this.addClass('default-value');
				}
			})
			.blur();
	} catch(err) {
		
	}

	// Slider
	try {
		$('.slider').each(function(){
			var $this	= $(this);
			var $slider	= $this.find('.slider-content UL');
			var $slides	= $slider.find('LI');
			
			var sWidth = 716 * $slides.length;
			
			$slider.css({ 'width' : sWidth + 'px' });
			
			$this.find('.prev').click(function(e){
				e.preventDefault();
				
				var mLeft = $slider.css('margin-left').replace('px', '');
				mLeft = Math.ceil(mLeft / 716) * 716;
				
				if ( mLeft < 0 ) {
					$slider.stop().animate({ marginLeft : mLeft + 716 + 'px' }, 400);
				}
			});
			
			$this.find('.next').click(function(e){
				e.preventDefault();
				
				var mLeft = $slider.css('margin-left').replace('px', '');
				mLeft = Math.floor(mLeft / 716) * 716;
				
				if ( mLeft > (sWidth - 716) * -1 ) {
					$slider.stop().animate({ marginLeft : mLeft - 716 + 'px' }, 400);
				}
			});
		});
	} catch(err) {
		
	}
	
	// Detail tabs
	try{
		$('.tabs').each(function(){
			var $this = $(this);
			var $parent = $this.parent();
			
			// add onClick event
			$this.find('A').click(function(e){
				e.preventDefault();
				
				var $A = $(this);
				var active = '#' + $A.attr('href').replace('#', '');
				
				$A.parent().addClass('selected')
					.siblings().removeClass('selected');
				
				$parent.find('.tab-content').css('display', 'none');
				$(active).css('display', 'block');
			});
			
			// set default if none selected
			var sel = $this.find('.selected');
			
			if ( !sel.length ) {
				sel = $this.find('LI:first').addClass('selected');
			}
			
			// activate tab & content
			sel.find('A').click();
		});
	} catch(err) {
		
	}
	
	// shopping cart - aceeasi adresa
	try{
		$('#same').change(changeAddr).click(changeAddr);
		function changeAddr(){
			if ( $('#same').attr('checked') ) {
				$('#adresa_livrare LI').css({ 'display' : 'none' });
			} else {
				$('#adresa_livrare LI').css({ 'display' : 'block' });
			}
		}
	} catch(err) {
		
	}
	
	// shopping cart - detalii firma
	try {
		$('INPUT[name="b_flag_firm"]').change(changePers).click(changePers);
		function changePers (){
			var selectedValue = $('INPUT[name="b_flag_firm"]:checked').val();
			
			if ( selectedValue == 1 ) {
				$('.detalii-firma').css({ 'display' : 'block' });
			} else {
				$('.detalii-firma').css({ 'display' : 'none' });
			}
		}
	} catch(err) {
		
	}
	
	
	// adauga colturi rotunjite in Opera
	try{
		if ($.browser.opera ) {
			$('.cart-section').addClass('opera-rounded');
		}
	} catch(err) {
		
	}
})