var MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false;
if(MSIE) { var MSIE_val = 0;  } else { var MSIE_val = 1; } 
var navigatorVersion = navigator.appVersion.replace(/.*?MSIE (\d\.\d).*/g,'$1')/1;

// funcja ktora pobiera elementy ze wzgledu na atrybut i jego wartosc (by wylowic elementy drgBoxi drgArea)
document.getElementsByAttribute = function(attribute, value, tagName, parentElement) {
	var children = (parentElement || document.body).getElementsByTagName((tagName || '*'));
	return $A(children).inject([], function(elements, child) {
		var attributeValue = child.getAttribute(attribute);
		if(attributeValue != null) {
			if(!value || attributeValue == value) {
				elements.push(child);
			}
		}
		return elements;
	});
}

function clearInnerHTML(obj) {
	// so long as obj has children, remove them
	while(obj.firstChild) obj.removeChild(obj.firstChild);
}

function CheckEnterPress(e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return false;
	if (keycode == 13)
	{	
		return true;
	}
}

function stopEnterPress(e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return false;
	if (keycode == 13)
	{	
		return false;
	}
}

function setDisplay(objectid,displaymode) {
  $j('#'+objectid).css('display',displaymode);
}


function radioLink(element_id) {
    
    $("#"+element_id).attr("checked", "checked");
    
}

function rozwin(name) {
    var container = document.getElementById('container'+name);
    if(container) {
      container.style.height = "17px";
      container.style.display = "";
    }
}

function xajax_update(urlparam, nameparam, onCompleteString) 
{ 
  $j.ajax({
	  url: urlparam,
	  type: "GET", 
	  success: function(html){
	    $j("#"+nameparam).html(html);
	    if(onCompleteString) eval(onCompleteString);
	  }
  });
}
function xajax_updatePost(urlparam, nameparam, postData, onCompleteString) 
{ 
  $j.ajax({
	  url: urlparam,
	  type: "POST", 
	  data: postData,
	  success: function(html){
	    $j("#"+nameparam).html(html);
	    if(onCompleteString) eval(onCompleteString);
	  }
  });
}

function xajax_updateElement(url, name, element) {
	element.innerHTML = "<img src='img/cms/ico/ajax-loader.gif' width='13' height='13' />";
	Tooltip.hide();
	new ajax( url,{method: 'GET', update: $(name) });
}
	    
function xajax_updatePostElement(url, name, postData) {
	Tooltip.hide();
	new ajax( url,{postBody: postData, update: $(name) });
}

function zwin(name) {
    var container = document.getElementById('container'+name);
    if(container) {
      container.style.height="0px";
      container.style.display="none";
    }
}

function showJump() {
    var jumper = document.getElementById('jumpToCategory');
    jumper.style.display = 'block';
}
function hideJump() {
    var jumper = document.getElementById('jumpToCategory');
    jumper.style.display = 'none';
}

var $j = jQuery.noConflict();

var $q = jQuery.noConflict();	

$j(document).ready(function(){

	$j('#mainsearch').keyup(function(){
		xajax_autocomplete_mainsearch();
	}); 
	
	$j("a[rel^='prettyPhoto']").prettyPhoto();


	//Set Default State of each portfolio piece
	$j(".paging").show();
	$j(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $j(".window").width();
	var imageSum = $j(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$j(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $jactive.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$j(".paging a").removeClass('active'); //Remove all active class
		$jactive.addClass('active'); //Add active class (the $jactive is declared in the rotateSwitch function)
		
		//Slider Animation
		$j(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$jactive = $j('.paging a.active').next();
			if ( $jactive.length === 0) { //If paging reaches the end...
				$jactive = $j('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 7000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$j(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$j(".paging a").click(function() {	
		$jactive = $j(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
	

});

function star_oMO( star_set_id , star_id ){
	$j('#rate').css('display','block');
	$j('#starrating').css('display','none');	

	var i = 1;
	for (i ;i <= 5;i++)
	{
		if(i<=star_id)
			$j('#star_'+star_set_id+'_'+i).attr('class','star');
		else
			$j('#star_'+star_set_id+'_'+i).attr('class','star-empty');
	}
}
function star_oMU( ){
	$j('#starrating').css('display','block');
	$j('#rate').css('display','none');	
}
