
$(document).ready(function(){ 	$('#ebookform').validate(); });

function slider() {
    var $active = $('#slider li.active');

    if ( $active.length == 0 ) $active = $('#slider li:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slider li:first');

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

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

    slidernavi();
}

var interval;

function slidernavi() {
    var $active = $('#slidernavi li.active');

    if ( $active.length == 0 ) $active = $('#slidernavi li:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slidernavi li:first');

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

    var href = $('#slidernavi li.active a').attr('href');
    $('.slidermore a').attr('href', href);
}

$(document).ready(function(){

	$('#slider li:first').addClass('active')
	$('#slidernavi li:first').addClass('active')
    interval = setInterval( "slider()", 5000 );
    $('.sliderplay a').click( function() { sliderstop(); return false; });

});



function sliderstop() {

		clearInterval(interval);
		$('.sliderplay a').addClass('stop');
		$('.sliderplay a').click( function() { sliderplay(); return false; });
		return false;
}

function sliderplay() {

		interval = setInterval( "slider()", 5000 );
		$('.sliderplay a').removeClass('stop');
		$('.sliderplay a').click( function() { sliderstop();  return false;});
			return false;
    }







/*
$(document).ready(function(){
	$("#slider").easySlider({
		auto: true,
		continuous: true,
		pause: 5000,
		numeric: true
	});
});
*/
/*
$(document).ready(function(){

	$(".rotating-header").dl();
});

*/


jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel();
});


/*
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 2,
        animation: 'slow',
        scroll: 1,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
*/


$(document).ready(function(){

		$('.ajaximg').each( function( index ) {
			var u = $(this).attr('xsrc');
			$(this).attr('src', u);
		});
});


$(document).ready(function(){

	if ( $('#fotosklep').length ) {

		$('.aborders:first').addClass('borderselected');
		$('.sklepimg:first').addClass('imageselected');
		fotosklepset();
	}

	$('.sklepga').click( function( index ) {
			$('.sklepimg').removeClass('imageselected');
			$(this).find('img:first').addClass('imageselected');
			fotosklepset();
			return false;

		});


	$('.aborders').click( function( index ) {
			$('.aborders').removeClass('borderselected');
			$(this).addClass('borderselected');
			fotosklepset();
			return false;

		});




});


function fotosklepset() {

	var bo = $('.borderselected:first');
	var io = $('.imageselected:first');

	var bw = bo.attr('xb');
	var bc = bo.attr('xbc');
	$('#fotoplotno').css('border', bw+'px solid #'+bc);
	var bg = bo.attr('xbg');
	$('#fotoplotno').css('background-color', '#'+bg);

	var di = $('#fotoplotno img');
	var id = io.attr('xid');
	var iw = bo.attr('xiw');
	var ih = bo.attr('xih');


	di.attr('src', '/cms/frontend/image.php?id='+id+'&height='+ih+'&width='+iw+'&bg='+bg);
	di.attr('width', iw);
	di.attr('height', ih);

	var pt = bo.attr('xpt');
	var pl = bo.attr('xpl');
	di.css('margin', pt+'px '+pl+'px');

	var rl = bo.attr('xrl');
	var dp = $('#fotoplotno');
	dp.css('margin-left', rl+'px');
	var w = bo.attr('xw');
	dp.css('width', w+'px');
	$('#formimage').val(''+id);
	$('#formframe').val(bo.attr('xid'));
}



