﻿
if(!Array.prototype.map) {
	Array.prototype.map = function(fun /*, thisp*/) {
		var len = this.length >>> 0;
		if(typeof fun != "function") throw new TypeError();
		var res = new Array(len), thisp = arguments[1];
		for(var i = 0; i < len; i++) {
			if(i in this) res[i] = fun.call(thisp, this[i], i, this);
		}
		return res;
	}
}

function show_menu_sub(obj){
	$(obj).addClass('cur_menu');
}
function hide_menu_sub(obj){
	$(obj).removeClass('cur_menu');
}

function show_carousel_txt(obj){
	if($(obj).parent().find('b').css('display') == 'inline'){
		$(obj).css('background', 'url(/templates/media/images/button_carousel_buy.png) left top no-repeat');
		$(obj).parent().find('b').css('display', 'none');
		$(obj).parent().find('.a').css('display', 'none');
	}else{
		$(obj).css('background', 'url(/templates/media/images/button_carousel_buy.png) left -30px no-repeat');
		$(obj).parent().find('b').css('display', 'inline');
		$(obj).parent().find('.a').css('display', 'inline');
	}
}

function show_block_read_more(obj){
	if($(obj).parent().find('.block_read_more').css('display') == 'block'){
		$(obj).parent().find('.block_read_more').css('display', 'none');
	}else{
		$(obj).parent().find('.block_read_more').css('display', 'block');
	}
}

function hide_block_read_more(obj){
	if($(obj).parent().css('display') == 'block'){
		$(obj).parent().css('display', 'none');
	}else{
		$(obj).parent().css('display', 'block');
	}
}
function show_block_g_bg(obj){
	$(obj).css('background', '#f3f4f5');
	$(obj).find('div').css('display', 'block');
	$(obj).find('a').css('color', '#ed1c24');
}
function hide_block_g_bg(obj){
	$(obj).css('background', 'none');
	$(obj).find('div').css('display', 'none');
	$(obj).find('a').css('color', '#666666');
}

function show_basket_layer(callback){
	$('#basket_txt').show('fast', function(){show_basket_layer.closed=false;if(callback && callback.apply) callback()});
	$('#button_basket a').css('background', 'url(/templates/media/images/button_basket.png) -24px top no-repeat');
	
}

function hide_basket_layer(callback){
	if(!show_basket_layer.closed) {
		$('#basket_txt').hide('fast', function(){show_basket_layer.closed=true;if(callback && callback.apply) callback()});
		$('#button_basket a').css('background', 'url(/templates/media/images/button_basket.png) left top no-repeat');
	}
}

function show_comparison_layer(callback){
	$('#comparison_txt').show('fast', function(){show_comparison_layer.closed=false;if(callback && callback.apply) callback()});
	$('#button_comparison a').css('background', 'url(/templates/media/images/button_comparison.png) left top no-repeat');
}

function hide_comparison_layer(callback){
	if(!show_comparison_layer.closed) {
		$('#comparison_txt').hide('fast', function(){show_comparison_layer.closed=true;if(callback && callback.apply) callback()});
		$('#button_comparison a').css('background', 'url(/templates/media/images/button_comparison.png) -24px top no-repeat');
	}
}

function show_popup_enter(obj){
	if($('.popup_enter').css('display') == 'none'){
		$('.popup_enter').css('display', 'block');
	}else{
		$('.popup_enter').css('display', 'none');
	}
}
function hide_popup_enter(obj){
	$('.popup_enter').css('display', 'none');
}

function show_add_question(obj){
	if($('.add_question').css('display') == 'none'){
	$('.add_report_error').css('display', 'none');
		$('.add_question').css('display', 'block');
	}else{
		$('.add_question').css('display', 'none');
	}
}
function hide_add_question(obj){
	$('.add_question').css('display', 'none');
}

function show_add_report_error(obj){
	if($('.add_report_error').css('display') == 'none'){
		$('.add_question').css('display', 'none');
		$('.add_report_error').css('display', 'block');
	}else{
		$('.add_report_error').css('display', 'none');
	}
}
function hide_add_report_error(obj){
	$('.add_report_error').css('display', 'none');
}

