/*
#############################################
#  -----------Copyright (c) 2011, Andrey Ignatyev/Андрей Игнатьев (rich)----  #
#  ----------------------------------------------------------------------------------------------  #
#  Программа защищена от копирования вышеизложенным текстом,-----  #
#  использование программы бесплатное. При копировании должно-----  #
#  сохраниться определение автора, изложенное выше.-----------------------  #
#  ----------------------------------------------------------------------------------------------  #
#  Копирование и использование программы без указания владельца----  #
#  ПРИСЛЕДУЕТСЯ ПО ЗАКОНУ -----------------------------------------------------  #
#############################################
*/ 

$(document).ready(function(){
	$('<div class="opacity_window" align="center" onclick="_close(); return false;"></div>').appendTo('body');
});
function open_rich_window(brand, product, price_old, price_new, val_5, id){
//Определение переменных
var setting=({
	colorWindow: 'gray',
	closeWindow: '/images/close.png',
	nextWindow: '/images/next.png',
	prevWindow: '/images/prev.png',
	loadingWindow: '/images/loading.gif',
});
if (price_new==0){
	price=price_old;
}
else{
	price=price_new;
}
//Опеределение событий
$('div.opacity_window').css({
	'background-color':setting.colorWindow,
	'width':'100%',
	'height':'100%',
	'opacity':'0.9',
	'position':'fixed',
	'left':'0',
	'top':'0',
	'display':'block'
});
$('div.opacity_window').after('<div class="toggle_window"></div>');
$('div.toggle_window').append('<div class="load_window"><img src="'+setting.loadingWindow+'" /></div>');
$('div.load_window').css({
	'top':'40%',
	'left':'50%',
	'display':'none',
	'position':'absolute'
});
$('div.toggle_window').css({
	'background-color':'#ffffff',
	'top':'5%',
	'left':'25%',
	'right':'65%',
	'bottom':'75%',
	'position':'fixed',
	'overflow':'auto'
});
$('div.toggle_window').show(100, function(){
		$('div.load_window').css({
			'display':'block'
		});
		}).animate({
			minWidth:'700px',
		}, 1000).animate({height:'610px',}, 1000).show(500, function (){
		$.ajax({
		type: 'GET',
		url: '/includes/show_product.php',
		cache: false,
		data: 'brand='+brand+'&product='+product+'&price='+price,
		success: function(html){
			$('div.toggle_window').show(500, function(){
				$('div.toggle_window').append('<div class="list_product"><div class="prev_window" onclick="list_window(\''+brand+'\', '+id+', \'prev\')"></div><div class="next_window" onclick="list_window(\''+brand+'\', '+id+', \'next\')"></div></div>');
				$('div.toggle_window').append('<div class="description"></div><div class="close" onclick="_close()"><img id="close" style="width:25px; float: right" src="'+setting.closeWindow+'" /></div>');
				$('div.list_product').css({
					'position':'absolute',
					'bottom':'0',
					'width':'100%',
					'height':'90px'
				});
				$('div.prev_window').css({
					'background-image':'url('+setting.prevWindow+')',
					'background-repeat':'no-repeat',
					'background-position':'right center',
					'width':'50%',
					'height':'100%',
					'float':'left',
					'opacity':'0.6'
				});
				$('div.next_window').css({
					'background-image':'url('+setting.nextWindow+')',
					'background-repeat':'no-repeat',
					'background-position':'left center',
					'width':'50%',
					'height':'100%',
					'float':'left',
					'opacity':'0.6'
				});
				$('img#close').css({
					'opacity':'0.6'
				});
				$('div.close').css({
					'top':'0',
					'right':'0',
					'width':'100px',
					'position':'absolute',
					'float':'right',
					'height':'100px'
				});
				$('div.load_window').css({
					'display':'none'
				});
				$('div.prev_window').mouseover(function(){
					$('div.prev_window').css({'opacity':'1.0'});
				}).mouseout(function(){
					$('div.prev_window').css({'opacity':'0.6'});
				});
				$('div.next_window').mouseover(function(){
					$('div.next_window').css({'opacity':'1.0'});
				}).mouseout(function(){
					$('div.next_window').css({'opacity':'0.6'});
				});
				$('div.close').mouseover(function(){
					$('div.close img').css({'opacity':'1.0'});
				}).mouseout(function(){
					$('div.close img').css({'opacity':'0.6'});
				});
			});
			$("div.description").html(html);
		}
	});
})
}

