	//Custom Select

		($(function(){			
			
			$('select#langselect').selectmenu();
            $('select#cselect').selectmenu();
			$('select#contactselect').selectmenu();
				
		}));		
		
		//a custom format option callback
		var addressFormatting = function(text){
			var newText = text;
			//array of find replaces
			var findreps = [
				{find:/^([^\-]+) \- /g, rep: '<span class="ui-selectmenu-item-header">$1</span>'},
				{find:/([^\|><]+) \| /g, rep: '<span class="ui-selectmenu-item-content">$1</span>'},
				{find:/([^\|><\(\)]+) (\()/g, rep: '<span class="ui-selectmenu-item-content">$1</span>$2'},
				{find:/([^\|><\(\)]+)$/g, rep: '<span class="ui-selectmenu-item-content">$1</span>'},
				{find:/(\([^\|><]+\))$/g, rep: '<span class="ui-selectmenu-item-footer">$1</span>'}
			];
			
			for(var i in findreps){
				newText = newText.replace(findreps[i].find, findreps[i].rep);
			}
			return newText;
		}		
    //Custom select end
    
    //Carousel start
    

/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
		
    });
	
	/*Hover stop*/
    carousel.clip.hover(function() {
                            carousel.stopAuto();
                    }, function() {
                            carousel.startAuto();
                    });


    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

// Ride the carousel...
jQuery(document).ready(function() {
    jQuery("#mycarousel").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null,
		wrap: 'circular',
		size:4,
		auto: 10,
		itemVisibleInCallback: {
			onBeforeAnimation: function(event, i, value) {
				jQuery('.jcarousel-control').find('A').removeClass('selected');
				var list_item = value % event.options.size;
				if (!list_item) list_item = event.options.size; 
				jQuery('.jcarousel-control').find('A').eq(list_item-1).addClass('selected');
			},
			onAfterAnimation: function(event, i, value) {
			}
		}
    });
	
});

// Carousel end

//tabs

$(function() {
	$( "#tabs" ).tabs();
});

$(function() {
	$( "#tabs2" ).tabs();
});

//filter start

function _show_all_areas() {
            // Show area icons
			$('.brands li.area').stop().animate({
				'opacity' : 1, 
				'width' : '160px', 
				'marginRight' : '10px', 
				'marginLeft' : '10px'
			}).removeClass("hideme");

            // Show text versions of the areas
			$('.brands li.area-text').stop().animate({
				'opacity' : 1, 
				'width' : '32%', 
				'marginRight' : '.28em', 
                'marginLeft' : '.28em',
                'height': '100%'
			}).removeClass("hideme");

            // Hide brands
			$('.brands li.brand').stop().animate({
				'opacity' : 0, 
				'width' : 0, 
				'marginRight' : 0, 
				'marginLeft' : 0
			}).addClass("hideme");
			
            // Hide text versions of the brands
			$('.brands li.brand-text').stop().animate({
				'width' : 0,
				'opacity' : 0,
				'marginRight' : 0, 
				'marginLeft' : 0,
				'height' : 0
			}).addClass("hideme");
}

function _show_area_brands(thisItem) {
            // Show the brands of the selected category
			$('.brands li[rel='+thisItem+']').stop().animate({
				'width' : '160px',
				'opacity' : 1,
				'marginRight' : '10px',
				'marginLeft' : '10px'
			}).removeClass("hideme");
			
            // Same, text version
			$('.brands li.brand-text[rel='+thisItem+']').stop().animate({
				'width' : '32%',
				'opacity' : 1,
				'marginRight' : '.28em',
				'marginLeft' : '.28em',
				'height' : '100%'
			}).removeClass("hideme");

            // Hide non-matching
			$('.brands li[rel!='+thisItem+']').stop().animate({
				'width' : 0,
				'opacity' : 0,
				'marginRight' : 0, 
				'marginLeft' : 0
			}).addClass("hideme");
			
            // Same for text version
			$('.brands li.brand-text[rel!='+thisItem+']').stop().animate({
				'width' : 0,
				'opacity' : 0,
				'marginRight' : 0, 
				'marginLeft' : 0,
				'height' : 0
			}).addClass("hideme");

            // Hide area icons
			$('.brands li.area').stop().animate({
				'width' : 0,
				'opacity' : 0,
				'marginRight' : 0, 
				'marginLeft' : 0
			}).addClass("hideme");
            
            // Hide area-text icons
			$('.brands li.area-text').stop().animate({
				'width' : 0,
				'opacity' : 0,
				'marginRight' : 0, 
				'marginLeft' : 0,
                'height' : 0
			}).addClass("hideme");
}

$(document).ready(function() {
	/*
    _show_all_areas();
    $("#cselect").val("kaikkituotekategoriat");
    $('.ui-selectmenu-status').text("Kaikki tuotekategoriat");
    */

    $('#cselect').change(function() {
        var thisItem = $(this).val();
		if (thisItem == "kaikkituotekategoriat") {
            _show_all_areas();
        } else {
            _show_area_brands(thisItem);
		}
	});
	
    // hover effect for the icons, eyecandy
	$('.brands li img').animate({'opacity' : 0.7}).hover(function() {
		$(this).animate({'opacity' : 1});
		}, function() {
			$(this).animate({'opacity' : 0.7});
	});
            
    $('.brands li.area a').bind('click', function(event) {
            event.preventDefault();
            var imgalt = $(this).find("img").attr("alt");
            $('.ui-selectmenu-status').text(imgalt);
            var thisItem = $(this).attr("class");
            _show_area_brands(thisItem);
            $("#cselect").val(thisItem);
            
    });
    
    $('.brands li.area-text a').bind('click', function(event) {
            event.preventDefault();
            var linktext = $(this).text();
            $('.ui-selectmenu-status').text(linktext);
            var thisItem = $(this).attr("class");
            _show_area_brands(thisItem);
            $("#cselect").val(thisItem);
            
    });
});

//filter end

//Validator

$(document).ready(function(){
    $("#a-form").validate();
  });
  
$(document).ready(function(){
    $("#contact-form").validate();
  });

$(document).ready(function(){
    $("#rekry").validate();
  });


//Placeholder
$(document).ready(function(){
$('.inputfield').addPlaceholder();
});
