window.onload = base;

var slideSpeed = 400;
var newspage = 0;
var oldObj = null;

function base(){
	//if(url('news.html')) requestText(newspage);
	if($('.filling_down_btn').length) hideFilling();
	if($('.down_btn').length) reposPtag();
	
	if(url('company_contactus.html') || url('upload_files.html')||url('used_equipment.html')) btnBG();
	if(browser('MSIE 8.0')){if(url('employment_opportunities.html') || url('used_equipment.html') || url('news.html')||url('filing_systems.html'))engine();}
	if(browser('MSIE 6.0')) {liRePos();}
	if ($('#blogger').length){
		loadBlog();
	}
}

function btnBG(){
	$('#header_right a').each(function(){
		if(url($(this).attr('href')) == true){
			$(this).addClass('current');
		}
	});
}

function liRePos(){
	if($('#kip_nav').length){
		if(url('kip_scanners.html')){
			$('#kip_nav li:eq(1)').css('margin','-19px 0 0 0');
		}
		if(url('kip_finishin_accessories.html')){
			$('#kip_nav li:eq(2)').css('margin','-19px 0 0 0');
		}
	}
}
function engine(){
	setInterval(resizeDiv,33);
}
	
function resizeDiv(){
	var eo_box = $("#eo_box");
	var content_company = $("#content_company");
	var eo_box_top = $("#eo_box").offset().top
	var container = $("#container");
	container.css('height',(content_company.height()+390)+'px');
	}
	
function reposPtag(){
	$('#content_in_right_services a').each(function(){
		if (!$(this).find('br').length){
			if(browser('MSIE 7.0')||browser('MSIE 6.0')){
				$(this).next().css('margin-top','-12px');
				$(this).find('img').css('margin','1px 0 0 0');
				$(this).css('margin-top','18px');
			}else{
				$(this).next().css('margin-top','-12px');
				$(this).find('img').css('margin','3px 0 0 0');
				$(this).css('margin-top','9px');
			}			
		}
	});
}

	
function url(pageName){
	var objURL = new Object();
	if(document.URL.match(pageName)){
		return objURL = true;
	}else{
		return objURL = false;
	}
}
	
function browser(pageName){
	var objURL = new Object();
	if(navigator.userAgent.indexOf(pageName)>-1){
		return objURL = true;
	}else{
		return objURL = false;
	}
}

var divArray = new Array();
var pbtn = new Array();
function hideFilling(){
	$('.hide_box').hide();
	$('.filling_down_btn').click(function(){
		if ($(this).hasClass('open')){
			$(this).next('.hide_box').slideUp(500);
			$(this).removeClass('open');
		}else{
			$(this).next('.hide_box').slideDown(500);
			$(this).addClass('open');
		}
	});	
}
function loadBlog(){
	var months = ['January','Febuary','March','April','May','June','July','August','September','October','November','December'];
	$.ajax({
		url : 'http://resolutionrepro.blogspot.com/feeds/posts/default',
		data : {
			alt:'json-in-script', 
			'max-results':10,
			orderby:'published'
		},
		dataType : 'jsonp',
		beforeSend:function(){
			$('#blogger').html('<div id="loading-icon"><img src="ajax-loader.gif" alt="" />Loading...</div>');
		},
		type : 'GET',
		error : function(xhr, errorcode, error){
			$('#loading-icon').remove();
			var content = '<h2>Error: '+errorcode+'</h2>'+
			'<div>'+error+'</div>';
			$('#blogger').html(content);
		},
		success : function(data){
			$('#loading-icon').remove();
			var content = '';
			$.each(data.feed.entry, function(i, post){
				var title = post.title.$t;
				var link = post.link[4].href;
				var article = post.content.$t;
				
				var publishdate = post.published.$t.split('T');
				var pubdate = publishdate[0].split('-');
				var year = pubdate[0];
				var month = pubdate[1];
				var day = pubdate[2];
				date = months[month-1]+' '+day+', '+year;
				
				content += 
				'<div class="blogger_entry">'+
					'<h3 class="news_title"><a href="'+link+'">'+title+'</a></h3>'+
					'<div class="news_date">'+date+'</div>'+
					'<div class="news_article">'+article+'</div>'+
				'</div>';
			});
			$('#blogger').html(content);
		}
	});
}
