/// <reference path="jquery-1.4.1-vsdoc.js" />

var Valtech = {};

Valtech.base = function() {
    return {
        init:
            function() {
                $(".scrollable").scrollable().navigator();            
                /*Track email links*/
                $('a.mailTo').click(function() {
                    var trackEmailAdress = $(this).attr('href').split('mailto:')[1];
                    Valtech.base.trackEmailGoal(trackEmailAdress.split('@')[0]);
                });

                $('.closeIeInfo').click(function() {
                    $('#ie6InfoSection').hide();
                    return false;
                });
                $('img').not('.background').lazyload();
            },
        trackEmailGoal:
            function(emailAddress) {
                _gaq.push(function() {
                    var pageTracker = _gat._getTracker("UA-9648009-1");
                    pageTracker._trackPageview('/cgoal/email/' + emailAddress + '/');
                });
                return true;
            }

    };
} ();
$(document).ready(Valtech.base.init);

Valtech.valtechDays = function() {
    return {
        init:
            function() {
                $('.valtechDaysForm .inputField').append('<span class="roundTopLeft"></span><span class="roundTopRight"></span><span class="roundBottomLeft"></span><span class="roundBottomRight"></span>');
                Valtech.valtechDays.validationError();
                $('.error input').focusout(function() {
                    if ($(this).val() !== '') {
                        $(this).parent('.error').removeClass('error');
                    }
                });
                $('.factsLink').click(function() {
                    $('li.active').removeClass('active');
                    $(this).parent('li').addClass('active');

                    $('.factsBox').show();
                    $('.agendaBox').hide();
                    $('.speakersBox').hide();
                    $('.signupBox').hide();
                    Valtech.valtechDays.updateIE8();
                    return false;
                });
                $('.agendaLink').click(function() {
                    $('li.active').removeClass('active');
                    $(this).parent('li').addClass('active');
                    //$('.affar').addClass('active');

                    $('.factsBox').hide();
                    $('.agendaBox').show();
                    $('.speakersBox').hide();
                    $('.signupBox').hide();
                    Valtech.valtechDays.updateIE8();
                    return false;
                });
                $('.signupLink').click(function() {
                    $('li.active').removeClass('active');
                    $(this).parent('li').addClass('active');
                    //$('.affar').addClass('active');

                    $('.factsBox').hide();
                    $('.agendaBox').hide();
                    $('.speakersBox').hide();
                    $('.signupBox').show();
                    Valtech.valtechDays.updateIE8();
                    return false;
                });
                $('.speakersLink').click(function() {
                    $('li.active').removeClass('active');
                    $(this).parent('li').addClass('active');

                    $('.factsBox').hide();
                    $('.agendaBox').hide();
                    $('.speakersBox').show();
                    $('.signupBox').hide();
                    Valtech.valtechDays.updateIE8();
                    return false;
                });

//                $('.speakersBox li').toggle(function() {
//                    $(this).find('.speakerMainBody').show();
//                    Valtech.valtechDays.updateIE8();
//                }, function() {
//                    $(this).find('.speakerMainBody').hide();
//                    Valtech.valtechDays.updateIE8();
//                });

                $('.affar').click(function() {
                    $(this).parents('ul').find('.active').removeClass('active');
                    $(this).addClass('active');
                    $('#affar').show();
                    $('#teknik').hide();
                    Valtech.valtechDays.updateIE8();
                    return false;
                });
                $('.teknik').click(function() {
                    $(this).parents('ul').find('.active').removeClass('active');
                    $(this).addClass('active');
                    $('#teknik').show();
                    $('#affar').hide();
                    Valtech.valtechDays.updateIE8();
                    return false;
                });

            },
        updateIE8:
            function() {
                if (jQuery.browser.version.substring(0, 2) == "8.") {
                    $('.boxContent').hide();
                    $('.boxContent').show();
                }
            },
        validationError:
            function() {
                $('.xformvalidator').parent('.inputField').addClass('error');
                $('.inputField .xformvalidator').hide();
            }
    };
} ();
$(document).ready(Valtech.valtechDays.init);

