<script type="text/javascript">
    $(document).ready(function(){
<?php
$delay = getSettingsValue('slideshow_delay');
if($delay > 0) {
    $delay = $delay * 1000;
    ?>
            setInterval("slideShow()", <?php echo $delay; ?>);
    <?php
}
?>           
    });


    function slideShow()
    {
        var current = $(".current");
        if($(".current").prev('.bannerSub').length == 0)
        {
            $("#banner_container .bannerSub").not("#banner_container .bannerSub:last").animate({opacity:0},1000);
            $("#banner_container .bannerSub:last").addClass("current").css({opacity:1});
        }else{
            $(".current").prev('.bannerSub').animate({opacity:1},1000, function(){
                $(this).addClass("current");
                current.removeClass("current");
            });
        }
    }
</script>
<?php

if(isset($_GET['featured'])) {
    $featured	= $_GET['featured'];
}
else {
    $featured	='Y';
}

$productListingFee = getSettingsValue('product_listing_fee');
if($featured == 'Y') {
    $sql="SELECT po.image_small,po.image_big,pd.product_id,po.product_option_id,po.product_stock,pd.product_name,(pd.product_price + po.additional_price) AS product_price,po.discount,ar.artist_id,
                    (SELECT pm.vimage_name FROM ".$tableprefix."product_view_images pm where pm.nimage_productid=pd.product_id LIMIT 0,1)AS smallimage
			  FROM ".$tableprefix."products pd
                          INNER JOIN ".$tableprefix."product_options po ON po.product_id = pd.product_id AND po.default_option = 'YES'
                          INNER JOIN ".$tableprefix."artists ar ON ar.artist_id = pd.product_artist_id
			  WHERE pd.product_artist_id=ar.artist_id AND pd.featured='Y' AND pd.vapproved='Y' 
			  AND ar.vapproved='Y' AND pd.deleted !='Y'  
                          AND ar.plan_expired='N' 
                          ";
    if($productListingFee > 0) {
        $sql .= " AND pd.payment_status='COMPLETED' ";
    }
    $sql .= "
                          ORDER BY pd.date_added  DESC";	

    $featured_image = "featured_items1.gif";
    $newitem_image = "new_items.gif";


}
else {


    $sql="SELECT po.image_small,po.image_big,pd.product_id,po.product_option_id,po.product_stock,pd.product_name,(pd.product_price + po.additional_price) AS product_price,po.discount,ar.artist_id,
        (SELECT pm.vimage_name FROM ".$tableprefix."product_view_images pm where pm.nimage_productid=pd.product_id LIMIT 0,1)AS smallimage
		      FROM ".$tableprefix."products pd
                      INNER JOIN ".$tableprefix."product_options po ON po.product_id = pd.product_id AND po.default_option = 'YES'
                      INNER JOIN ".$tableprefix."artists ar ON ar.artist_id = pd.product_artist_id
		      WHERE ar.vapproved='Y' AND pd.deleted !='Y' AND pd.vapproved='Y'  
                      AND ar.plan_expired='N'   ";
    if($productListingFee > 0) {
        $sql .= " AND pd.payment_status='COMPLETED' ";
    }
    $sql .= "  ORDER BY pd.date_added  DESC";


    $featured_image = "featured_items.gif";
    $newitem_image = "new_items_h.gif";
}



$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());						

$totalrows = mysql_num_rows(mysql_query($sql));

$cms_content = displayCMS('home_page');



?>	
<?php /*
<div class="bannertop">

<div align="left" id="banner">
<div id="cms_align" align="left">
					<h3 align="center"><?php echo $cms_content[0]?></h3>
					<p align="center"><?php echo stripslashes($cms_content[1]);?></p>
</div>

<!--<div  class="register"><a href="<?php echo SITE_URL?>/register.php"><img src= "<?php echo SITE_URL;?>/themes/<?php echo $active_template[5]?>/register.gif" ></a></div>-->
</div>


</div>
*/

