$(function(){

	$("#logotypy").cycle({
		fx: 'scrollLeft',
		height: 40,
		width: 400,
		timeout: 6000,
		fit: true,
	});
	
	$("#wizerunek").cycle({
		fx: 'fade',
		width: 980,
		height: 321,
		timeout: 5000,
		fit: true,
	});
	
  externalLinks();
  
  var link = document.location.href;
  link = link.split('/');
  var ile = link.length;
  // var link = link[ile-1].split('=');
  // console.log(link[ile-1]);
  var strona = link[ile-1];
  
  menu_aktywne();
  zalacz_cssy(strona);
});


function menu_aktywne(){
  var link = document.location.href;
  var as = document.getElementById('menu').children;
  var ilosc = as.length;
  for(i=0;i<ilosc;i++){
    if(as[i].href == link){
      as[i].className = 'active';
      return true;
    }
  }
}

function zalacz_cssy(strona){
  if(strona == '') strona = 'sg';
  var link = document.location.href;
  // tablica poniżej powinna zawierać wyjątki podstron,
  //przy których żadne dodatkowe cssy nie muszą zostać załadowane.
  var exceptions = new Array();
  var exceptions_length = exceptions.length;
  if(exceptions_length > 0){
    for(i=0;i<exceptions_length;i++){
      if(strona == exceptions[i]) return false;
    }
  }
  if(link.indexOf('realizacje') > 1){
	strona = 'realizacje';
  }
  var st = document.createElement('link');
  st.setAttribute('rel','stylesheet');
  st.setAttribute('href','./css/'+strona+'.css');
  document.head.appendChild(st);
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && ( 
			anchor.getAttribute("class") == "external" ||
			anchor.getAttribute("class") == "external nofollow" || 
			anchor.getAttribute("class") == "external pager" || 
			anchor.getAttribute("class") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}

