$(document).ready(function(){
    //png transparency fix for IE6:
    var toPngFix = $('.pngfix, .nav-natalia li img, .natalia-page h1');
    if(toPngFix.length)
        toPngFix.pngFix();
        
    //fancy box:
    if($('.home-video').length )
        $('.home-video a').fancybox({
            'padding': 0
        });
    if($('.lightbox-image').length )
 	$("a.lightbox-image").fancybox({
	    'titleShow'     : 'inside',
            'type': 'image',
		'transitionIn'	: 'none',
		'transitionOut'	: 'none'
	});

    if($('.youtube').length ) {
        $('.youtube').each(function() {
                $(this).fancybox({
                'padding'		: 0,
                'autoScale'		: false,
                'transitionIn'	: 'none',
                'transitionOut'	: 'none',
                'title'			: this.title,
                'width'		    : 680,
                'height'		: 495,
                'href'			: $(this).attr('href').replace(new RegExp("watch\\?v=", "i"), 'v/'),
                'type'			: 'swf',
                'swf'			: {
                        'wmode'                 : 'transparent',
                        'allowfullscreen'       : 'true'
                }
                });
        });
    }
    
    if($('.shops-link').length)
	// $('.shops-link').fancybox({
	//     'padding': 0,
	//     'type': 'iframe',
	//     'width': 887,
	//     'height': 590
	// });                             
	$('.shops-link').click(function() {                       

		window.open($(this).attr('href'),"popup",
		               "width=890,height=585,left=30,top=20");
		return false;
	}); 
    /*if($('#modal-link').length )
        $('#modal-link').fancybox({
            'padding': 0
        });    */    
                 
    //rollover effect:
    imgHover();

});

$(window).load(function() {
    if($('.news-page').length || $('.contact-page').length) {
        $('.side-col, .main-col').height(Math.max($('.side-col').height(), $('.main-col').height()));
    }
});



function imgHover() {

    var buttons = $('.nav-natalia img');

    for(var i=0, images=[]; i<buttons.length; i++) {
        var newSrc = $(buttons[i]).attr('data-rollover');

        var j;
        var check = false;
        for(j=0; j<images.length; j++) {
            if(images[j].src == newSrc) {
                check = true;
                break;
            }
        }

        if(!check) {
            images.push(new Image());
            images[images.length-1].src = newSrc;
        }
    }

    var test = "";
    for(var i=0; i<images.length; i++) {
        images[i].onload = function() {
            for(j=0; j<buttons.length; j++) {
                if(!buttons.eq(j).parents('.current').length) {
                    if($(buttons[j]).attr('src') == $(buttons[j]).attr('data-original')) {
                        $(buttons[j]).mouseover(function(){
                            if($(this).attr('src') != $(this).attr('data-rollover'))
                                $(this).attr('src', $(this).attr('data-rollover'));
                        });
                        $(buttons[j]).mouseout(function(){
                            $(this).attr('src', $(this).attr('data-original'));
                        });
                    }
                }
            }
        }
        if(navigator.appName == "Microsoft Internet Explorer")
            images[i].src = images[i].src;            
    }
    
    $('.nav-natalia li.current img').each(function() {
        $(this).attr('src', $(this).attr('data-rollover'));
    });
}

