$(document).ready(function () {

    var d = $(window).width(),
        flag = 0,
        the_nav, nav_pos, nav_width, next, _index = 0,
        _rel, _href, _cols, _colWidth, timer, slideSpeed = 5000, 
		maxIndex = -1, t = setTimeout(nextSlide,slideSpeed);
	$(".box-wrapper").each(function(){maxIndex=maxIndex+1})
	function nextSlide() {
		if (_index < maxIndex){_index = _index + 1;}else{_index = 0;};
		$(".box-wrapper.active, .block-holder.active").removeClass('active');
		$(".box-wrapper").eq(_index).addClass('active');
		$(".block-animator").animate({
			'margin-left': '-' + ((d + 135) * _index) + 'px'
		}, 1200, 'easeInOutExpo', function () {
			flag = 0;
			t = setTimeout(nextSlide,slideSpeed);
		})
	};
    $(".block-animator .block-holder, .block-wrapper").each(function () {
        if ($.browser.msie) {
            $(this).width(d).css({
                'display': 'block'
            })
        } else {
            $(this).width(d).fadeIn("slow")
        }
    });
    $("a").each(function () {
        $(this).attr("hideFocus", "true").css("outline", "none")
    });
    $(".dropdown-holder").each(function () {
        var a = $(this).closest('.dropdown');
        var b = $(a).closest('li').position();
        $(this).find('.col:last').addClass('last');
        _cols = $(this).find('.col').length;
        _colWidth = $(this).find('.col').width();
        if (_cols < 3) {
            $(a).width((_colWidth * 2) + 200);
            $(a).find('.c').css({
                'padding-right': '0px'
            })
        }
    });
    $("a[href*='youtube']").attr('rel', 'shadowbox');
    $("#content a").each(function () {
        if ($(this).closest('.blog-wrapper').length < 0) {
            _rel = $(this).attr('rel');
            _href = $(this).attr('href');
            if (_href == '#') {
                _href = '#none'
            }
            if ($(this).children().is('img')) {
                $(this).attr('rel', 'shadowbox ' + _rel)
            }
        }
    });
    $(".bucket-container .bucket").equalHeights();
    $("#nav > li").each(function () {
        if ($(this).find('.dropdown').length >= 1) {
            $(this).addClass('hasChildren')
        }
        $(this).find('a:first').addClass('first')
    });
    $("#lp-tabs > li > a").click(function () {
        var a = $(this).parent().index();
        $("#lp-tabs li.active, #lp-tabs li.active a.active").removeClass('active');
        $(".tab-container > .tab-content.active").removeClass('active').addClass('hidden');
        $("#lp-tabs li").eq(a).addClass('active').children('a').addClass('active');
        $(".tab-container > .tab-content").eq(a).removeClass('hidden').addClass('active');
        return false
    });
    $(".menu-header-container .menu > li").bind('mouseover', function () {
        if ($.browser.msie) {
            $(".dropdown:visible").closest('li').removeClass('hover');
            $(".menu-header-container .menu > li.active").removeClass('hover');
            clearTimeout(timer)
        }
        the_nav = $(this).find('.dropdown');
        if ($(".menu-header-container .menu > li.active").length != 0) {
            $(".menu-header-container .menu > li.active").removeClass('hover')
        }
        if ($(the_nav).length == 1) {
            $(this).addClass('hover');
            if ($.browser.msie) {
                if (parseInt($.browser.version, 10) >= 8) {
                    $(".dropdown-holder > div").equalHeights()
                }
            } else {
                $(".dropdown-holder > div").equalHeights()
            }
        }
    }).bind('mouseout', function () {
        if ($.browser.msie) {
            if ($(this).find('.dropdown').is(':visible')) {} else {
                $(this).removeClass('hover')
            }
        } else {
            $(this).removeClass('hover')
        }
    });
    if ($.browser.msie) {
        if (parseInt($.browser.version, 10) < 8) {
            $(".dropdown").bind('mouseover', function () {
                clearTimeout(timer);
                $(this).closest('li').addClass('hover')
            }).bind('mouseout', function () {
                timer = setTimeout(function () {
                    $(".dropdown:visible").closest('li').removeClass('hover')
                }, 500)
            })
        }
    }
    $(".box-wrapper").hover(function () {
        $(this).find('a').css({
            'color': '#FFFFFF'
        })
    }, function () {
        $(this).find('a').removeAttr('style')
    });
    $('#.tabset.blog-nav > li > a').bind('click', function () {
        var a = $(this).parent();
        var b = $('blog-home-container.active');
        var c = $(this).attr('name');
        $('#.tabset.blog-nav > li.active').removeClass('active');
        $(a).addClass('active');
        if ($.browser.msie) {
            $('.blog-home-container.active').css({
                'display': 'none'
            }).removeClass('active');
            if ($('#' + c + '-container').hasClass('hidden')) {
                $('#' + c + '-container').removeClass('hidden')
            }
            $('#' + c + '-container').css({
                'display': 'block'
            }).addClass('active')
        } else {
            $('.blog-home-container.active').fadeOut('fast', function () {
                $(this).removeClass('active');
                if ($('#' + c + '-container').hasClass('hidden')) {
                    $('#' + c + '-container').removeClass('hidden')
                }
                $('#' + c + '-container').fadeIn('fast').addClass('active')
            })
        }
        return false
    });
    $(".box").bind('click', function () {
		_index = $(this).parent().index();
		if (flag == 0) {
			clearTimeout(t);
			flag = 1;
			var a = $(this).attr('id');
			$(".box-wrapper.active, .block-holder.active").removeClass('active');
			$(this).addClass('active');
			$(".box-wrapper").eq(_index).addClass('active');
			$(".block-animator").animate({
				'margin-left': '-' + ((d + 135) * _index) + 'px'
			}, 1200, 'easeInOutExpo', function () {
				flag = 0
				t = setTimeout(nextSlide,slideSpeed);
			})
		}
		return false
	});
    $(window).resize(function () {
        d = $(window).width();
        $(".block-animator .block-holder, .block-wrapper").width(d)
    });
    $(".see a").hover(function () {
        $(this).stop().animate({
            'margin-left': 15
        }, 200)
    }, function () {
        $(this).stop().animate({
            'margin-left': 0
        }, 200)
    });
    $(".see a").bind('click', function () {
		if (flag == 0) {
			clearTimeout(t);
			flag = 1;
			next = $(this).closest('.block-holder').next().length;
			_index = parseInt($(this).closest('.block-holder').index()) + 1;
			if (next != 0) {
				$(".box-wrapper.active, .block-holder.active").removeClass('active');
				$(".box-wrapper").eq(_index).addClass('active');
				$(".block-holder").eq(_index).addClass('active');
				$(".block-animator").animate({
					'margin-left': '-' + ((d + 135) * _index) + 'px'
				}, 1200, 'easeInOutExpo', function () {
					flag = 0;
					t = setTimeout(nextSlide,slideSpeed);
				})
			} else {
				return true
			}
		}
		return false
	});
    $("#sidebar > ul.tweets").tweet({
        username: "voxmobile",
        count: 5,
        loading_text: 'loading tweets...'
    })
});
(function ($) {
    $.fn.equalHeights = function (a, b) {
        tallest = (a) ? a : 0;
        this.each(function () {
            if ($(this).height() > tallest) {
                tallest = $(this).height()
            }
        });
        if ((b) && tallest > b) tallest = b;
        if (tallest >= 310) {
            var c = (tallest - 300) + 5
        }
        return this.each(function () {
            $(this).height(tallest).css({
                "overflow": "visible",
                "background-position": "0 " + c + "px"
            })
        })
    }
})(jQuery);

function detectMobile() {
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
        return true
    }
}
