// The Source Javascript
commons = {
    hover: function(options) {
        $(options.targets).hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });
    }
    /*,
    activate: function(options){
    $(options.targets).click(function(){
    $(this).siblings().removeClass('active');
    if(!$(this).hasClass('active')){
    $(this).addClass('active');
    }
    return false;           
    });
    },
	
	toggle: function(options){
    $(options.targets).click(function(){
    if(!$(this).hasClass('active')){
    $(this).addClass('active');
    }else{
    $(this).removeClass('active');
    }
    return false;
    });
    }*/
}

var timerId;

slides = {
    ini: function() {
        slides.postSlide();
        slides.subNavSlide();
        slides.brandLogoSlide();
        slides.pressSlide();
        slides.pressDetailSlide();
        slides.pressDetailNavSlide();
        slides.brandDetailSlide();
        slides.homePromoSlideLeft();
        slides.homePromoSlideRight();
        slides.lookbookThumbHover();
        slides.eventSlide();
        slides.subFeatureSlide();
        slides.downloadHoverSlide();
        slides.fittingRoomSlide();
        slides.productSlide();
        slides.relatedPostSlide();
        slides.aboutUsSlide();
    },
    postSlide: function() {
        $('.blog-list .post').hover(function() {
            var shift = -180;

            $(this).find('.slide-cont').stop().animate({ 'top': shift }, 300);
            //$(this).find('.slide-cont').stop().animate({'top':shift},'normal');
        },
			function() {
			    $(this).find('.slide-cont').stop().animate({ 'top': '0' }, 300);
			});
    },
    relatedPostSlide: function() {
        $('.related-posts .post').hover(function() {
            var shift = -180;

            $(this).find('.slide-cont').stop().animate({ 'top': shift }, 300);
            //$(this).find('.slide-cont').stop().animate({'top':shift},'normal');
        },
			function() {
			    $(this).find('.slide-cont').stop().animate({ 'top': '0' }, 300);
			});
    },
    productSlide: function() {
        $('.product-list .post').hover(function() {
            var shift = -180;

            $(this).find('.slide-cont').stop().animate({ 'top': shift }, 300);
            //$(this).find('.slide-cont').stop().animate({'top':shift},'normal');
        },
			function() {
			    $(this).find('.slide-cont').stop().animate({ 'top': '0' }, 300);
			});
    },
    downloadHoverSlide: function() {
        $('.download-list .item').hover(function() {

            //$(this).siblings().find('.image-cont .image-overlay').css({'display':'block'});
            //$(this).find('.image-cont .image-overlay').css({'display':'none'});
            $(this).find('.image-cont').css({ 'border': '1px solid #FFF' });
            //$(this).find('.line-detail li').css({ 'border-bottom': '1px solid #FFF' });
            //$(this).find('.on').css({'display':'block'}); //02 96904844 davui
        },
			function() {
			    //$(this).siblings().find('.image-cont .image-overlay').css({'display':'none'});
			    //$(this).find('.image-cont .image-overlay').css({'display':'none'});
			    $(this).find('.image-cont').css({ 'border': '1px solid #3f3f3f' });
			    //$(this).find('.line-detail li').css({ 'border-bottom': '1px solid #3f3f3f' });
			});
    },
    eventSlide: function() {
        $('.event-list .post').hover(function() {
            var shift = -250;

            $(this).find('.slide-cont').stop().animate({ 'top': shift }, 300);
            //$(this).find('.slide-cont').stop().animate({'top':shift},'normal');
        },
			function() {
			    $(this).find('.slide-cont').stop().animate({ 'top': '0' }, 300);
			});
    },
    fittingRoomSlide: function() {
        $('.fittingroom-list .post').hover(function() {
            var shift = -280;

            $(this).find('.slide-cont').stop().animate({ 'top': shift }, 300);
        },
			function() {
			    $(this).find('.slide-cont').stop().animate({ 'top': '0' }, 300);
			});
    },
    lookbookThumbHover: function() {
        $('.lookbook-grid .item').hover(function() {

            $(this).siblings('li.item').find('.shade').css({ 'display': 'block' });
        },
			function() {
			    $(this).siblings('li.item').find('.shade').css({ 'display': 'none' });
			});
    },
    pressDetailSlide: function() {
        $('.press-clipping .slide-cont .slide .clipping').hover(function() {

            $(this).siblings('li').find('.on').css({ 'display': 'none' });

            $(this).find('.on').css({ 'display': 'block' });
            //$(this).find('.slide-cont').stop().animate({'top':shift},'normal');
        },
        			function() {
        			    $(this).find('.on').css({ 'display': 'block' });
        			    $(this).siblings('li').find('.on').css({ 'display': 'block' });
        			});
    },
    brandDetailSlide: function() {
        $('.brand-detail .overlay .right .intro .slide .expand').click(function() {

            if ($('.brand-detail .overlay .right .intro .slide').css('top') == '0px')
                var shift = -405;
            else
                var shift = 0;

            $('.brand-detail .overlay .right .intro .slide').stop().animate({ 'top': shift }, 300);

        });
    },
    aboutUsSlide: function() {
        $('.about-us .overlay .right .intro .logo .expand').click(function() {

            if ($('.about-us .overlay .right .intro .slide').css('top') == '0px')
                var shift = -425;
            else
                var shift = 0;

            $('.about-us .overlay .right .intro .slide').stop().animate({ 'top': shift }, 300);

        });
    },
    pressSlide: function() {
        $('.press-list .clipping').hover(function() {
            var shift = -254;

            $(this).find('.slide-cont').stop().animate({ 'top': shift }, 300);
            //$(this).find('.slide-cont').stop().animate({'top':shift},'normal');
        },
			function() {
			    $(this).find('.slide-cont').stop().animate({ 'top': '0' }, 300);
			});
    },
    pressDetailNavSlide: function() {
        $('.press-clipping .controls ul.slide-nav li').click(function() {


            var i = $('.press-clipping .controls ul.slide-nav li').index(this);
            if (i == 0)
                var selectedShift = -5;
            else
                var selectedShift = ($('.press-clipping .controls ul.slide-nav li').width() * i) - (5);

            var coverShift = -(912 * i);

            //show active
            $('.press-clipping .controls ul.slide-nav li').siblings().removeClass('active');
            if (!$(this).hasClass('active')) {
                $(this).addClass('active');
            }

            //slide selected
            $('.press-clipping .controls .right .selected').stop().animate({ 'left': selectedShift }, 300);

            // slide covers
            $('.press-clipping .slide-cont .slide').stop().animate({ 'left': coverShift }, 300);


        });
    },
    subNavSlide: function() {
        $('.nav-item').hover(function() {
            var shift = 0;

            $(this).find('.sub-nav').stop().animate({ 'top': shift }, 300);
            //$(this).find('.slide-cont').stop().animate({'top':shift},'normal');
        },
			function() {
			    $(this).find('.sub-nav').stop().animate({ 'top': '-169' }, 300);
			});
    },
    brandLogoSlide: function() {
        $('.brand-grid .slide .item').hover(function() {
            var shift = -145;

            $(this).stop().animate({ 'top': shift }, 300);
            //$(this).find('.slide-cont').stop().animate({'top':shift},'normal');
        },
			function() {
			    $(this).stop().animate({ 'top': '0' }, 300);
			});
    },
    homePromoSlideLeft: function() {
        $('.home-features .slide-left').click(function() {
            var count = $('.home-features .slide-cont > div.slide').size();

            var shift = 1000;

            var currentActive = $('.home-features .slide-cont').css('left').replace('px', '') / shift;

            currentActive = (currentActive * -1)

            shift = shift * (currentActive - 1);

            if ((currentActive) == 1) {

                $('.home-features .slide-left').css('display', 'none');
            } else {

                $('.home-features .slide-left').css('display', 'block');
            }

            if ((currentActive) == count) {

                $('.home-features .slide-right').css('display', 'none');
            } else {

                $('.home-features .slide-right').css('display', 'block');
            }

            $('.home-features .slide-cont').stop().animate({ 'left': -shift }, 300);


            resetTimer(currentActive);
        });
    },
    subFeatureSlide: function() {
        $('.toolbar .sub-features li').hover(function() {
            var shift = -169;
            //alert("in here");
            $(this).find('.on').stop().animate({ 'top': shift }, 300);

        },
			function() {
			    $(this).find('.on').stop().animate({ 'top': 51 }, 300);
			});
    },
    homePromoSlideRight: function() {
        $('.home-features .slide-right').click(function() {
            var count = $('.home-features .slide-cont > div.slide').size();

            var shift = 1000;

            var currentActive = $('.home-features .slide-cont').css('left').replace('px', '') / shift;

            currentActive = (currentActive * -1)

            shift = shift * (currentActive + 1);

            if ((currentActive + 1) < 1) {

                $('.home-features .slide-left').css('display', 'none');
            } else {

                $('.home-features .slide-left').css('display', 'block');
            }

            if ((currentActive + 2) == count) {

                $('.home-features .slide-right').css('display', 'none');
            } else {

                $('.home-features .slide-right').css('display', 'block');
            }

            $('.home-features .slide-cont').stop().animate({ 'left': -shift }, 300);

            resetTimer(currentActive);
        });
    }
}


