<script type="text/javascript">
    $(document).ready(function(){
        var delay
    
<?php
$delay = getSettingsValue('slideshow_delay');
if ($delay > 0) {
    $delay = $delay * 1000;
    ?>
                delay = '<?php echo intval($delay); ?>';
                $('.carousel').carousel({
                interval: delay?delay:2000
                })
                   
    <?php
}
?>
         
      $('.prod_green').click(function(){
         //var pid=$(this).attr('id');          
         //window.location = "<?php echo SITE_URL ?>/productdetails.php?productid="+pid;
         var OptimizedUrl=$(this).attr('data');          
         window.location = OptimizedUrl;
        });
     
    });


   
</script>
<?php
if (isset($_GET['featured'])) {
    $featured = ($_GET['featured'] == 'Y') ? 'Y' : 'N';
} else {
    $featured = 'Y';
}
$currency_attributes = displayCurrencyType();
//***************************Product Listing  Modifications for Scalability **********************
$orderBy    =   " product_id DESC";
$sql        = Products::getProduct_list_Query($featured,$orderBy);

//***************************Product Listing  Modifications for Scalability End**********************
$prodimagedir = "products/";
$page = $_GET['page'];

if (empty($page)) {
    $page = 1;
}

$limit = getPaginationLimit();

if ($limit == 0) {
    $limit = 12;
}
$sql_qr = dopaging($sql, '', $limit);
$result = mysql_query($sql_qr) or die(mysql_error());

$productCountQuery      =   Products::getProduct_list_QueryCount($featured);
$resultRow              =   mysql_query($productCountQuery);   
$totalrows              =   mysql_result($resultRow,0,"productCount");
$cms_content = displayCMS('home_page');
?>	
<?php
    //Fetching Home page banners
$sql = " SELECT * FROM " . $tableprefix . "homepagebanners
         WHERE deleted = 'N'
         order by homepage_banner_id ASC ";
$resultBan = mysql_query($sql) or die(mysql_error());
$bannerRow = mysql_num_rows($resultBan);
$imagesArray    =   array();
$cnt=0;
while ($imageObj = mysql_fetch_object($resultBan)) {
  //  echo  $imageObj->image;
    $imagesArray[$cnt]['image_name'] = $imageObj->image;
    $imagesArray[$cnt]['link'] = $imageObj->link;
    $cnt++;
}
?>
<!--<script src="js/carousel.js"></script>-->
<div class="banner_sec">
    <div class="banner">	
            <!--<img src="<?php echo SITE_URL ?>/images/banner_slide1.jpg">-->

        <div id="myCarousel" class="carousel slide" data-ride="carousel"> 
            <!-- Indicators -->
            <ol class="carousel-indicators">
                <?php
                $loopVar = 0;
                foreach ($imagesArray as $image) {
                    
                    ?>
                    <li data-target="#myCarousel" data-slide-to="<?php echo $loopVar ?>" class="<?php echo $loopVar == 0 ? 'active' : '' ?>"></li>

                    <?php
                    $loopVar++;
                }
                ?>
            </ol>
            <div class="carousel-inner">
                <?php
                $loopVar = 0;
                foreach ($imagesArray as $image) {
                    
                      $bannerLink = '';
                    //echopre($image);
                    if($image['link']!='')
                        {
                            $bannerLink     =    generalMethods::addhttp($image['link']);
                      }else{
                             $bannerLink       =   'categorydetail.php';
                      }
                  if(ENABLE_AMAZON_S3_IMAGES == "Y"){  
                    $homeBanner = AMAZON_S3_DOMAIN_URL."homepagebanners/". $image['image_name'] ;

                    }
                    else   { $homeBanner =  SITE_URL . "/homepagebanners/". $image['image_name']; }

                    ?>
                    <div class="item <?php echo $loopVar == 0 ? 'active' : '' ?>"> <a href="<?php echo $bannerLink;?>" target="_blank" alt="<?php echo $bannerLink;?>" title="<?php echo $bannerLink;?>"><img src="<?php echo $homeBanner ?>" style="width:100%" alt="First slide"></a>
                        <div class="container">
                            <?php /*<div class="carousel-caption">
                                <?php if(trim($cms_content[0])!=''){?>
                                <h1><?php echo $cms_content[0]?></h1>
                                <?php }?>
                                <p><?php echo $cms_content[1]?></p>
                                <p><a class="btn btn-lg btn-primary" href="register.php" role="button">Sign up today</a></p>
                            </div>*/?>
                        </div>
                    </div>
                    <?php
                    $loopVar++;
                }
                ?>

            </div>
            <a class="left carousel-control" href="#myCarousel" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a> <a class="right carousel-control" href="#myCarousel" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a> 
        </div>

    </div>
