﻿/* SALE/NEW ITEMS 
------------------------------------------------------------------------------------*/
function nextItem(id) {
	if($('#' + id + ' .active').next().length != 0)
	{
		$('#' + id +' .active')
			.removeClass('active')
			.next()
			.addClass('active');
		
		if($('#' + id + ' .active').next().length == 0)
		{
			$('#' + id + 'Next').attr('src','/images/button-stop.png');
		}
	}
	
	checkPrev(id);
}

function prevItem(id)
{
	if($('#' + id + ' .active').prev().length != 0)
	{
		$('#' + id +' .active').removeClass('active').prev().addClass('active');
		if($('#' + id + ' .active').prev().length == 0)
		{
			$('#' + id + 'Prev').attr('src','/images/button-stop.png');
		}
	}
	checkNext(id);
}

function checkNext(id)
{
	if($('#' + id + ' .active').next().length != 0 && $('#' + id + 'Next').attr('src') == '/images/button-stop.png' )
	{
		$('#' + id + 'Next').attr('src','/images/button-right.png');
	}
}

function checkPrev(id)
{
	if($('#' + id + ' .active').prev().length != 0 && $('#' + id + 'Prev').attr('src') == '/images/button-stop.png' )
	{
		$('#' + id + 'Prev').attr('src','/images/button-left.png');
	}
}

function checkBtn(id)
{
	if($('#' + id + ' .active').prev().length == 0)
	{
		$('#' + id + 'Prev').attr('src','/images/button-stop.png');
	}
	
	if($('#' + id + ' .active').next().length == 0)
	{
		$('#' + id + 'Next').attr('src','/images/button-stop.png');
	}
}

$(function(){
	checkBtn('newItem');
	checkBtn('saleItem');
});

/* GALLERY IMAGES
------------------------------------------------------------------------------------*/

$(function() {
	ShowPreview();
});

function ShowPreview() {
    var count = 0;
    $('.preview').each(function() {
            if( (((imageInd + 1) * countShow) > count) && ((imageInd * countShow) <= count))
                $(this).show();
            else
                $(this).hide();

            count++;  
    });

    CheckScreenBtn();
}

function NextPage() {
    if(imageInd < totalScreenPages)
        imageInd++;
    ShowPreview();
}

function PrevPage() {
    if(imageInd > 0)
        imageInd--;
        
    ShowPreview();
}

function CheckScreenBtn() {
    if(imageInd == 0)
        $('#upScreen')
            .attr('src', envPrefix + 'images/button-stop.png');
    else
        $('#upScreen')
            .attr('src', envPrefix + 'images/screenshot-arrow-up-normal.png');
   
   if(imageInd == totalScreenPages)
        $('#downScreen')
            .attr('src', envPrefix + 'images/button-stop.png');
    else
        $('#downScreen')
                .attr('src', envPrefix + 'images/screenshot-arrow-down-normal.png');
}

$(function() {
	$(".preview img").click(function() {			    
		if($(this).attr('flvSrc') != "")
		{
			var fileName = $(this).attr('flvSrc');
			$('#previewImage').css('display', 'none');
			$('#previewFlv').css('display', 'block');
			
			swfobject.embedSWF(envPrefix + 'flvPlayer/player.swf', "player", "337", "210", "9.0.0", "expressInstall.swf", {file : fileName, bufferlength : 5});
		}
		else
		{
			$('#player').html('');
			$('#previewImage').css('display', 'block');
			$('#previewFlv').css('display', 'none');
			$('#main-screenshot').attr('src', $(this).attr('bigImageSrc'));				   
		}
	});
	
	$('.preview img').eq(0).click();
});