var width1;

if($("#additionals_line").length>0){width1=1020}else{width1=265}
(function () {
    $.fn.infiniteCarousel = function () {
        function repeat(str, n) {
            return new Array(n + 1).join(str);
        }

        return this.each(function () {
            // magic!
            var $wrapper = $('> div', this).css('overflow', 'hidden'),
                $slider = $wrapper.find('> ul').width(9999),
                $items = $slider.find('> li'),
                $single = $items.filter(':first')

            singleWidth = width1,
                visible = Math.ceil($wrapper.innerWidth() / singleWidth),
                currentPage = 1,
                pages = Math.ceil($items.length / visible);

            /* TASKS */

            // 1. pad the pages with empty element if required
            if ($items.length % visible != 0) {
                // pad
                $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
                $items = $slider.find('> li');
            }

            // 2. create the carousel padding on left and right (cloned)
            $items.filter(':first').before($items.slice(-visible).clone().addClass('cloned'));
            $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
            $items = $slider.find('> li');

            // 3. reset scroll
            $wrapper.scrollLeft(singleWidth * visible);

            // 4. paging function


            function gotoPage(page) {
                var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;

                $wrapper.filter(':not(:animated)').animate({
                    scrollLeft: '+=' + left
                },
                500, function () {
                    // if page == last page - then reset position
                    if (page > pages) {
                        $wrapper.scrollLeft(singleWidth * visible);
                        page = 1;
                    } else if (page == 0) {
                        page = pages;
                        $wrapper.scrollLeft(singleWidth * visible * pages);
                    }

                    currentPage = page;
                $(".navigation li a").removeClass("selected");
                $(".navigation li a").eq(page - 1).addClass("selected");
				});
				
            }

            // 5. insert the back and forward link
            $wrapper.after('<a href="#" class="arrow back">&lt;</a><a href="#" class="arrow forward">&gt;</a>');

            // 6. bind the back and forward links
            $('a.back', this).click(function () {
                return gotoPage(currentPage - 1);
            });
            $('a.forward', this).click(function () {
                return gotoPage(currentPage + 1);
            });
            $('a.pic1', this).click(function () {
                return gotoPage(1);
            });
            $('a.pic2', this).click(function () {
                return gotoPage(2);
            });
            $('a.pic3', this).click(function () {
                return gotoPage(3);
            });
            $('a.pic4', this).click(function () {
                return gotoPage(4);
            });
            $(this).bind('goto', function (event, page) {
                gotoPage(page);
            });
            $(this).bind('next', function () {
                gotoPage(currentPage + 1);
            });
        });
    };
})(jQuery);


$(document).ready(function () {
var menuPos = new Array();							
menuPos = {"technology": 0,  "products": -20, "games_applications": 10, "developers": -12, "partners": -19, "about": -10, "contact": -13};

$("#menu_links li").hover(function () {$("#glow").show();$("#glow").css("left",240 + $(this).position().left + menuPos[this.id] + "px" );}, function(){$("#glow").hide()});
    if($.browser.mozilla){$("#products").hover(function () {
        $("#products ul").show()
    },
    function () {
        $("#products ul").hide()
    })
    $("#about").hover(function () {
        $("#about ul").show()
    },
    function () {
        $("#about ul").hide()
    })}
if($.browser.msie){var relativeX; var relativeY;
	$("#header").mousemove( function(e) {
     relativeX = e.pageX - this.offsetLeft;
    relativeY = e.pageY - this.offsetTop;
	  if(relativeX>363 && relativeX<465 && relativeY>10){$("#products ul").show();}else{$("#products ul").hide();}
       if(relativeX>782 && relativeX<884 && relativeY>10){$("#about ul").show();}else{$("#about ul").hide();}})
	$("#content_area").hover(function () {
	$("#products ul, #about ul").hide()
	})}
    
	//$("#menu_links").mousemove(function(e){
//    var relativeX = e.pageX - this.offsetLeft;
//    var relativeY = e.pageY - this.offsetTop;
//	if(relativeX>680 && relativeX<780){$("#about ul").show();}else{$("#about ul").hide();}
//	if(relativeX>272 && relativeX<357){$("#products ul").show()}else{$("#products ul").hide();}
//	$("#about ul").mouseout(function(){$("#about ul").hide();})

//	})

	
    $(function () {if($("#additionals_line").length>0){
 
$(".infiniteCarousel").hover(function () {
            if($.browser.mozilla){$("#1, #2").fadeIn();}else{$("#1, #2").show();$("#products ul, #about ul").hide()}

        },
        function () {
            if($.browser.mozilla){$("#1, #2").fadeOut();}else{$("#1, #2").hide()}

        });}
        $("#1").hover(function () {
            $(this).addClass("back_hover");
        },
        function () {
            $(this).removeClass("back_hover");
        });
        $("#1").mousedown(function () {
            $(this).addClass("back_active");
        });
        $("#1").mouseup(function () {
            $(this).removeClass("back_active");
        });
        $("#2").hover(function () {
            $(this).addClass("forward_hover");
        },
        function () {
            $(this).removeClass("forward_hover");
        });
        $("#2").mousedown(function () {
            $(this).addClass("forward_active");
        });
        $("#2").mouseup(function () {
            $(this).removeClass("forward_active");
        });
    });
    var autoscrolling = true;
    $('.infiniteCarousel').infiniteCarousel().mouseover(function () {
        autoscrolling = false;
    }).mouseout(function () {
        autoscrolling = true;
    });
    setInterval(function () {
        if (autoscrolling) {
			if ($("#fancy_outer").length>0)
			{
				if($("#fancy_outer").css('display')=="none")
				{
					$('.infiniteCarousel').trigger('next');
				}
			}
			else
			{
				$('.infiniteCarousel').trigger('next');
			}
            
        }
    },
    6500);
	
})
if($("a[rel=fancyvideo]").length>0){
$("a[rel=fancyvideo]").fancybox({
overlayShow: true,
frameWidth:640,
frameHeight:360})}