﻿Cufon.replace('h1, h2, #menu, .panelCover, .contentHeader p', { hover: true });

// ipad/iphone redirect
var ua = navigator.userAgent;
if (/iPad/i.test(ua) || /iPhone/i.test(ua)){
    var path = self.location.pathname;
    path = path.substr(path.lastIndexOf('/') + 1).toLowerCase()
    path = '#' + ((path != '' && path !='default.aspx') ? path.substring(0, path.lastIndexOf('.')) : 'home');
    self.location.replace('/ipad.aspx' + path);
}

$(function () {
    var isIE = $.browser.msie;

    if ($('#Home').length || $('#Contact').length) {
        $(window).resize(function () {
            var el = (!$('#Home').length) ? $('#cContact') : $('#cHome');
            el.css('marginLeft', ($(window).width() <= 980) ? parseInt(-$(window).width() / 2) : '-480') + 'px';
        });
        $(window).trigger('resize');
    }



    var selected = $('#menu').find('.selected:last');
    var firstSelected = $('#menu').find('.selected:first');
    $('#back').click(function () {
        var nextList = selected.parent().prev().find('ul');
        if (nextList.length) {
            nextLocation = nextList.find('a:last');
        } else {
            var nextLocation = selected.parent().prev().find('a');
            if (!nextLocation.length) {
                nextLocation = firstSelected.parent().prev().find('a');
            }
        }
        self.location.href = nextLocation.attr('href');
        return false
    });
    $('#next').click(function () {
        var nextLocation = selected.parent().next().find('a');
        if (!nextLocation.length) {
            nextLocation = firstSelected.parent().next().find('a');
        }
        self.location.href = nextLocation.attr('href');
        return false
    });

    if (!$('#About').length) {
        $('#menu div').css({ overflow: 'hidden', 'height': 0 })
        var submenu = $('#subAbout')
        submenu.hover(
            function () { $(this).find('a:first').addClass('selected').end().find('div').stop().animate({ height: '30px' }, 200) },
            function () { $(this).find('a:first').removeClass('selected').end().find('div').stop().animate({ height: '0px' }, 100); Cufon.replace('#menu') }
        )
    }

    $('#Home .panelCover').hover(
        function () {
            if (isIE) $(this).find('span').hide();
            $(this).animate({ opacity: 0 }, 'slow')
        },
        function () {
            if (isIE) $(this).find('span').show();
            $(this).animate({ opacity: 1 }, 'fast', function () {
                if (isIE) $(this)[0].style.removeAttribute('filter');
            })
        }
    )

    $('a[rel="external"]').attr('target', '_blank');
});

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25185346-1']);
_gaq.push(['_trackPageview']);

(function () {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
