/*
jQuery(document).ready(function() {
  //
});
*/

/**
 * ----------------------------------------------------------------------------------------
 * Funckja zwracająca komunikat.
 * @param string Text  :Wiadomość do pobrania
 * @param bool Type  :Rodzaj wiadomości
 *   - false : error
 *   - true : ok
 */
function getMessage(Text, Type)
{
  if(Type === false)
  {
    return '<div class="errorMessage">'+Text+'</div>';
  }
  else if(Type === true)
  {
    return '<div class="okMessage">'+Text+'</div>';
  }
}


function rotateItems(Items, Index)
{
	if(Index >= 0)
	{
    if(RotateAnim)
    {
      clearTimeout(RotateAnim);
    }
		
		$('#item_' + Items[ItemsIndexNow]).fadeOut(2000);
		ItemsIndexNow = Index;
		ItemsIndex = Index;
		$('#item_' + Items[ItemsIndex]).fadeIn(2500);
	}
	else
	{
		$('#item_' + Items[ItemsIndex]).fadeOut(2000);

		if(!Items[ItemsIndex + 1])
		{
			ItemsIndex = 0;
		}
		else
		{
			ItemsIndex++;
		}
		
		//document.title = "::"+ItemsIndex+"/"+Items[ItemsIndex]+"::"+(new Date().getTime());
		
		$('#item_' + Items[ItemsIndex]).fadeIn(2500);
		ItemsIndexNow = ItemsIndex;
	}

  sIFR.replace(adihaus, {
    selector: '.news-desc h3',
    css: [
      '.sIFR-root { color: #ffffff; font-size: 24px; text-transform: uppercase; }' 
    ],
    wmode: 'transparent'
  });

  sIFR.replace(adihaus, {
    selector: '.news-desc .short-desc',
    css: [
      '.sIFR-root { color: #ffffff; font-size: 14px; text-transform: uppercase; }' 
    ],
    wmode: 'transparent'
  });
	
	RotateAnim = setTimeout('rotateItems(Items)', 5000);
}


function showNews(BoxInfoPositions_Id)
{
  //Pobieramy jaką akcję chcemy wykonać
  var TargetURL = '/ajax/action.php?action=getNews&Id='+BoxInfoPositions_Id;

  //Przygotowanie pól formularza do wysłania
  var strPost = null;

  //Wysyłamy żądanie do servera
  $.ajax({
    type:      'GET',
    url:       TargetURL,
    data:      strPost,
    dataType:  'html',
    success:   function(reciveData)
    {
      if(RotateAnim)
      {
        clearTimeout(RotateAnim);
      }

      $('#containerNews').html(reciveData);
			
      
      sIFR.replace(adihaus, {
        selector: '.news-desc h3',
        css: [
          '.sIFR-root { color: #ffffff; font-size: 24px; text-transform: uppercase; }' 
        ],
        wmode: 'transparent'
      });

      sIFR.replace(adihaus, {
        selector: '.news-desc .short-desc',
        css: [
          '.sIFR-root { color: #ffffff; font-size: 14px; text-transform: uppercase; }' 
        ],
        wmode: 'transparent'
      });
    }
  });
}




function showPoznajStarlink()
{
  //Pobieramy jaką akcję chcemy wykonać
  var TargetURL = '/ajax/action.php?action=getPoznajStarlink';

  //Przygotowanie pól formularza do wysłania
  var strPost = null;

  //Wysyłamy żądanie do servera
  $.ajax({
    type:      'GET',
    url:       TargetURL,
    data:      strPost,
    dataType:  'html',
    success:   function(reciveData)
    {
      if(RotateAnim)
      {
        clearTimeout(RotateAnim);
      }

      $('#containerNews').html(reciveData);
			
      sIFR.replace(adihaus, {
        selector: '.news-desc h3',
        css: [
          '.sIFR-root { color: #ffffff; font-size: 24px; text-transform: uppercase; }' 
        ],
        wmode: 'transparent'
      });

      sIFR.replace(adihaus, {
        selector: '.news-desc .short-desc',
        css: [
          '.sIFR-root { color: #ffffff; font-size: 14px; text-transform: uppercase; }' 
        ],
        wmode: 'transparent'
      });
    }
  });
}


function showImage(oAction, ImageId)
{
  $('.indicators .floatR a img').attr('src', '/img/Original/indicator.png');
  $('img', oAction).attr('src', '/img/Original/indicator_active.png');
	
  //$('.box .mediaboxImages .wr3').fadeOut(500);
  $('.box .mediaboxImages .wr3').hide();
  $(ImageId).fadeIn(1000);
}

function showDialog(ObjectId, Width, Height)
{
  $.ui.dialog.defaults.bgiframe = true;
  $(ObjectId).dialog({
    bgiframe: true,
    modal: true,
    width: Width,
		height: Height,
    position: 'center',
		
		close: function(event, ui) { $(ObjectId).dialog('destroy'); }
	});
}

/**
 * ----------------------------------------------------------------------------------------
 * Funckja wysyłająca formularz wyszukiwania do servera
 * 
 * @param string oForm         :Formularz z którego jest wysyłana akcja
 */
function searchForm(oForm)
{
  // Pobieramy dane do wyszukiwania
  var SearchSection = jQuery.trim(oForm.SearchSection.value)
  var SearchField = jQuery.trim(oForm.SearchField.value)
  var SearchValue = jQuery.trim(oForm.SearchValue.value)
  
  // Ustawiamy action w formularzu
  var TargetURL = '/Search/0/1/'+SearchField+'='+SearchValue+'/'+SearchSection+'.html';
  $(oForm).attr('action', TargetURL);
  
  // Sprawdzamy czy są dane do wyszukiwania
  if(SearchSection != '' && SearchField != '' && SearchValue != '')
  {
    window.location = TargetURL;
  }

  return false;
}

/**
 * ----------------------------------------------------------------------------------------
 * Funckja wywołująca kod Google w momencie kliknięcia na link mailowy do podbrania odpłatnych raportów
 * 
 */
function runGogleCode()
{
	var imgGogleCode = new Image();
	imgGogleCode.src = 'http://www.googleadservices.com/pagead/conversion/1070692998/?label=sE5CCNTrkwEQhvXF_gM&amp;guid=ON&amp;script=0';
}