function list_window(brand, id, list){
	var setting=({
		colorWindow: 'gray',
		closeWindow: '/images/close.png',
		nextWindow: '/images/next.png',
		prevWindow: '/images/prev.png',
	});
	if (list=='next'){
		var id=id+1;
		$.ajax({
			type: 'GET',
			url: '/includes/show_product.php',
			cache: false,
			data: 'brand='+brand+'&id='+id,
			success: function(html){
			$('div.description').html(html);
			}
		});
		$('div.list_product').replaceWith('<div class="list_product"><div class="prev_window" onclick="list_window(\''+brand+'\', '+id+', \'prev\')"></div><div class="next_window" onclick="list_window(\''+brand+'\', '+id+', \'next\')"></div></div>');
		$('div.list_product').css({
			'position':'absolute',
			'bottom':'0',
			'width':'100%',
			'height':'90px'
		});
		$('div.prev_window').css({
			'background-image':'url('+setting.prevWindow+')',
			'background-repeat':'no-repeat',
			'background-position':'right center',
			'width':'50%',
			'height':'100%',
			'float':'left',
			'opacity':'0.6'
		});
		$('div.next_window').css({
			'background-image':'url('+setting.nextWindow+')',
			'background-repeat':'no-repeat',
			'background-position':'left center',
			'width':'50%',
			'height':'100%',
			'float':'right',
			'opacity':'0.6'
		});
		$('div.prev_window').mouseover(function(){
			$('div.prev_window').css({'opacity':'1.0'});
		}).mouseout(function(){
			$('div.prev_window').css({'opacity':'0.6'});
		});
		$('div.next_window').mouseover(function(){
			$('div.next_window').css({'opacity':'1.0'});
		}).mouseout(function(){
			$('div.next_window').css({'opacity':'0.6'});
		});
	}
	else{
		var id=id-1;
		$.ajax({
			type: 'GET',
			url: '/includes/show_product.php',
			cache: false,
			data: 'brand='+brand+'&id='+id,
			success: function(html){
				$('div.description').html(html);
			}
		});
		$('div.list_product').replaceWith('<div class="list_product"><div class="prev_window" onclick="list_window(\''+brand+'\', '+id+', \'prev\')"></div><div class="next_window" onclick="list_window(\''+brand+'\', '+id+', \'next\')"></div></div>');
		$('div.list_product').css({
			'position':'absolute',
			'bottom':'0',
			'width':'100%',
			'height':'90px'
		});
		$('div.prev_window').css({
			'background-image':'url('+setting.prevWindow+')',
			'background-repeat':'no-repeat',
			'background-position':'right center',
			'width':'50%',
			'height':'100%',
			'float':'left',
			'opacity':'0.6'
		});
		$('div.next_window').css({
			'background-image':'url('+setting.nextWindow+')',
			'background-repeat':'no-repeat',
			'background-position':'left center',
			'width':'50%',
			'height':'100%',
			'float':'right',
			'opacity':'0.6'
		});
		$('div.prev_window').mouseover(function(){
			$('div.prev_window').css({'opacity':'1.0'});
		}).mouseout(function(){
			$('div.prev_window').css({'opacity':'0.6'});
		});
		$('div.next_window').mouseover(function(){
			$('div.next_window').css({'opacity':'1.0'});
		}).mouseout(function(){
			$('div.next_window').css({'opacity':'0.6'});
		});
	}
}

function _close(){
$('div.toggle_window').fadeOut(500, function(){
	$('div.opacity_window').css({
		'background-color':'gray',
		'width':'100%',
		'height':'100%',
		'opacity':'0.9',
		'position':'fixed',
		'left':'0',
		'top':'0',
		'display':'none',
		'overflow':'scrool'
	});
	$('div.toggle_window').remove('div.toggle_window');
});
}
