var oGoogleMaps;

$(document).ready( function() {
	
		fPreparePrintProductData();
	
		$('#txtDrukujKarteProduktu').click(printProductData);
		
		if($('.pojRatingDisabled').length){
				$('.ratingMessage').css('display', 'block');
		}
		
		bRated = false;
		
		$('.pojRatingEnabled .one-star, .pojRatingEnabled .two-stars, .pojRatingEnabled .three-stars, .pojRatingEnabled .four-stars, .pojRatingEnabled .five-stars ').click(function(){
			
			if(bRated)
				return false;
			
			bRated = true;
			
			$('.pojRating').addClass('pojRatingDisabled');
			$('.pojRating').removeClass('pojRatingEnabled');
			
			iScore = $(this).text();
			
			sUrl = 'index.php?sModul=mProductsXML&sAction=setRankingForProduct&iProductId='+iProductTheirId+'&iScore='+iScore+'&iPreviousScore='+iProductScore;
		
			$.ajax({
					type: 'GET',
					url: sUrl,
					dataType : 'xml',
					success: function(oXml){				
							
							var iStatus = $(oXml).find('iStatus').text();
							
							if (iStatus == 1){
								
									$('.ratingMessage').css('display', 'block');			
									$(".rate").html(iScore);
									if(iNewRank = $(oXml).find('iNewRank').text()){
											$('#pojProdDesc .pojRating .current-rating').css('width',iNewRank/5*100+'%');
									}
									
									$.cookie('aRankedProductsTheirIds['+iProductTheirId+']', iScore, { expires: 1 });
								
							}
					}
			});
			
		}
		);

		
		$('#pojTabs').tabs({
			show : function(event, ui) {
			// uruchomienie google maps
				
				if ( $(ui.panel).hasClass('googlemaps') && $("script[src^='http://maps.google.com']").size() ){
						
					Load();
					
				} // hasClass('googlemaps')
			}
			//select : function(event, ui) { alert('test') }
		});
		
		//Load();
	
		    $('#pojProdImgSlide')
		    .after('<div id="nav"">') 
		    .cycle({
				fx: 'fade',
				pager:  '#nav' 
			});
	
		
});


//function to resize the flash container for 3D models in product page.
function fSetFlashHeight(iHeight) {
	$('#poj3DPresentationContainer').css('height', iHeight + 'px');
	$('#poj3DPresentationContainer').css('padding', '40px 0px 20px 17px');
}


//funkcja inicjująca mapę w pozycji startowej
function Load(){
	if(GBrowserIsCompatible())  
	{
		mapa = new GMap2(document.getElementById("pojMap"));
		switch (sLang) {
		case 'ie':
		case 'uk':
			mapa.setCenter(new GLatLng(53.238921,-1.461182), 5);
			break;
		case 'cz':
			mapa.setCenter(new GLatLng(49.88756, 15.43579), 6);
			break;
		default:
			mapa.setCenter(new GLatLng(51.929805, 18.537883), 5);  
		}		
	}	
}
function printProductData() {
	
	fPreparePrintProductData();
	
	window.print();
	return false;
	
}

function fPreparePrintProductData(){
	
	// skopiowanie danych produktu dla drukowania
	$('#pojPrintImage').html($('#pojProdImg img').clone());
	$('#pojPrintProductData').html($('#pojProdDesc').clone());
	
	if($('#pojPrintProductData .pojPrice').length==0)
			$('#pojProdfeatured .pojPrice').clone().insertAfter($('#pojPrintProductData .pojRating'));
			
	$('#pojPrintProductData .item-feature li').append('<div class="clear"></div>')
	
	$('#pojPrintTechnicalData').html($('#TabFeatures .pojCol3').clone());
	$('#pojPrintFeatures').html($('#TabFeatures .pojCol4').clone());
	
	// potrzebne, zeby cechy i funkcje oraz dane techniczne nie przechodzily na druga strone
	$('#pojPrintFeatures .pojCol4 ul:last li:last').append('<div style="height: 10px"></div>');
	
	$('#pojPrintTechnicalData .pojCol3 ul li:last').addClass('lastLiItem');
	$('#pojPrintFeatures .pojCol4 ul li:last').addClass('lastLiItem');
	
}

/**
 * dodanie produktu do sesji do listy produktow porownania
 * @param {int} iProductId
 */
function fAddProductToCompare(iProductId){
	
		sUrl = 'index.php?sModul=mProductsXML&sAction=addProductToCompare&iProductId='+iProductId;
		
		$.ajax({
				type: 'GET',
				url: sUrl,
				dataType : 'xml',
				success: function(oXml){				
						
						var iStatus = $(oXml).find('iStatus').text();
						
						if (iStatus == 1){
							
								$('#btnAddProductToCompare').hide();
								$('#pojProduktDodanyDoPorownania').show();
							
						} else {
								
								alert( $(oXml).find('sMessage').text() );
						}
				}
		});
	
}


/**
 * @desc zwraca obiekt konfiguracji dla wideo prezentacji (jesli istnieje)
 */
function getConfig(){
	
		if(undefined != oVPConfig){
				return oVPConfig;
		}
	
}
