	$(document).ready(function() { 
							   
		$('.tabs .tab-active').show(); // show default content
		$('.tabs .header ul a').click(function(){
			$('.tabs .header ul li').removeClass('active');
			$(this).parent().addClass('active'); // make clicked tab active
			$('.tabs .tab').hide(); // hide all content
			$('.tabs').find('#' + $(this).attr('rel')).show(); // and show content related to clicked tab
			return false;
		});
		
		$("#convertinput").keyup(function () {
			updateConvert();
		});
		
		$("#convertinput").change(function () {
			updateConvert();
		});
		
		$("#converttype").change(function () {
			updateConvert();
		});
		
		$("a.lightview").fancybox({'overlayShow': true, overlayOpacity:0.9,frameWidth:550,frameHeight:300,hideOnContentClick:false});
		$("a.lightview2").fancybox({'overlayShow': true, overlayOpacity:0.9,frameWidth:810,frameHeight:400 });
		$("a.lightview3").fancybox({'overlayShow': true, overlayOpacity:0.9,frameWidth:350,frameHeight:250 });
		
		$("a").focus(function () {
        	$(this).blur();
		});
		$("img.rollover").hover(function () {
			newsrc=$(this).attr('src').replace('.jpg','-over.jpg').replace('.png','-over.png');
        	$(this).attr('src',newsrc);
		},function () {
			newsrc=$(this).attr('src').replace('-over.jpg','.jpg').replace('-over.png','.png');
        	$(this).attr('src',newsrc);
		});
		
	
		var config = {
				toolbar:
					[
						['Format','TextColor','Bold','Italic','Underline','Strike'],
						['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
						['Link','Unlink'],['Maximize'],
						['NumberedList','BulletedList','Outdent','Indent'],
						['Undo','Redo','-','RemoveFormat'],
						['Cut','Copy','Paste','PasteText','PasteFromWord'],
					    ['Table','HorizontalRule','SpecialChar']
					],
				uiColor: '#dddddd'
				};
		$('.wysiwyg').each(function(index) {
			config.width=$(this).css('width');
			config.height=$(this).css('height');
			$(this).ckeditor(config);
		});
		
		
	});
	
	function clickSub(thediv,div,image){
        $.each($('.'+div),function(){
            if(this.id==thediv){
                if(this.style.display=='none')
                {
                    $('#'+this.id).slideDown(700);
                    $('#'+image).show(700);
                    $('#'+'plus-'+this.id).hide(700)
                }
                else
                {
                    $('#'+this.id).slideUp(700);
                    $('#'+image).show(700);
                    $('#'+'minus-'+this.id).hide(700)
                }
            }else
            {
                $('#'+this.id).slideUp(700);
                $('#'+'minus-'+this.id).hide(700);
                $('#'+'plus-'+this.id).show(700);
            }

        });
	}
	
	
	
function sendEmailContactUs()  {
	$('.submit').val('Sending...');
	$('.submit').attr("disabled","true");
	$.post('form-contactus.php?r='+Math.random(),{			
		visitor_name: $('#visitor_name').val(),			
		visitor_email: $('#visitor_email').val(),
		visitor_telephone: $('#visitor_telephone').val(),				
		visitor_message: $('#visitor_message').val()		
		},
		function (data) {
			$('#sendStatus').html("<br /><p>Your message has been sent, we will reply as soon as possible.<br /><br />Thank you,<br />David Interiors Ltd.</p>");
			$('.submit').val('Send Message');
			$('.submit').attr("disabled",false);
			$('#contactUsForm').html("");
		}
	);
	return false;
}
	
	
	function adslideSwitch() {
	    var $active = $('#adslideshow IMG.adactive');

	    if ( $active.length == 0 ) $active = $('#adslideshow IMG:last');

	    var $next =  $active.next().length ? $active.next()
	        : $('#adslideshow IMG:first');

	    $active.addClass('last-active');

	    $next.css({opacity: 0.0})
	        .addClass('adactive')
	        .animate({opacity: 1.0}, 1000, function() {
	            $active.removeClass('adactive last-active');
	        });
	}
	
	function slideSwitch() {
	    var $active = $('#slideshow IMG.active');

	    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

	    var $next =  $active.next().length ? $active.next()
	        : $('#slideshow IMG:first');

	    $active.addClass('last-active');

	    $next.css({opacity: 0.0})
	        .addClass('active')
	        .animate({opacity: 1.0}, 1000, function() {
	            $active.removeClass('active last-active');
	        });
	}

	$(function() {
	    setInterval( "slideSwitch()", 5000 );
	    setInterval( "adslideSwitch()", 8000 );
	});
	
	function addtocart(productid) {
		$.post('cart/add.htm?r='+Math.random(),{
			productid: productid,
			quantity: '1'
			},
			function (data) {
				refreshcartinfo(data);
			},
			'json'
		);
	}
	
	
	function updateConvert(){
		newval=parseFloat($("#convertinput").val())*parseFloat($("#converttype").val());
		$("#convertoutput").val(newval.toFixed(2));
	}
	
	
	function buildlink(lang,itemid,varname,modulename,varid,varprice)
	{
	
		window.location="http://109.203.96.226/~davidint/en/carpetsandrugs/webshop/cart/add/"+itemid+"/"+varid+"/"+1+"/"+modulename+".htm";
	};
	
	function buildlink2(itemid,lang,variant,modulename)
	{
		var qty=$('#qty').val();
		window.location='/'+lang+"home/webshop/cart/add/"+itemid+"/"+variant+"/"+qty+"/"+modulename+".htm";
	
	};
	
	
	function sendEmail() {
		$('.submit').val('Sending...');
		$('.submit').attr("disabled","true");
		$.post('form-contactus.php?r='+Math.random(),{			
			visitor_name: $('#clientname').val(),			
			visitor_email: $('#clientemail').val(),
			visitor_tel: $('#clienttelephone').val()			
			},
			function (data) {
				$('#sendStatus').html("<br /><p>Your quote has been sent, we will reply as soon as possible.<br /><br />Thank you<br />");
				$('.submit').val('Send Message');
				$('.submit').attr("disabled",false);
				$('#contactUsForm').html("");
			}
		);
		return false;
	}
	
	function buildlink3(itemid,lang,modulename)
	{
		var size= $('#size-variant').val();
		var qty=$('#qty').val();
		window.location='/'+lang+"home/webshop/cart/add/"+itemid+"/"+size+"/"+qty+"/"+modulename+".htm";
	};
	
	function slideSwitch() {
	    var $active = $('#slideshow IMG.active');

	    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

	    var $next =  $active.next().length ? $active.next()
	        : $('#slideshow IMG:first');

	    $active.addClass('last-active');

	    $next.css({opacity: 0.0})
	        .addClass('active')
	        .animate({opacity: 1.0}, 1000, function() {
	            $active.removeClass('active last-active');
	        });
	}
	
	
