$(document).ready(function() {

    
        function formatText(index, panel) {
		  return index + "";
	    }
    
        $(function () {
        
            $('.anythingSlider').anythingSlider({
                easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
                autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
                delay: 10000,                    // How long between slide transitions in AutoPlay mode
                startStopped: false,            // If autoPlay is on, this can force it to start stopped
                animationTime: 600,             // How long the slide transition takes
                hashTags: false,                 // Should links change the hashtag in the URL?
                buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
        		pauseOnHover: false,             // If true, and autoPlay is enabled, the show will pause on hover
        		startText: "",             // Start text
		        stopText: "",               // Stop text
		        navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
            });
            
            $("#slide-jump").click(function(){
                $('.anythingSlider').anythingSlider(6);
            });
            
        });
    
////buyers guide

    //rotation speed and timer
    var speed = 1000;
    var run = setInterval('rotate()', speed);

    //grab the width and calculate left value
    var item_width = $('#slides li').outerWidth();
    var left_value = item_width * (-1);

    //move the last item before first item, just in case user click prev button
    $('#slides li:first').before($('#slides li:last'));

    //set the default item to the correct position 
    $('#slides ul').css({ 'left': left_value });
  
    //if user clicked on prev button
    $('#prev').hover(
    
     function() {
		    clearInterval(run);
		},
		function() {
		    run = setInterval('rotate()', speed);
		}
    );
      $('#next').hover(
    
     function() {
		    clearInterval(run);
		},
		function() {
		    run = setInterval('rotate()', speed);
		}
    );
    $('#prev').click(function() {

        //get the right position            
        var left_indent = parseInt($('#slides ul').css('left')) + item_width;

        //slide the item            
        $('#slides ul').animate({ 'left': left_indent }, 200, function() {

            //move the last item and put it as first item            	
            $('#slides li:first').before($('#slides li:last'));

            //set the default item to correct position
            $('#slides ul').css({ 'left': left_value });

        });

        //cancel the link behavior            
        return false;

    });


    //if user clicked on next button
    $('#next').click(function() {

        //get the right position
        var left_indent = parseInt($('#slides ul').css('left')) - item_width;

        //slide the item
        $('#slides ul').animate({ 'left': left_indent }, 200, function() {

            //move the first item and put it as last item
            $('#slides li:last').after($('#slides li:first'));

            //set the default item to correct position
            $('#slides ul').css({ 'left': left_value });

        });

        //cancel the link behavior
        return false;

    });

    //if mouse hover, pause the auto rotation, otherwise rotate it
    $('#slides').hover(

		function() {
		    clearInterval(run);
		},
		function() {
		    run = setInterval('rotate()', speed);
		}
	);
///buyers guide
    $("#navlist").show();
   
     
    
    $("#linksearch").click(function(){
        if(document.getElementById("search_op").style.display=="none")
              document.getElementById("search_op").style.display="block";
       else
          document.getElementById("search_op").style.display="none";
    });
    
    $("#close").click(function(){
     document.getElementById("search_op").style.display = "none";
    });
    
      var URL = new String(window.location);
        var ResultsURL = URL.split("/")[3].toUpperCase();
        $("#menumain a").each(function(i) {
           
            var List = ($(this).html()).toUpperCase();
            if (ResultsURL == "") {
                if ($(this).html() == "Home") {
                
                    $(this).attr("class", "active");
                }
            }
            else if (ResultsURL == List) {
           
                $(this).attr("class", "active");
            }
        else if (ResultsURL == "INTERIOR_DESIGN_PROJECTS") {
                
               if ($(this).html() == "Projects") {
                
                   $(this).attr("class", "active");
                }
        
           }
           
       
            
        });
    
    
    
    $('#divProjectSearch').show();

//    $('.infiniteCarousel').infiniteCarousel();

    $('#EmailFriend').click(function() {

        var re = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
        if (($('#SenderName').val() == '')) {
            $('#EmailReqired').show(1000);
            if (($('#SenderMailId').val().search(re) > -1) && ($('#ToEmailList').val().search(re) > -1)) {
                $('#EmailErrordevEmail').hide(2000);
            }
            return false
        }
        else {
            $('#EmailReqired').hide(1000);

            if (($('#SenderMailId').val().search(re) > -1) && ($('#ToEmailList').val().search(re) > -1)) {
                $('#EmailErrordevEmail').hide(2000);
                //$('#mask').hide(1000);
                //$('#maincontaner').animate({ top: '500px', left: '1200px' }, 1000);
                $('#maincontaner').hide(100);
                $('#ConfimMail').show(2000);

                return true;
            }
            else {
                $('#EmailErrordevEmail').show(1000);
                return false;
            }
        }


    });


    $("#emailAFriend").hide();
    $("#create").click(function() {

        $("#emailAFriend").slideToggle(2000);

        $("#maincontaner").show(2000);


        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        $('#mask').css({ 'width': maskWidth, 'height': maskHeight, backgroundColor: "black" });

        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow", 0.8);

        $('#SenderName').val('');
        $('#SenderMailId').val('');
        $('#tags2').val('');

        $("#t_error").html("");
        $("#d_error").html("");
        $("#tg_error").html("");
    });

    $("#cls").click(function() {
        $('#mask').hide();
        $('#EmailErrordevEmail').hide(2000);
        $("#emailAFriend").hide('slow');
        $('#maincontaner').hide("slow");

    });

    $('#btnSubmit').click(function() {
        var title_r = $('#SenderName').val();
        var desc_r = $('#SenderMailId').val();
        var tag_r = $('#tags2').val();

        var title = $.trim(title_r);
        var desc = $.trim(desc_r);
        var tag_r = $.trim(tag_r);
        var login = "Login";
        var start = "start";

        if (title != '' && desc != '' && tag_r != '') {
            $('#t_error').hide();
            $('#d_error').hide();
            $('#tg_error').hide();
        } else {
            if (title == '') {
                $('#t_error').show();
                $("#t_error").html("(Not Empty.)");
            }
            if (desc == '') {
                $('#d_error').show();
                $("#d_error").html("(Not Empty.)");
            }
            if (tag_r == '') {
                $('#tg_error').show();
                $("#tg_error").html("(Not Empty.)");
            }
        }
    });

    $('#projectSearch').click(function() {

        var objFromDate = document.getElementById("txtFromDate").value;
        var objToDate = document.getElementById("txtToDate").value;
        var date1 = new Date(objFromDate.replace(/[-]/g, " "));
        var date2 = new Date(objToDate.replace(/[-]/g, " "));
        var date3 = new Date();
        mymonth = date3.getMonth();

        if (mymonth == 0)
            month = "Jan"
        else if (mymonth == 1)
            month = "Feb"
        else if (mymonth == 2)
            month = "Mar"
        else if (mymonth == 3)
            month = "Apr"
        else if (mymonth == 4)
            month = "May"
        else if (mymonth == 5)
            month = "Jun"
        else if (mymonth == 6)
            month = "Jul"
        else if (mymonth == 7)
            month = "Aug"
        else if (mymonth == 8)
            month = "Sep"
        else if (mymonth == 9)
            month = "Oct"
        else if (mymonth == 10)
            month = "Nov"
        else if (mymonth == 11)
            month = "Dec"
       // var objRegExp = /^([012]?\d|3[01])-([Jj][Aa][Nn]|[Ff][Ee][bB]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][u]l|[aA][Uu][gG]|[Ss][eE][pP]|[oO][Cc]|[Nn][oO][Vv]|[Dd][Ee][Cc])-(19|20)\d\d$/
      
        var objRegExp =/^(0[1-9]|[12][0-9]|3[01])[- /.]([A-Za-z]{3})[- /.](19|20)\d\d$/
        if (objFromDate != "") {
            if (objRegExp.test(objFromDate) == false) {
                $('#errorMessageTo').hide(500);
                $('#errorMessageToLess').hide(500);
                $('#errorMessageFromLess').hide(500);
                $('#errorMessageDate').hide(500);
                $('#errorMessageFrom').show(500);

                // alert("Please enter valid From date (dd-mmm-yyyy)");
                return false;
            }
        }
        if (objToDate != "") {
            if (objRegExp.test(objToDate) == false) {
                $('#errorMessageToLess').hide(500);
                $('#errorMessageFromLess').hide(500);
                $('#errorMessageDate').hide(500);
                $('#errorMessageFrom').hide(500);
                $('#errorMessageTo').show(500);
                return false;
            }
        }
        var date4 = date3.getDate() + "-" + month + "-" + date3.getFullYear();
        var currentDate = new Date(date4.replace(/[-]/g, " "));
        if (date1 > date2) {
            $('#errorMessageFromLess').hide(500);
            $('#errorMessageDate').hide(500);
            $('#errorMessageFrom').hide(500);
            $('#errorMessageTo').hide(500);
            $('#errorMessageToLess').show(500);
            return false;
        }
        else if (date1 > currentDate) {

            $('#errorMessageDate').hide(500);
            $('#errorMessageFrom').hide(500);
            $('#errorMessageTo').hide(500);
            $('#errorMessageToLess').hide(500);
            $('#errorMessageFromLess').show(500);
            return false;
        }
        else if (date2 > currentDate) {
            $('#errorMessageFrom').hide(500);
            $('#errorMessageTo').hide(500);
            $('#errorMessageToLess').hide(500);
            $('#errorMessageFromLess').hide(500);
            $('#errorMessageDate').show(500);
            return false;
        }


    });
      if ($("#SearchStatus").val() == "1") {

        document.getElementById("search_op").style.display = "block";
    }
    else {

        document.getElementById("search_op").style.display = "none";
    }



//Buyers guide carousel

//end of buyers guide carousel

});