$(function() {

var hoverOptions = { targets: '.press-clipping .controls ul.slide-nav li, .home-features .slide-left, .home-features .slide-right' };
    //var actOptions = { targets : '#highlights .tabs ul li' };
    //var actOptions = { targets : '' };

    //var toggleOptions = { targets : '' };

    //var activeOptions = { targets : '' };
    commons.hover(hoverOptions);
    //commons.activate(actOptions);
    //commons.toggle(toggleOptions);

    slides.ini();

});


$(document).ready(function() {
    resetTimer(1); 
    var viewportwidth;
    var viewportheight;

    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerWidth,
              viewportheight = window.innerHeight
    }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

    else if (typeof document.documentElement != 'undefined'
             && typeof document.documentElement.clientWidth !=
             'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth,
               viewportheight = document.documentElement.clientHeight
    }

    // older versions of IE

    else {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
                 viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }

    var h = viewportheight - 500;
    $('#home .overlay').css({ 'height': h + 'px' });

});

function resetTimer(currentActive) {
    window.clearInterval(timerId);

    var i = currentActive + 1;
    var count = $('.home-features .slide-cont > div.slide').size();

    timerId = window.setInterval(function() {
    if (++i < count) {
    $('.home-features .slide-right').click();

    } else {
    i = 1;
    $('.home-features .slide-cont').stop().animate({ 'left': 0 }, 300);
    $('.home-features .slide-left').css('display', 'none');
    $('.home-features .slide-right').css('display', 'block');
    }
    }, 6000);
}