Valtech.calendar = function() {
    return {
        init:
            function() {
                $('a.calendar').click(Valtech.calendar.showCalendar);
                $('a.news').click(Valtech.calendar.showNews);
                $('a.valtechlabs').click(Valtech.calendar.showValtechLabs);
            },
        showCalendar:
                function() {
                    $('div.calendar').css('z-index', '5');
                    $('div.news').css('z-index', '4');
                    $('div.valtechlabs').css('z-index', '3');
                    $('a.calendar').css('color', '#5b5b5b');
                    $('a.news').css('color', '#18b0ff');
                    $('a.valtechlabs').css('color', '#18b0ff');
                    $('.calendarContentWrapper').css('display', 'block');
                    $('.newsContentWrapper').css('display', 'none');
                    $('.valtechLabsContentWrapper').css('display', 'none');
                    return false; 
                },
        showNews:
                function() {
                    $('div.calendar').css('z-index', '4');
                    $('div.news').css('z-index', '5');
                    $('div.valtechlabs').css('z-index', '3');
                    $('a.calendar').css('color', '#18b0ff');
                    $('a.news').css('color', '#5b5b5b');
                    $('a.valtechlabs').css('color', '#18b0ff');
                    $('.calendarContentWrapper').css('display', 'none');
                    $('.newsContentWrapper').css('display', 'block');
                    $('.valtechLabsContentWrapper').css('display', 'none');
                    return false;
                },
        showValtechLabs:
                function() {
                    $('div.calendar').css('z-index', '3');
                    $('div.news').css('z-index', '4');
                    $('div.valtechlabs').css('z-index', '5');
                    $('a.calendar').css('color', '#18b0ff');
                    $('a.news').css('color', '#18b0ff');
                    $('a.valtechlabs').css('color', '#5b5b5b');
                    $('.calendarContentWrapper').css('display', 'none');
                    $('.newsContentWrapper').css('display', 'none');
                    $('.valtechLabsContentWrapper').css('display', 'block');
                    return false;
                },
        eventExpandHandler:
                function() {
                    $('.calendarItem').hoverIntent({
                        sensitivity: 2,
                        interval: 200,
                        over: Valtech.calendar.expandEvents,
                        timeout: 0,
                        out: Valtech.calendar.colapseEvents
                    });
                },
        newsExpandHandler:
                function() {
                    $('.newsItem').hoverIntent({
                        sensitivity: 2,
                        interval: 200,
                        over: Valtech.calendar.expandNews,
                        timeout: 0,
                        out: Valtech.calendar.colapseNews
                    });
                },

        valtechLabsExpandHandler:
                function() {
                    $('.valtechLabsItem').hoverIntent({
                        sensitivity: 2,
                        interval: 200,
                        over: Valtech.calendar.expandValtechLabs,
                        timeout: 0,
                        out: Valtech.calendar.colapseValtechLabs
                    });
                },        
        colapseEvents:
                function() {
                    $('.calendarItem').animate({ "height": "35px" }, "fast", function() {
                        $('.calendarItem .newsFade').css('display', 'block');
                    });
                    $('.calendarItem').not(this).find('.month').css({ 'background-image': 'url(../Templates/Css/Images/calendarGreenMonth.png)',
                        'color': '#ffffff',
                        'padding': '8px 4px'
                    });
                    $(this).find('a').css('color', '#ffffff');
                    $('.calendarItem').not(this).find('a').css("display", "inline-block");
                },
        expandEvents:
                function() {
                    $('.calendarItem').not(this).find('a').css('display', 'none');
                    $('.calendarItem').not(this).find('.month').css({ 'background-image': 'none',
                        'color': '#89c305',
                        'padding': '0px 4px'
                    });
                    $('.calendarItem .newsFade').css('display', 'none');
                    $('.calendarItem').not(this).animate({ "height": "20px" }, "fast", function() { });
                    $(this).find('a').css('color', '#18B0FF');
                    $(this).animate({ "height": "65px" }, "fast");
                },
        colapseNews:
                function() {
                    $('.newsItem').animate({ "height": "35px" }, "fast", function() {
                        $('.newsItem .newsFade').css('display', 'block');
                    });
                    $(this).find('a').css('color', '#ffffff');
                    $('.newsItem').not(this).find('a').css("display", "inline-block");
                },
        expandNews:
                function() {
                    $('.newsItem').not(this).find('a').css("display", "none");
                    $('.newsItem').not(this).animate({ "height": "20px" }, "fast", function() { });
                    $('.newsItem .newsFade').css('display', 'none');
                    $(this).find('a').css('color', '#18B0FF');
                    $(this).animate({ "height": "65px" }, "fast");
                },
        colapseValtechLabs:
                function() {
                    $('.valtechLabsItem').animate({ "height": "35px" }, "fast", function() {
                    $('.valtechLabsItem .newsFade').css('display', 'block');
                    });
                    $(this).find('a').css('color', '#ffffff');
                    $('.valtechLabsItem').not(this).find('a').css("display", "inline-block");
                },
        expandValtechLabs:
                function() {
                    $('.valtechLabsItem').not(this).find('a').css("display", "none");
                    $('.valtechLabsItem').not(this).animate({ "height": "20px" }, "fast", function() { });
                    $('.valtechLabsItem .newsFade').css('display', 'none');
                    $(this).find('a').css('color', '#18B0FF');
                    $(this).animate({ "height": "65px" }, "fast");
                }
    };
} ();
$(document).ready(Valtech.calendar.init);

$(function() {
    $('a[rel*=external]').click(function() {
        window.open(this.href);
        return false;
    });
});