function rotate() {
    $('#next').click();
}







//$.fn.infiniteCarousel = function() {

//    function repeat(str, num) {

//        return new Array(num + 1).join(str);
//    }

//    return this.each(function() {
//    
//        var $wrapper = $('> div', this).css('overflow', 'hidden'),
//            $slider = $wrapper.find('> ul'),
//            $items = $slider.find('> li'),
//            $single = $items.filter(':first'),

//            singleWidth = $single.outerWidth(),
//            visible = Math.ceil($wrapper.innerWidth() / singleWidth), // note: doesn't include padding or border
//            currentPage = 1,
//            pages = Math.ceil($items.length / visible);
//            

//        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
//        //        if (($items.length % visible) != 0) {
//        //            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
//        //            $items = $slider.find('> li');
//        //        }

//        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
//        $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'); // reselect

//        // 3. Set the left position to the first 'real' item
//        $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;
//          
//         
//          
//          
//            left = dir<1 ? -525:525;
//        
//            $wrapper.filter(':not(:animated)').animate({
//                scrollLeft: '+=' + left
//            }, 500, function() {
//                if (page == 0) {
//                    $wrapper.scrollLeft(singleWidth * visible * pages);
//                    page = pages;
//                } else if (page > pages) {

//                    $wrapper.scrollLeft(singleWidth * visible);
//                    // reset back to start position
//                    page = 1;
//                }

//                currentPage = page;
//            });

//            return false;
//        }
//        
//         
//        

//        $wrapper.after('<a class="arrow back">&lt;</a><a class="arrow forward">&gt;</a>');

//        // 5. Bind to the forward and back buttons
//        $('a.back', this).click(function() {
//        
//            return gotoPage(currentPage-1);
//        });

//        $('a.forward', this).click(function() {
//        
//            return gotoPage(currentPage+1);
//        });

//        // create a public interface to move to a specific page
//        $(this).bind('goto', function(event, page) {
//            gotoPage(page);
//        });
//    });
//};

