﻿$(document).ready(function(){

	$("body").css("display", "none");
	//$("body").fadeIn(2000, loadContent);
	$("body").fadeIn(500);
	
	$(".nav a").click(function(event){
        event.preventDefault();
        linkLocation = this.href;
        $("body").fadeOut(500, redirectPage);
    });
 
    function redirectPage() {
        window.location = linkLocation;
    }
	
    /*---------- Dynamic Lead ----------*/
    if($('#slider').length > 0){
        $('#slider').cycle({
            fx:     'fade',
            pager:  '.sliderNav',
            pagerEvent: 'mouseover',
            speed:   500,
            timeout: 0
    	});
    }

    /*---------- Our Action Process ----------*/
    $('.bottom-menu .item1').click(function(){
        if($(this).hasClass('active')){
        }else{
            $('.auctionProcess ul li').fadeOut(300);
        }
        $('li.howItWorks').fadeIn(400);
        $('#slider li:first-child').fadeIn(400);
        $('.bottom-menu a').removeClass('active');
        $('.bottom-menu .item1').addClass('active');

    });

    $('.bottom-menu .item2').click(function(){
        if($(this).hasClass('active')){
        }else{
            $('.auctionProcess ul li').fadeOut(300);
        }
        $('li.wise').fadeIn(400);
        $('.bottom-menu a').removeClass('active');
        $('.bottom-menu .item2').addClass('active');
    });

    $('.bottom-menu .item3').click(function(){
        $('.bottom-menu a').removeClass('active');
		
		if ($('.lightbox').length == 0)
		{
			$('body').prepend('<div class="lightbox"><!-- --></div>');
			$('body').prepend('<div class="lightbox"><!-- --></div>');
			// set the propper video to each section. One for the public and one for the client section.
			if ($('.client-section').length > 0)
			{
				$('body').prepend('<div class="video-lightbox"><iframe width="600" height="400" src="http://www.youtube.com/embed/uoO6D3YXQGc?rel=0" frameborder="0" allowfullscreen></iframe></div>');
			}
			else
			{
				$('body').prepend('<div class="video-lightbox"><iframe width="600" height="400" src="http://www.youtube.com/embed/IzkGSI-kb0k?rel=0" frameborder="0" allowfullscreen></iframe></div>');
			}
		}
        $('.lightbox').fadeIn(200);
        $('.video-lightbox').fadeIn(300);
        $('.lightbox').click(function(){
            $('.video-lightbox').fadeOut(170);
            $(this).fadeOut(200, function(){
                //$('.lightbox, .video-lightbox').detach();
            });
        });
    });

    /*---------- Portfolio ----------*/
    $('.openPorfolio, .bigArrow').click(function(){
        $('.portfolio').slideUp(400, function(){
            //$('.block').fadeOut(300);
            $('.portfolioGallery').fadeIn(350, function(){
				$('.portfolioGallery ul li:even').addClass('even');
				$('.portfolioGallery ul li:odd').addClass('odd');
				$('.portfolioGallery ul').fadeIn(300);
				$('.portfolioGallery').jScrollPane();
				$('.portfolioGallery').css('background','#27318B');
				 $('.backBtn').click(function(){
						$('.portfolioGallery').fadeOut(400, function(){
							$('.portfolioGallery ul').hide();
							$('.portfolio').slideDown(400);
						});
					});
            })
        });
    });


    /*---------- About Us ----------*/
    $('.teamMenu a').click(function(){
        if($(this).hasClass('active')){
        }else{
            $('.teamMenu a').removeClass('active');
            $(this).addClass('active');
            var showInfo = $(this).attr('dsc');
            $('.column .about').css('padding-right','23px');
            $('.about-description').show(300, function(){
                $('.about-description li').fadeOut(50);
                $('.about-description li.' + showInfo).fadeIn(150);
                $('.about-description li#scrollable').jScrollPane();
            });
        }
    });

    /*---------- Project Experience Gallery ----------*/
    $('.seeList').click(function(){
        $('.projectExperience').slideUp(400, function(){
            $('.projectExperienceGallery').fadeIn(350, function(){
				$('.projectExperienceGallery ul li:even').addClass('even');
				$('.projectExperienceGallery ul li:odd').addClass('odd');
				$('.projectExperienceGallery ul').fadeIn(300);
				$('.projectExperienceGallery').css('background','#711471');
				 $('.backBtn').click(function(){
						$('.projectExperienceGallery').fadeOut(400, function(){
							$('.projectExperienceGallery ul').hide();
							$('.projectExperience').slideDown(400);
						});
					});
            })
        });
    });

    /*---------- Prcess ----------*/
    $('.arrowStep').mouseover(function(){
        if( $(this).hasClass('active') ){}
        else{
            $('.arrowStep').removeClass('active');
            $('span.time').removeClass('active');
            $(this).addClass('active').parent().find('span.time').addClass('active');
            //$(this).parent().find()
            $('.circles').fadeOut(100);
            $(this).parent().find('.circles').slideDown(300);
        }
    });


    if($('.column').hasClass('homePage')){
		$.fn.blocksCycle.defaults.urls = intellimarket.images;
        window.setTimeout(function(){$('.main').blocksCycle();}, 1000);
    };

	if($('.column').hasClass('auction')){
		$.fn.blocksCycle.defaults.urls = intellimarket.images;
		$.fn.blocksCycle.defaults.infinite = false;
        window.setTimeout(function(){$('.main').blocksCycle();}, 1000);
		
		$('body').prepend('<div class="lightbox"><!-- --></div>');
		// set the propper video to each section. One for the public and one for the client section.
		if ($('.client-section').length > 0)
		{
			$('body').prepend('<div class="video-lightbox"><iframe width="600" height="400" src="http://www.youtube.com/embed/uoO6D3YXQGc?rel=0" frameborder="0" allowfullscreen></iframe></div>');
		}
		else
		{
			$('body').prepend('<div class="video-lightbox"><iframe width="600" height="400" src="http://www.youtube.com/embed/IzkGSI-kb0k?rel=0" frameborder="0" allowfullscreen></iframe></div>');
		}
		
    };

	if($('.column').hasClass('contact')){
		$.fn.blocksCycle.defaults.urls = intellimarket.images;
		$.fn.blocksCycle.defaults.infinite = false;
        window.setTimeout(function(){$('.main').blocksCycle();}, 1000);
    };

	if($('.column').hasClass('about')){
		$.fn.blocksCycle.defaults.urls = intellimarket.images;
		$.fn.blocksCycle.defaults.infinite = false;
        window.setTimeout(function(){$('.main').blocksCycle();}, 1000);
    };

	if($('.column').hasClass('portfolio-page')){
		$.fn.blocksCycle.defaults.urls = intellimarket.images;
		$.fn.blocksCycle.defaults.infinite = false;
        window.setTimeout(function(){$('.main').blocksCycle();}, 1000);
    };

    if($('.column').hasClass('news')){
		$.fn.blocksCycle.defaults.urls = intellimarket.images;
		$.fn.blocksCycle.defaults.infinite = false;
        window.setTimeout(function(){$('.main').blocksCycle();}, 1000);
    };
	
	if($('.column').hasClass('thank')){
		$.fn.blocksCycle.defaults.urls = intellimarket.images;
		$.fn.blocksCycle.defaults.infinite = false;
        window.setTimeout(function(){$('.main').blocksCycle();}, 1000);
    };
	
	if($('.column').hasClass('privacy-policy')){
		$.fn.blocksCycle.defaults.urls = intellimarket.images;
		$.fn.blocksCycle.defaults.infinite = false;
        window.setTimeout(function(){$('.main').blocksCycle();}, 1000);
		$('.privacy').jScrollPane();
    };


	if ($('.galleryList'))
	{
		$(".galleryList li:nth-child(1)").addClass('first');
		$(".galleryList li:nth-child(2)").addClass('first');
		
		var len = $(".whiteRule").length;
		$($(".whiteRule")[len - 1]).remove();
		$($(".whiteRule")[len - 2]).remove();
	}
	
	if ($('.hearItBlock'))
	{
		$('.hearItBlock').jScrollPane();
	}
	
	// if contact form present
	if ($('#icpsignup5475').length > 0)
	{
		// removing the message for the required validator, we will only  mark the fields.
		jQuery.validator.messages.required = "";
		jQuery.validator.messages.email = "";

		$("#icpsignup5475").validate({
			invalidHandler: function(e, validator) {
				
				var errors = validator.numberOfInvalids();
				if (errors) {
					var message = errors == 1
						? 'You missed 1 field. It has been highlighted.'
						: 'You missed ' + errors + ' fields.  They have been highlighted.';
					//$("div.error span").html(message);
					//alert(message);
					//$("div.error").show();
				} else {
					//$("div.error").hide();
				}
			},
			onkeyup: false,
			messages: {
			},
			debug:false
		});
	}
});