</div>


<div class="clear"></div>
<div class="success">
    <div class="container">
        <div class="row">
<?php if ($_REQUEST['reg'] == "1") { ?><div class="thanku_msg"><div><?php echo REGISTER_SUC_MSG ?></div></div><?php } ?>
        </div>
    </div>
</div>
<!-- .Welcome Note Start -->
<div class="welcomenote">
    <div class="container">
        <div class="row">
            <div class="col-sm-12 col-lg-12 col-md-12">                
                <?php if(trim($cms_content[0])!=''){?>                
                <h3><?php echo $cms_content[0]?></h3>
                <?php }?>
               <p><?php echo $cms_content[1]?></p>
            </div>
        </div>
    </div>
</div>
<!-- /.Welcome Note End -->
</div>
<div class="clear"></div>
<div class="featuredproduct_list">
    <div class="container">
        <div class="row">
            <div class="col-sm-12 col-lg-12 col-md-12 ">
                <h1>
                    <?php
                    if ($featured == 'Y') {
                        echo FEATURED_PRODUCTS_TEXT;
                    } else {
                        echo NEW_PRODUCTS_TEXT;
                    }
                    ?>
                </h1>
            </div>
            <?php
            if ($totalrows > 0) {
                $i = 1;
                $cells = 4;
                $count_row = 1;
                while ($row = mysql_fetch_array($result)) {
                    $product_image = "";
                    // Image Selection Modification // Done By Asha
                    $imageurl = '';
                    if ($row["default_image_small"]!= "") {
                        $product_image = $row["default_image_small"];
                    }  // end if product image null check
                   
                    
                
                    if ($product_image == "") {
                        $imageurl = SITE_URL . "/" . $prodimagedir . "noimage.jpg";
                    } else {
                        if (strstr($product_image, "http://") || strstr($product_image, "https://")) {
                            $imageurl = $product_image;
                        }  else {
                              if(ENABLE_AMAZON_S3_IMAGES=="Y"){ 
                                 $imageurl = AMAZON_S3_DOMAIN_URL.$prodimagedir.$product_image;    
                             }else{
                                 $imageurl = SITE_URL . "/" . $prodimagedir . $product_image;
                             }
                        }
                    }
                    
                    $imageurl = "<img class='product_img' src='" . $imageurl . "' border='0' >";
            

// Image Listing Modification End

                    if ($row["default_stock"] > 0) {
                        $productinstock = true;
                    } else {
                        $productinstock = false;
                    }
                 
                /********************Multicart 3.0 Modifications******************************************/
                    $SEOFriendlyLink = getOptimisedLink(SITE_URL, $row["product_category"], $row["alias"]);

                    $subscriptionFlag   =    Products::is_subscription_product($row["product_id"]);
                   
                 /********************Multicart 3.0 Modifications End ******************************************/
                    $prd_full_name = stripslashes($row["product_name"]);
                    if (strlen($row["product_name"]) > 30) {
                        $prd_name = stripslashes(substr($row["product_name"], 0, 30));
                    } else {
                        $prd_name = stripslashes($row["product_name"]);
                    }

                    $price = $row['product_price'];

                    $discountstr = "";


                    
                    $conversionRate = ConvertedCurrencyRate($currency_attributes[2]);
                    $converted_price = $price * $conversionRate;
                    $discountprice = 0;
                    if ($row["default_discount"] != "0") {
                        $discountprice = $converted_price - ($converted_price * $row["default_discount"]) / 100;
                        $discountprice = number_format($discountprice, 2, ".", "");
                        $discountstr = "<br>" . strtolower(MAIL_ORDER_TEXT_DISCOUNT) . "(" . $row["default_discount"] . "%)";
                    }

                    $display_product_price = number_format($converted_price, 2, ".", "");
                    // End Set Currency Value
                    ?>
                    <div class="col-sm-12 col-lg-4 col-md-4">
                        <div class="products" <?php if ($count_row == 4) { ?> style="margin-right:0px;"  <?php } ?>>
                            
                            <?php /*echo SITE_URL ?>/productdetails.php?productid=<?php echo $row["product_id"]*/ ?>
                            <a class="product_anchor" data="<?php echo $row["product_id"] ?>" href="<?php echo $SEOFriendlyLink; ?>">
                                <div class="imgblock">
        <?php echo $imageurl ?>
                                </div>
                            </a>

                            <!--GreenOver-->
                            <div class="prod_green" id="<?php echo $row["product_id"] ?>" data="<?php echo $SEOFriendlyLink; ?>" >
                                <div class="prodover_blk">
                                    <?php
                                    if ($productinstock) {
                                        ?>
                                    <?php
                                    // Hide Shop now Button for Subscription Items
                                     if(!$subscriptionFlag) { ?>
                                   
                                        <div class="prodover_blk_row">
                                            <div class="adtocart_tbn_blk cart_btn_home">
                                                <a class="adtocart" href="<?php echo SITE_URL ?>/homepage_addtocart.php?productid=<?php echo $row["product_id"] ?>&product_option_id=<?php echo $row["default_option_id"] ?>" class="add_cart_small"> <?php echo ADD_TO_CART_TEXT; ?> </a>
                                                <div class="clear"></div>  
                                            </div>
                                        </div>
                                    <?php } ?>
                                        <div class="clear"></div>
                                        <?php
                                    } else {
                                        ?>
                                        <div class="prodover_blk_row">
                                            <div class="adtocart_tbn_blk cart_btn_home"><img src="<?php echo SITE_URL ?>/images/home_outfstock.gif"  alt="<?php echo OUT_STOCK_TEXT;?>" border="0"/></div>
                                            <div class="clear"></div>  
                                        </div>
                                        <div class="clear"></div>
                                        <?php
                                    }
                                    ?>
                                </div>
                            </div>
                            <!--GreenOver:End-->

                            <h5><a href="<?php echo $SEOFriendlyLink; ?>" title="<?php echo $prd_full_name; ?>">
                                    <?php
                                    if (strlen($prd_name) > 24) {
                                        echo substr($prd_name, 0, 24) . "...";
                                    } else {
                                        echo $prd_name;
                                    }
                                    ?>
                                </a>
                            </h5>
                            <div class="product_price"><p> <?php if ($discountprice != 0) { ?> <?php echo $currency_attributes[0] ?> <?php echo $discountprice; ?> <span>(<strike><?php echo $currency_attributes[0] ?> <?php echo $display_product_price; ?> </strike>)</span> <?php } else { ?> <?php echo $currency_attributes[0] ?> <?php echo $display_product_price; ?> <?php } ?> </p></div>

                            <?php /*

                              <?php
                              if($productinstock) {
                              ?>

                              <div class="adtocart_tbn">
                              <a class="adtocart" href="<?php echo SITE_URL?>/homepage_addtocart.php?productid=<?php echo $row["product_id"]?>&product_option_id=<?php echo $row["product_option_id"]?>" class="add_cart_small"><?php echo ADD_TO_CART_TEXT; ?></a>
                              <a class="more_btn" href="<?php echo SITE_URL?>/productdetails.php?productid=<?php echo $row["product_id"]?>" class="more_btn"><?php echo MORE_TEXT; ?></a>
                              <div class="clear"></div>
                              </div>
                              <?php
                              }
                              else {

                              ?>
                              <div class="adtocart_tbn" align="left"><img src="<?php echo SITE_URL?>/images/home_outfstock.gif"  alt="Out of Stock" border="0"/></div>
                              <?php

                              }
                              ?>
                             */ ?>
                            <div class="clear"></div>
                        </div>
                    </div>
                    <?php
                    if ($count_row == $cells) {
                        $count_row = 1;
                    } else {
                        $count_row++;
                    }
                }
                ?>
                <?php
            } else {
                ?>
                <div class="col-sm-12 col-lg-12 col-md-12">
                    <div class="noproducts" ><?php echo NO_PRODUCT_FOUND_TEXT;?></div>
                </div>
<?php }  // end else
?>

            <input type="hidden" value="<?php echo $featured; ?>" name="featured">

            <div class="clear"></div>
        </div>

<?php if ($totalrows > $limit) { ?>
            <div class="col-sm-12 col-lg-12 col-md-12">
                <div  class="pagination"> <?php echo rightpaging(); ?></div>
            </div>
<?php } ?>

    </div>
</div>