
$(document).ready(function() {

    var innerpage = isFrontPage;
    if (innerpage == "hide") 
	{
        $('body').addClass('innerBG');
        $('#mainCnt h1').addClass('titl');
        $('#cnt_menuHold').hide();
		$('#mainCnt').find('.blogs_list').next().addClass('paginate');

    }
    else 
	{
        $('#mainimage').addClass('towrap');
        $('#mainCnt').children('p').addClass('towrap');
        $('.dsp2').addClass('towrap');
        $(".towrap").wrapAll('<div class="chkheight"></div>');
        var HT = $('.chkheight').height();
        $('.chkheight').replaceWith($('.chkheight').contents());
        if (HT < 300) {
            HT = 290;
        }

        var calHT = 0;
        if (HT < 530) {
            calHT = 530 - HT
        }
        else {
            calHT = 30;
        }

        $('.listingBlocks').css({ paddingTop: calHT + "px" });

        //$('#mainCnt').find('p:first').css({ height: '360px' });

        var slider = "<div class='image_reel'>";
        for (b = 1; b <= def_imges.length; b++) {
            slider += "<img title='" + def_imgesTitle[(b - 1)] + "' src='" + def_imges[(b - 1)] + "' style='vertical-align:middle;border:0;' />";
        }
        slider += "</div>";
        var imagecount = def_imges.length;

        if (imagecount > 1) {
            slider += "<div class='paging'>";
            var count = 1;

            for (count = 1; count <= def_imges.length; count++) {

                slider += "<a href='#' rel=" + count + ">" + count + "</a>";
            }
            slider += "</div>";
        }


        $('#mainimage').append(slider);
        $(".paging").show();
        $(".paging a:first").addClass("active");
        var imageWidth = $("#mainimage").width();
        var imageSum = $(".image_reel img").size();
        var imageReelWidth = imageWidth * imageSum;
        $(".image_reel").css({ 'width': imageReelWidth });

        rotate = function() {
            var triggerID = $active.attr("rel") - 1;
            var image_reelPosition = triggerID * imageWidth;

            $(".paging a").removeClass('active');
            $active.addClass('active');

            $(".image_reel").animate({
                left: -image_reelPosition
            }, 500);

        };

        rotateSwitch = function() {
            play = setInterval(function() {
                $active = $('.paging a.active').next();
                if ($active.length === 0) {
                    $active = $('.paging a:first');
                }
                rotate();
            }, 7000);
        };

        rotateSwitch();


        /*$(".image_reel a").hover(function() {
        clearInterval(play); 
        }, function() {
        rotateSwitch();
        });	*/

        //On Click
        $(".paging a").click(function() {
            $active = $(this);

            clearInterval(play);
            rotate();
            rotateSwitch();
            return false;
        });

        $(".next").click(function() {
            $active = $('.paging a.active').next();
            if ($active.length === 0) {
                $active = $('.paging a:first');
            }
            clearInterval(play);
            rotate();
            rotateSwitch();
        })
    }
});