$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);
?>
<?php if($_REQUEST['reg']=="1"){?><div style="color: green; font-weight: bold; float: left; width: 465px;"><div style="float:right"><?php echo REGISTER_SUC_MSG?></div></div><?php }?>
<div <?php if($bannerRow==0) { ?> class="bannertop" <?php  }  else { ?> style="height:337px;width:988px;" <?php } ?>>
    <div align="left" id="banner_container">
        <?php

        $cms_content = displayCMS('home_page');


        if(strlen($cms_content[1])>20)
			  $cms_body = substr($cms_content[1],0,20)."...";
			else
			   $cms_body = $cms_content[1];

        //echo $category_name;


        if(mysql_num_rows($resultBan) > 0) {
            $zindex = 100;
            while($bRow = mysql_fetch_object($resultBan)) {
                ?>
        <div style="z-index:<?php echo $zindex--; ?>;position:absolute;background-image: url('./homepagebanners/<?php echo $bRow->image;?>')" class="bannerSub">
            <!--banner area start -->
            <div align="left"  <?php if($bannerRow==0) { ?> id="banner" <?php  }  else { ?> style="float:left;height:337px;width:988px;" <?php } ?>>
                <div id="cms_align" align="right">

                    <div>
                        <p align="center"><?php echo $cms_content[0]?></p>
                        <p align="center"><?php echo $cms_content[1]?></p>
                    </div>

                </div>
            </div>
            <!--banner area end -->
        </div>
                <?php
            }
        }


         else
        {
        ?>

    <div id="cms_align" align="left">

					<div>
						<p align="center"><?php echo $cms_content[0]?></p>
						<p align="center"><?php echo $cms_content[1]?></p>
					</div>

				</div>

    <?php

    }


?>	

    </div>

</div>
<div class="featuredproduct_list">
    <h1>
        <?php if($featured=='Y') {
            echo FEATURED_PRODUCTS_TEXT ;
        }  else {
            echo NEW_PRODUCTS_TEXT;
        } ?>
    </h1>
    <?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["image_small"] !="") {
                $product_image = $row["image_small"];

            }  // end if product image null check
            elseif($row["image_big"] != "") {
                $product_image = $row["image_big"];
            }
            else
                {
                     $product_image=$row["smallimage"];
            }

       if($product_image=="") {
                $imageurl = $site_url."/".$prodimagedir."noimage.jpg";
            }
            else {
                if(strstr($product_image, "http://")) {
                    $imageurl = $product_image;
                }
                elseif(!is_file($prodimagedir.$product_image) && !file_exists($prodimagedir.$product_image)) {
                             $imageurl = $site_url."/".$prodimagedir."noimage.jpg";
                }
                else {
                    $imageurl = $site_url."/".$prodimagedir.$product_image;
                }
            }
        
             $imageurl = "<img class='product_img' src='".$imageurl."' border='0' >";
// Image Listing Modification End

            if(checkProductStock($row["product_id"]) > 0) {
                $productinstock = true;
            }
            else {
                $productinstock = false;
            }
            /*
				if(!empty($product_image))
				{ // Rename Image Thumb;
					$imgexp=explode(".",$product_image);
					
					$imagename=rtrim($product_image, strrchr($product_image, '.'));;
					//echo substr($product_image, strrpos($product_image, '.') +2 );
					$extension=substr($product_image, strrpos($product_image, '.') + 1);
					
					$imagename=$imagename."_thumb.".$extension;
					
				}  end thumb creation*/ 


            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="";


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

            }


            $display_product_price = number_format($converted_price,2,".","");
            // End Set Currency Value
            ?>
    <div class="products" <?php if($count_row==4) {?> style="margin-right:0px;"  <?php } ?>>
        <a href="<?php echo SITE_URL?>/productdetails.php?productid=<?php echo $row["product_id"]?>"><?php echo $imageurl?></a>
        <h5><a href="<?php echo SITE_URL?>/productdetails.php?productid=<?php echo $row["product_id"]?>" title="<?php echo $prd_name; ?>">
                        <?php
                        if(strlen($prd_name)>27) {
                            echo substr(ucwords(strtolower($prd_name)),0,27)."...";
                        } else {
                            echo ucwords(strtolower($prd_name));
                        }
                        ?>
            </a>
		</h5>
        <div class="product_price"><p> <?php if($discountprice!=0) { ?> <?php echo  $currency_attributes[0] ?> <?php echo $discountprice;?> (<strike><?php echo  $currency_attributes[0] ?> <?php echo $display_product_price;?> </strike>) <?php }  else { ?> <?php echo  $currency_attributes[0] ?> <?php echo $display_product_price;?> <?php } ?> </p></div>
                <?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>
            <?php
            if($count_row ==$cells) {
                $count_row = 1;
            }
            else {
                $count_row++;
            }
        }
        ?>
        <?php
    }
    else {

        ?>
    <div class="noproducts" >No Products Found.</div>

        <?php }  // end else
    ?>

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

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

<?php if($totalrows>$limit) {?>
<div  class="pagination"> <?php echo rightpaging();?></div>
    <?php  } ?>
