/* @version $Id: v 0.1 07.07.2010 - 16:12:31 Exp $
 *
 * Project:     stream-of-time
 * File:        jslib.js *
 *
 * This library is commercial distributed software; you can't
 * redistribute it and/or modify it without owner (or author) approval.
 *
 * @link http://bestartdesign.com
 * @copyright (C) 2009
 *
 * @author Seyar Chapuh <seyarchapuh@gmail.com>, <sc@bestitsolutions.biz>
 */
Chimera = {}
$(function(){
    $("a.gallery").fancybox({'hideOnContentClick': true});
})


var countMainImages = 0;
function changeMainImg(speed)
{
    var next = 0;
    var current = parseInt($('#mainImages img').index( $('#mainImages img.visible') ));

    if( current < countMainImages-1 )
        next = $('#mainImages img').index( $('#mainImages img.visible').next() );

    $('#mainImages img').eq(next).css({left:0, display:'none'});
    $('#mainImages img').eq(current).fadeOut(speed);
    $('#mainImages img').eq(next).css({left:0, display:'none'}).fadeIn(speed);
    $('#mainImages img').removeClass('visible');
    $('#mainImages img').eq(next).addClass('visible');

}
function checkbox_click(thisObj)
{
    var src = $(thisObj).children('img').attr('src');
    $(thisObj).children('img').attr('src', $(thisObj).children('img').attr('rel') );
    $(thisObj).children('img').attr('rel', src);
    $inp = $(thisObj).prev();


    if( src.indexOf('nochecked') != -1 )
    {
        $inp.val('1');
        if(document.getElementById('ur'))
        document.getElementById('ur').style.display='';
    }else{
        $inp.val('0');
        if(document.getElementById('ur'))
        document.getElementById('ur').style.display='none';
    }
}

function radio_click(thisObj, input)
{
    var objclass = $(thisObj).attr('class');
    $(input).val($(thisObj).attr('href'));
    $('.'+objclass).each(function()
    {
        if( $(this).children('img').attr('src').indexOf('nochecked') == -1 )
        {
            var src = $(this).children('img').attr('src');
            $(this).children('img').attr('src', $(this).children('img').attr('rel') );
            $(this).children('img').attr('rel', src);
        }
    });

    if( $(thisObj).children('img').attr('src').indexOf('nochecked') != -1 )
    {
        var src = $(thisObj).children('img').attr('src');
        $(thisObj).children('img').attr('src', $(thisObj).children('img').attr('rel') );
        $(thisObj).children('img').attr('rel', src);
    }
}

$(document).ready(function(){
    countMainImages = $('#mainImages img').length;

    var speed = 2000;
    $('#mainImages img').eq(0).css({left:0, display:'none'}).addClass('visible').fadeIn(speed);
    setInterval('changeMainImg('+speed+')', 5000);

    $('.custom').SelectCustomizer();
});

function myAlert( text, type )
{
    $('#message').show();
    $('#message').html('<div class="message "><div class="message_l flLeft"></div><div class="message_c flLeft">'
            +text+'</div><div class="message_r flLeft"></div><div class="clear"></div>').slideDown('fast');

    $('#message .message').addClass(type);
    if( document.documentElement.scrollTop != 0 )
        $('#message').css('top', 40+document.documentElement.scrollTop+'px');


    setTimeout( function(){
		$('#message').slideUp('fast',
			function(){ $('#message').hide(); }
		);
	} , 7000 );
}

function sort()
{
    $("#sort_asc").val($('#sample3_options').find(".selectedclass").attr('alt'));
    $('#filterForm').submit();
}

var animated = 0;
function advice_prev()
{
    if( animated == 0 )
    {
        animated = 1;
        num = $('.otherGoodsInner .otherGood').length;
        var div = $('.otherGoodsInner .otherGood').eq(num-1);
        $('.otherGoodsInner').animate(
          {marginLeft: '0px'},
          400,
          'swing',
          function() {
            $('.otherGoodsInner').prepend( div );
            $('.otherGoodsInner').css('marginLeft', '0px');
            animated = 0;
          });
    }
//    $('.advice_inner .advice').eq(0).remove();
}

function advice_next()
{
   if( animated == 0 )
   {
       animated = 1;
       var div = $('.otherGoodsInner .otherGood').eq(0);
       $('.otherGoodsInner').animate({
            marginLeft: '-160px'
          }, 400, 'swing', function() {
            $('.otherGoodsInner').css('marginLeft', '0px');
            $('.otherGoodsInner').append( div );
            animated = 0;
          });
   }
}

var animated2 = 0;
function good_img_prev()
{
    if( animated2 == 0 )
    {
        animated2 = 1;
        num = $('.goodInnerThumbs .goodInnerThumb').length;
        var div = $('.goodInnerThumbs .goodInnerThumb').eq(num-1);
        $('.goodInnerThumbs').animate(
          {marginLeft: '0px'},
          400,
          'swing',
          function() {
            $('.goodInnerThumbs').prepend( div );
            $('.goodInnerThumbs').css('marginLeft', '0px');
            animated2 = 0;
          });
    }
//    $('.advice_inner .advice').eq(0).remove();
}

function good_img_next()
{
   if( animated2 == 0 )
   {
       animated2 = 1;
       var div = $('.goodInnerThumbs .goodInnerThumb').eq(0);
       $('.goodInnerThumbs').animate({
            marginLeft: '0'
          }, 400, 'swing', function() {
            $('.goodInnerThumbs').css('marginLeft', '0px');
            $('.goodInnerThumbs').append( div );
            animated2 = 0;
          });
   }
}

//��������� ������ ������
$(document).ready(function(){

	if (($.cookie('stat')!='dol') & ($.cookie('stat')!='grn')) {
		//alert('1');
		//$.cookie('stat','grn');
	}

	$(".id_dol").click(function () {

	  $(".kurs").toggle();

	  $(".goodStatus").toggle();

	  //$(".kurs_grn").hide();

	  //$(".goodStatus img").css({'src','{$template_root}images/dol.png'});

	  //alert($(this).attr('rel'));
	  //$(this).attr('rel')
	  $.cookie('stat', $(this).attr('rel'));


	  return false;
    });



});

