/* CREDITS
 * ----------------------------------------------------------
 * Title:		Belisol - Main JavaScript file
 * Author:		Wim Hendrikx <wim@inventis.be>
 * Date:		29/11/2010
 * ----------------------------------------------------------
 * Inventis - Web Architects - We design the Web!
 * www.inventis.be
*/

$(document).ready(function(){
    $('#slider1').tinycarousel({interval:true, intervaltime: 4000});
    $('#slider2').tinycarousel({interval:true, intervaltime: 4000});
    $('#slider3').tinycarousel({interval:true, intervaltime: 4000});
    $('#showcase').tinycarousel({intervaltime: 4000});

    $('#language').click(function(){
        if(!$(this).next().hasClass('active')){
            $(this).next().addClass('active');
        }else{
            $(this).next().removeClass('active');
        }
        return false;
    });

    $(document.body).click(function(){
        $('#language').next().removeClass('active');
    });

    if($.browser.msie && $.browser.version < 8){
        if($('.pagination')){
            var totalWidth = 0;
            var margin = 5;
            $('.pagination li').each(function(){
                totalWidth += margin + $(this).width();
            });

            totalWidth  = totalWidth / $('.pagination').size();
            totalWidth += 8; // Extra width for active item

            var containerWidth = 680;
            var marginLeft = (containerWidth / 2) - (totalWidth / 2);
           
            $('.pagination').css('marginLeft', marginLeft + 'px');
        }
    }

    if($('.no-csstransforms .extra_blocks .photogallery img')){
        $('.no-csstransforms .extra_blocks .photogallery img').transform({rotate: '-3deg'});
    }

    $('.properties .heading2').each(function(){
        $(this).click(function(){
            $(this).next().slideToggle();
        });
    });

    $('.color_panel img').addpowerzoom({
        magnifiersize: [89, 66]
    });

    $("a[rel=imgset]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
        'centerOnScroll'    : true,
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Foto ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});

	if(typeof(fancyMessage) != 'undefined'){
		$.fancybox(
			'<div class="fancyMessage">'+fancyMessage+'<a class="button" href="#" onclick="$.fancybox.close();">Ok</a></div>',
			{
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'padding'		: 1,
				'centerOnScroll': true
			}
		);
	}
	
	// DOORCAROUSEL
    var dc  = $('#doors_carousel');
    dc.tinycarousel({display: 4, animation: true, duration: 1500, callback: function(element, iteration){
	    if(iteration >= 1){
		    var doors = $('.hiddenDoor');
		    doors.each(function(i, el){
			   if(i < 4){
				   var $el  = $(el);
				   var src  = $el.attr('alt');
				   $el.attr('src', src);
				   $el.attr('alt', '');
				   $(el).removeClass('hiddenDoor');
			   }
		    });
	    }
    }});

    $('#doors_carousel img').hover(
        function(){
            var el = $(this).parent().parent();
            el.animate({paddingTop: '20px', height: '270px', backgroundPosition: '10px 260px'},100);
        },
        function(){
            var el = $(this).parent().parent();
            el.animate({paddingTop: '0px', height: '290px', backgroundPosition: '10px 240px'},100);
        }
    );
        
    $('#doors_detail a.carousel').fancybox({
        'transitionIn'		: 'elastic',
        'transitionOut'		: 'elastic'
    });

});

$('select').not('.ie7 select').customStyle();