function show_txt_description(obj){
	$('#txt_options').css('display', 'none');
	$('#txt_description').css('display', 'block');
	$('#txt_comment').css('display', 'none');
	$(obj).css('background', 'url(/templates/media/images/button_description2.gif) left -26px no-repeat');
	$('.button_options').css('background', 'url(/templates/media/images/button_options.gif) left top no-repeat');
	$('.button_comment').css('background', 'url(/templates/media/images/button_comment.gif) left top no-repeat');
}
function show_txt_options(obj){
	$('#txt_description').css('display', 'none');
	$('#txt_options').css('display', 'block');
	$('#txt_comment').css('display', 'none');
	$('.button_description2').css('background', 'url(/templates/media/images/button_description2.gif) left top no-repeat');
	$(obj).css('background', 'url(/templates/media/images/button_options.gif) left -26px no-repeat');
	$('.button_comment').css('background', 'url(/templates/media/images/button_comment.gif) left top no-repeat');
}
function show_txt_comment(obj){
	$('#txt_description').css('display', 'none');
	$('#txt_options').css('display', 'none');
	$('#txt_comment').css('display', 'block');
	$('.button_description2').css('background', 'url(/templates/media/images/button_description2.gif) left top no-repeat');
	$('.button_options').css('background', 'url(/templates/media/images/button_options.gif) left top no-repeat');
	$(obj).css('background', 'url(/templates/media/images/button_comment.gif) left -26px no-repeat');
}


function show_specifications(id, obj){
	return false;
	$(obj).css('background', '#f2f3f5');
	$('.item').parent().find('#item_specifications_'+id).css('display', 'block');
}
function hide_specifications(id, obj){
	return false;
	$(obj).css('background', '#ffffff');
	$('.item').parent().find('#item_specifications_'+id).css('display', 'none');
}


function show_block(obj){
	if($(obj).parent().find('.block').css('display') == 'none'){
		$(obj).parent().find('.block').css('display', 'block');
		$(obj).parent().find('.arrow').css('background', 'url(/templates/media/images/arrow_blue_top.gif) left top no-repeat');
	}else{
		$(obj).parent().find('.block').css('display', 'none');
		$(obj).parent().find('.arrow').css('background', 'url(/templates/media/images/arrow_blue_bottom.gif) left top no-repeat');
	}
}

jQuery.preloadImages = function(){
	for(var i = 0; i<arguments.length; i++){
		jQuery("<img>").attr("src", arguments[i]);
	}
};
$.preloadImages("/templates/media/images/more_info_bottom_bg.png", "/templates/media/images/more_info_bg.gif");

function show_more_info(){
	$('#more_info').slideDown(300);
	show_shadow();
}
function hide_more_info(){
	$('#more_info').slideUp(300);
	hide_shadow();
}

/*shadow*/

function getPageScroll(){
    var yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
    }
    arrayPageScroll = new Array('',yScroll) 
    return arrayPageScroll;
}
function getPageSize(){
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {  
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) { // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }   
    
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){  
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}

function show_gallery(link){
	$('#gallery2 .gallery_images_little a').map(function(i, e){
		e = $(e);
		if(e.attr('rel')==$(link).attr('rel')) {
			e.click();
		}
	})
	document.getElementById('gallery2').style.display = 'block';
	show_shadow();
}
function hide_gallery(){
	document.getElementById('gallery2').style.display = 'none';
	hide_shadow();
}

function show_gallery2(link){
	$('#gallery_images_big img').attr({src:$(link).attr('href')});
	$('#gallery3 h2').html($(link).attr('title'));
	$('#gallery3 .gallery_images_little a').map(function(i, e){
		e = $(e);
		if(e.attr('rel')==$(link).attr('rel')) {
			e.click();
		}
	});
	document.getElementById('gallery3').style.display = 'block';
	show_shadow();
}
function hide_gallery2(){
	document.getElementById('gallery3').style.display = 'none';
	hide_shadow();
}

function show_span(obj){
	$(obj).find('span').css('display', 'block');
}
function hide_span(obj){
	$(obj).find('span').css('display', 'none');
}

function show_shadow(){
    var objOverlay = document.getElementById('overlay');
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();

    objOverlay.style.height = (arrayPageSize[1] + 'px');
    objOverlay.style.display = 'block';
}
function hide_shadow(){
    objOverlay = document.getElementById('overlay');
    objOverlay.style.display = 'none';
}
