$(document).ready(function(){
    if ($('#megamenu').length)
    {
        $('#megamenu').dcMegaMenu({
            rowItems: '4',
            speed: 'fast',
            effect: 'fade'
        });
    }

    if ($('.dialog').length)
    {
        $('.dialog').dialog({
            modal: true,
            autoOpen: false
        });
    }

    $('#menu ul#topnav li').last().css('margin-right','0');

    $('#billboard-content span.close').click(function(){
        $(this).parents('#billboardad').hide();
    });

    $('#header').show();

    $('.awicon.icon-openklappen').click(function(){
        $(this).parents('.portlet').find('.portlet-content').slideToggle();
        $(this).toggleClass('icon-dichtklappen');
    });

    $.fn.colorbox.settings.opacity = 0.7;

    var windowHeight = $(window).height();
    var windowWidth = $(window).width(); 
    $("a[rel='zoom']").colorbox({
    	maxWidth:windowWidth,maxHeight:windowHeight,scalePhotos:true,
        onClosed:function(){
            $("div.commercial").css({
                'visibility' : 'visible'
            })
        }, 
        onOpen:function(){
            $("div.commercial").css({
                'visibility' : 'hidden'
            });
        }
    } );
    $(".openGallery").click(function(){
        $("a[rel='zoom']:first").click();
        $('div.commercial').css('visibility','hidden');
        return false;
    });
    $("a[rel='zoom1']").colorbox({
        onClosed:function(){
            $("div.commercial").css({
                'visibility' : 'visible'
            })
        }, 
        onOpen:function(){
            $("div.commercial").css({
                'visibility' : 'hidden'
            });
        }
    } );
    $(".openGallery1").click(function(){
        $("a[rel='zoom1']:first").click();
        $('div.commercial').css('visibility','hidden');
        return false;
    });

    $("#idFilterBlock_1 .openGallery1").colorbox();

    $(".loginbox").colorbox({
        width:"876px",
        height:"604px",
        iframe:true,
        href:"/myautoweek/login.php?cache=no",
        onClosed:function(){
            $("div.commercial").css({
                'visibility' : 'visible'
            });
            $('#idAwVideoPlayer').css({
                'visibility':'visible'
            });
        }
    });
    $(".loginbox").click(function(){
        $('div.commercial').css('visibility','hidden');
        $('#idAwVideoPlayer').css('visibility','hidden');
    });

    $(".registerbox").colorbox({
        width:"876px", 
        height:"604px", 
        iframe:true, 
        onClosed:function(){
            $("div.commercial").css({
                'visibility' : 'visible'
            });
            $('#idAwVideoPlayer').css({
                'visibility':'visible'
            });
        }
    });
    $(".registerbox").click(function(){
        $('div.commercial').css('visibility','hidden');
        $('#idAwVideoPlayer').css('visibility','hidden');
    });

    $(".carbasebox").colorbox({
        width:"600px", 
        height:"442px", 
        iframe:true, 
        onClosed:function(){
            $("div.commercial").css({
                'visibility' : 'visible'
            });
        }
    });
    $(".carbasebox").click(function(){
        $('div.commercial').css('visibility','hidden');
    });

    $(".commentreportbox").colorbox({
        width:"628px", 
        height:"524px", 
        iframe:true
    });

    $(".vm_helpbox").colorbox({
        width:"670px", 
        height:"540px", 
        iframe:true, 
        href:"/myautoweek/vm_help.php", 
        onClosed:function(){
            $("div.commercial").css({
                'visibility' : 'visible'
            });
        }
    });
    $(".vm_helpbox").click(function(){
        $('div.commercial').css('visibility','hidden');
    });

    $(".vm_feedbackbox").colorbox({
        width:"710px", 
        height:"464px", 
        iframe:true, 
        href:"/myautoweek/vm_feedback.php", 
        onClosed:function(){
            $("div.commercial").css({
                'visibility' : 'visible'
            });
        }
    });
    $(".vm_feedbackbox").click(function(){
        $('div.commercial').css('visibility','hidden');
    });

    $('a[rel=external]').attr('target','_blank');

    $("table.oddeven tr:odd").addClass('odd');
    $("table.oddeven tr:even").addClass('even');

    $(".collapsable .header").parent().find('tr:gt(1)').toggle();
    $(".collapsable .header").click(function() {
        $(this).parent().find('tr:gt(1)').toggle();
    });

    if ($('input.starobliged').length){
        $('input.starobliged').rating({
            required:true,
            callback:function(value, link)
            {
                var span = $('#idRatingTip_' + this.name);
                if (span)
                {
                    span[0].original = this.title;
                    span.html(this.title);
                }
            },
            focus:function(value, link)
            {
                var span = $('#idRatingTip_' + this.name);
                if (span)
                {
                    span[0].original = span[0].original || span.html();
                    span.html(this.title);
                }
            },
            blur:function(value, link)
            {
                var span = $('#idRatingTip_' + this.name);
                if (span)
                    span.html(span[0].original);
            }
        });
    }

	$('.trigger .magtrigger').click(function(){
		window.open('http://abonnement.autoweek.nl#origin=titelsite-autoweek&linktype=click-navigatielink-rechts-buttonbovenaan', '_blank');
//		window.open('http://abonnement.autoweek.nl?utm_medium=titelsite&utm_source=autoweek&utm_campaign=homepage&utm_content=button_bovenaan', '_blank');
//		window.open('http://abonnement.autoweek.nl/?utm_source=AutoWeek%2Bhompage%2Baboknop&utm_medium=autoweek%2Baboknop&utm_campaign=autoweek%2Baboknop', '_blank');
		return false;
	});
});

