﻿var intervalID;
var slideIndex = 2;
var timeOutId;

$(document).ready(function () {
    //home page main pops
    $('.category').live('click', function () {
        $('body').append($('<div>').append($('.main-pops .categoryPop').clone()).remove().html() + '<div class="overlay"></div>');
        $('.overlay').css('height', $(document).height());
        middlePop();
    });
    $('.industry').live('click', function () {
        $('body').append($('<div>').append($('.main-pops .industryPop').clone()).remove().html() + '<div class="overlay"></div>');
        $('.overlay').css('height', $(document).height());
        middlePop();
    });
    $('.pop-wrapper .close').live('click', function () {
        $('body > .pop-wrapper, body > .overlay').remove();
    });

    //home slideshow
    slideShow();
    $("#gallery img").hover(
        function () { clearTimeout(timeOutId); },
        function () { slideShow(); }
    );
    //intervalID = setInterval('gallery()', 3000);    
    //    $("#gallery img").hover(
    //        function () { window.clearInterval(intervalID); },
    //        function () { intervalID = setInterval('gallery()', 3000); }
    //    );

    //footer popup animations
    $('.main-footer .pop').hover(
        function () {
            if (!$(this).is(':animated'))
                $(this).animate({ height: '174' }, 250);
        },
        function () {
            $(this).animate({ height: '54' }, 250);
        }
    );  
    
   
	   	 fixDot();
	function fixDot(){
	 
	 	var width = $(window).width(); 
		if (width <1108){
		    $('.header-special').css("left","5%");
		}      
		else
		{
		      $('.header-special').css("left","8%");
		}
	 
	}
    	  //fix for small resolution
    	$(window).resize(function () {
		fixDot(); 
	});  
    
});

function slideShow() {
    timeOutId = setTimeout(gallery, 3000);
}

function gallery() {
    var browser = $.browser
    if (browser.msie && parseInt(browser.version.substring(0, 1)) < 9) {
        var img = new Image();
        img.src = '/Content/Images/home/home-gallery/slide' + slideIndex + '.png';
        img.onload = function () {
            $("#gallery img").show(function () {
                $(this).attr('src', img.src);
                slideIndex = slideIndex == 7 ? 1 : slideIndex + 1;
                slideShow();
            });
        }        
    }
    else {        
        var img = new Image();
        img.src = '/Content/Images/home/home-gallery/slide' + slideIndex + '.png';
        img.onload = function () {
            $("#gallery img").fadeOut("normal", function () {
                $(this).attr('src', img.src);
                $(this).fadeIn("fast");
                slideIndex = slideIndex == 7 ? 1 : slideIndex + 1;
                slideShow();
            });
        }
    }
}

function middlePop() {
    $('.pop-wrapper').css('top', ($(window).height() - $('body > .pop-wrapper').height()) / 2 + $(window).scrollTop() + "px");
}
